-
-
Notifications
You must be signed in to change notification settings - Fork 437
docs: show package tag instead of monorepo release in subpackage docs #4229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
maxrjones
wants to merge
4
commits into
zarr-developers:main
Choose a base branch
from
maxrjones:docs/subpackage-header-version
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| # Shared Material for MkDocs configuration for the sub-package docs sites. | ||
| # Each package's mkdocs.yml pulls this in via INHERIT and defines only its | ||
| # identity (site_name, repo_*, site_description, site_url) and nav. | ||
| # The inventories list below is the superset used by all packages; an | ||
| # inventory a package never references is harmless. | ||
| site_author: Davis Bennett | ||
| use_directory_urls: true | ||
|
|
||
| watch: | ||
| - src | ||
|
|
||
| theme: | ||
| language: en | ||
| name: material | ||
| logo: _static/logo_bw.png | ||
| favicon: _static/favicon-96x96.png | ||
|
|
||
| palette: | ||
| # Light mode | ||
| - media: "(prefers-color-scheme: light)" | ||
| scheme: default | ||
| toggle: | ||
| icon: material/brightness-7 | ||
| name: Switch to dark mode | ||
|
|
||
| # Dark mode | ||
| - media: "(prefers-color-scheme: dark)" | ||
| scheme: slate | ||
| toggle: | ||
| icon: material/brightness-4 | ||
| name: Switch to light mode | ||
|
|
||
| font: | ||
| text: Roboto | ||
| code: Roboto Mono | ||
|
|
||
| features: | ||
| - content.code.annotate | ||
| - content.code.copy | ||
| - navigation.indexes | ||
| - navigation.instant | ||
| - navigation.tracking | ||
| - search.suggest | ||
| - search.share | ||
|
|
||
| plugins: | ||
| - autorefs | ||
| - search | ||
| - mkdocstrings: | ||
| enable_inventory: true | ||
| handlers: | ||
| python: | ||
| paths: [src] | ||
| options: | ||
| allow_inspection: true | ||
| docstring_section_style: list | ||
| docstring_style: numpy | ||
| inherited_members: true | ||
| line_length: 60 | ||
| separate_signature: true | ||
| show_root_heading: true | ||
| show_signature_annotations: true | ||
| show_source: true | ||
| show_symbol_type_toc: true | ||
| signature_crossrefs: true | ||
| show_if_no_docstring: true | ||
| extensions: | ||
| - griffe_inherited_docstrings | ||
|
|
||
| inventories: | ||
| - https://docs.python.org/3/objects.inv | ||
| - https://numpy.org/doc/stable/objects.inv | ||
| - https://zarr.readthedocs.io/en/stable/objects.inv | ||
|
|
||
| # Override the header source widget's version fact (the monorepo's latest | ||
| # release) with the latest tag matching the package's prefix. | ||
| extra_javascript: | ||
| - _static/source-version.js | ||
|
|
||
| markdown_extensions: | ||
| - admonition | ||
| - attr_list | ||
| - def_list | ||
| - footnotes | ||
| - md_in_html | ||
| - pymdownx.details | ||
| - pymdownx.superfences | ||
| - toc: | ||
| permalink: true | ||
| - pymdownx.highlight: | ||
| anchor_linenums: true | ||
| line_spans: __span | ||
| pygments_lang_class: true | ||
| - pymdownx.inlinehilite |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| /* Material's header source widget shows the monorepo's latest release | ||
| (e.g. v3.3.0). Replace it with the latest tag for this package, and | ||
| patch the theme's sessionStorage cache so instant navigation keeps it. | ||
|
|
||
| The GitHub repo and the package's tag prefix (e.g. zarr_metadata-) are | ||
| derived from repo_url, whose final path segment is the package directory, | ||
| so this file is identical across all sub-package docs sites. */ | ||
| (() => { | ||
| const source = document.querySelector('[data-md-component="source"]') | ||
| if (!source || !source.href) | ||
| return | ||
| const segments = new URL(source.href).pathname.split("/").filter(Boolean) | ||
| const REPO = segments.slice(0, 2).join("/") | ||
| const PREFIX = segments[segments.length - 1].replace(/-/g, "_") + "-" | ||
|
|
||
| const parse = version => version | ||
| .replace(/^v/, "") | ||
| .split(/[.+-]/) | ||
| .map(part => parseInt(part, 10) || 0) | ||
|
|
||
| const newestFirst = (a, b) => { | ||
| const va = parse(a), vb = parse(b) | ||
| for (let i = 0; i < Math.max(va.length, vb.length); i++) | ||
| if ((vb[i] || 0) !== (va[i] || 0)) | ||
| return (vb[i] || 0) - (va[i] || 0) | ||
| return 0 | ||
| } | ||
|
|
||
| /* Cache the tag for the tab's lifetime (like the theme's own __source | ||
| cache) so navigation doesn't burn GitHub's unauthenticated API rate | ||
| limit. Keyed by prefix in case sub-package sites share an origin. */ | ||
| const CACHE_KEY = `__package_tag/${PREFIX}` | ||
|
|
||
| async function latestPackageTag() { | ||
| const cached = sessionStorage.getItem(CACHE_KEY) | ||
| if (cached) | ||
| return cached | ||
| const response = await fetch( | ||
|
maxrjones marked this conversation as resolved.
|
||
| `https://api.github.com/repos/${REPO}/tags?per_page=100` | ||
| ) | ||
| if (!response.ok) | ||
| return undefined | ||
| const tags = await response.json() | ||
| const versions = tags | ||
| .map(tag => tag.name) | ||
| .filter(name => name.startsWith(PREFIX)) | ||
| .map(name => name.slice(PREFIX.length)) | ||
| .sort(newestFirst) | ||
| if (versions[0]) | ||
| sessionStorage.setItem(CACHE_KEY, versions[0]) | ||
| return versions[0] | ||
| } | ||
|
|
||
| function patchDom(version) { | ||
| for (const el of document.querySelectorAll(".md-source__fact--version")) | ||
| el.textContent = version | ||
| } | ||
|
|
||
| function patchCache(version) { | ||
| const facts = __md_get("__source", sessionStorage) | ||
|
maxrjones marked this conversation as resolved.
|
||
| if (!facts) | ||
| return false | ||
| facts.version = version | ||
| __md_set("__source", facts, sessionStorage) | ||
| return true | ||
| } | ||
|
|
||
| latestPackageTag().then(version => { | ||
| if (!version) | ||
| return | ||
| patchDom(version) | ||
| if (patchCache(version)) | ||
| return | ||
| /* The theme's own API request hasn't resolved yet — patch both the | ||
| cache and the DOM once it renders the facts list. */ | ||
| new MutationObserver((_, observer) => { | ||
| if (patchCache(version)) { | ||
| patchDom(version) | ||
| observer.disconnect() | ||
| } | ||
| }).observe(source, { childList: true, subtree: true }) | ||
| }) | ||
| })() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../source-version.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.