Skip to main content

brainx-sphinx-header

Sphinx extension that injects the canonical BrainX brand header and footer into any docs site, fetched live from the landing site so every package's docs stays in visual sync.

Install

pip install brainx-sphinx-header

Use

In your docs/conf.py:

extensions = [
    # ...
    "brainx_sphinx_header",
]

That's it. On the next build, the BrainX header and footer are fetched from https://brainx.chaobrain.com/shared-header, cached at <docs>/_brand/, and emitted as _static/css/brainx-header.css + _static/js/brainx-header.js (plus the matching brainx-footer.{css,js}).

Configuration (optional)

All settings have sensible defaults. Override in conf.py only if you need to.

Setting Default Purpose
brainx_header_url "https://brainx.chaobrain.com/shared-header" Where to fetch the canonical header
brainx_header_ttl 3600 Cache TTL in seconds
brainx_header_offline False Use cache only, never fetch
brainx_header_local None Path to a local shared-header dir for live preview
brainx_inject_base True Inject <base href="{html_baseurl}"> into the docs index so the site works at both /<pkg> and /<pkg>/ (no-op if html_baseurl is unset)
brainx_ssr_inject True Post-process every built .html to embed the header/footer markup in the document at first paint (no flash, SEO, no-JS, screen readers). The JS injection remains as a self-skipping fallback.
brainx_sitemap True Write sitemap.xml at the docs root listing every page under html_baseurl (no-op if html_baseurl is unset). Disable via BRAINX_SITEMAP=0 too.

Each setting also honors an environment variable (BRAINX_HEADER_URL, BRAINX_HEADER_TTL, BRAINX_HEADER_OFFLINE=1, BRAINX_HEADER_LOCAL, BRAINX_SSR_INJECT=0) which takes precedence — handy for CI.

What it does

  • Fetches header.html, header.css, header.js, footer.html, footer.css from the BrainX landing site (with TTL cache + stale fallback).
  • Emits them as Sphinx static assets and registers them via add_css_file / add_js_file.
  • Header: appends CSS overrides that hide sphinx_book_theme / pydata_sphinx_theme native top bars (header.bd-header, .bd-header-article, .header-article-items.header-article__inner); wires the BrainX header's burger to the theme's hidden original (.primary-toggle) so sidebar toggle keeps working — no template overrides needed.
  • Footer: appends below the theme's native footer. The canonical CSS ships margin-top: 6rem for the Astro landing page; the extension appends an override that zeros that margin in docs context so the brand footer sits flush against the theme footer instead of leaving a 6–8rem blank band. {{YEAR}} is substituted at extension-emit time.
  • SSR injection (v0.5.0+): on build-finished, every built page outside _static/ gets the header markup written in right after <body> and the footer right before </body>. The document ships the brand chrome at first paint — no flash, crawlers and no-JS clients see it, screen readers see it. Idempotent via data-bx-header / data-bx-footer markers; the JS preambles also self-skip those markers so they become a pure behavior payload (plus a fallback if SSR is disabled). Disable via brainx_ssr_inject = False or BRAINX_SSR_INJECT=0.
  • Slash-tolerant index: injects <base href="{html_baseurl}"> into the docs index page, so the site renders correctly whether reached via https://host/<pkg> or https://host/<pkg>/. Sub-pages already resolve correctly via their own real paths and are not touched. Pair with an exact-match nginx block (location = /<pkg> { alias .../current/index.html; default_type text/html; }) to actually serve the no-slash URL without a redirect. Disable via brainx_inject_base = False if you want the historical 301-redirect behavior.
  • Sitemap + index canonical (v0.6.0+): on build-finished, writes sitemap.xml (one <url> per source document) so search engines can find every page; the landing site's sitemap-index.xml lists each /<pkg>/sitemap.xml. The docs index's canonical becomes /<pkg>/ instead of Sphinx's default /<pkg>/index.html, matching every link to it; the sitemap uses the same URL.

Local development

To preview a header change against your local landing-site build before pushing:

BRAINX_HEADER_LOCAL=/path/to/brainx.chaobrain.com/dist/shared-header sphinx-build -b html docs docs/_build/html

Supported themes

sphinx_book_theme, pydata_sphinx_theme (the bd-* selector family). Other themes will still render the BrainX header but without button delegation; their native header is unaffected.

Metadata

Release files for brainx-sphinx-header 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for brainx-sphinx-header 0.6.0
File Size Uploaded
brainx_sphinx_header-0.6.0.tar.gz 15.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for brainx-sphinx-header 0.6.0
File Interpreter ABI Platform
brainx_sphinx_header-0.6.0-py3-none-any.whl Python 3 none any Details

Total release size: 30.0 kB

Release files / brainx_sphinx_header-0.6.0.tar.gz

Download URL brainx_sphinx_header-0.6.0.tar.gz
Size 15.7 kB
Tags Source
SHA-256 checksum
How to use checksums
0383aba3607f8584cf7db388be67bc87551428cb42a09ce2e3c84ab565e37979
BLAKE2b-256 checksum
How to use checksums
b5fe2cff0f370ecfab7dc2d7fcdfe99b1ab6d64a5fdc7d22697e79fc88ea64c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.11

Release files / brainx_sphinx_header-0.6.0-py3-none-any.whl

Download URL brainx_sphinx_header-0.6.0-py3-none-any.whl
Size 14.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
09b1c4dd52b8164c7afd6f083a101d3b5328d20edaf9e3abd849c7da501d604b
BLAKE2b-256 checksum
How to use checksums
a825fd527ed7458a85fa63493dc658831b837a3da6dd81f4915587a794b3467c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.11

Release history Release notifications | RSS feed

This release

0.6.0 This release

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

1 release file

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page