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.cssfrom 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_themenative 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: 6remfor 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 viadata-bx-header/data-bx-footermarkers; the JS preambles also self-skip those markers so they become a pure behavior payload (plus a fallback if SSR is disabled). Disable viabrainx_ssr_inject = FalseorBRAINX_SSR_INJECT=0. - Slash-tolerant index: injects
<base href="{html_baseurl}">into the docs index page, so the site renders correctly whether reached viahttps://host/<pkg>orhttps://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 viabrainx_inject_base = Falseif you want the historical 301-redirect behavior. - Sitemap + index canonical (v0.6.0+): on
build-finished, writessitemap.xml(one<url>per source document) so search engines can find every page; the landing site'ssitemap-index.xmllists 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)
| File | Size | Uploaded | |
|---|---|---|---|
| brainx_sphinx_header-0.6.0.tar.gz | 15.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| 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
|