-
Notifications
You must be signed in to change notification settings - Fork 184
docs: add a version switch. #1642
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
Merged
Merged
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -193,6 +193,38 @@ jobs: | |
| branch: main | ||
| folder: docs/ | ||
| target-folder: docs/amaranth/${{ github.ref_name }}/ | ||
| - name: Generate list of versions | ||
| if: ${{ github.event_name == 'push' && (github.event.ref == 'refs/heads/main' || startsWith(github.event.ref, 'refs/tags/v') && !contains(github.event.ref, 'dev')) }} | ||
| run: | | ||
| git clone --depth=1 [email protected]:amaranth-lang/amaranth-lang.github.io.git ~/amaranth-lang.github.io | ||
| cd ~/amaranth-lang.github.io/docs/amaranth/ | ||
|
|
||
| ( | ||
| venv_path=$(mktemp -d) | ||
| python3 -m venv "$venv_path" | ||
| source "$venv_path"/bin/activate | ||
| pip install packaging | ||
| python >versions.json <<EOF | ||
| import json | ||
| from pathlib import Path | ||
| from packaging.version import Version | ||
|
|
||
| versions = Path('.').glob('v*') | ||
| versions = (path.name[1:] for path in versions if path.is_dir()) | ||
| versions = sorted(versions, key=Version, reverse=True) | ||
| versions = ({"name": version, "root_url": f"/docs/amaranth/v{version}/"} for version in versions) | ||
| print(json.dumps(list(versions), indent=2)) | ||
| EOF | ||
| ) | ||
|
|
||
| git add versions.json | ||
| if ! git diff-index --quiet --cached HEAD; then | ||
| git \ | ||
| -c user.name="$GITHUB_ACTOR" \ | ||
| -c user.email="[email protected]" \ | ||
| commit -m "Update docs/amaranth/versions.json" | ||
| git push | ||
| fi | ||
|
|
||
| publish-docs-dev: | ||
| needs: document | ||
|
|
||
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,111 @@ | ||
| document.addEventListener('DOMContentLoaded', () => { | ||
| let contentRoot = new URL( | ||
| document.documentElement.dataset.content_root ?? DOCUMENTATION_OPTIONS.URL_ROOT, | ||
| window.location.href, | ||
| ); | ||
|
|
||
| function insertVersionSwitch(versions) { | ||
| let versionElement = document.querySelector('.wy-side-nav-search > .version'); | ||
| if (!versionElement) return; | ||
|
|
||
| let root = document.createElement('div'); | ||
| root.innerHTML = ` | ||
| <div class="switch-menus"> | ||
| <div class="version-switch"><select></select></div> | ||
| </div> | ||
| `; | ||
|
|
||
| let switchMenus = root.firstElementChild; | ||
| let versionSwitch = switchMenus.firstElementChild; | ||
| let versionSwitchSelect = versionSwitch.firstElementChild; | ||
|
|
||
| let versionElementStyles = getComputedStyle(versionElement); | ||
| let cssStyleSheet = new CSSStyleSheet(); | ||
| cssStyleSheet.replaceSync(String.raw` | ||
| .wy-side-nav-search > div.switch-menus { | ||
| margin-top: ${versionElementStyles.marginTop}; | ||
| margin-bottom: ${versionElementStyles.marginBottom}; | ||
| color: ${versionElementStyles.color}; | ||
|
|
||
| div.version-switch { | ||
| select { | ||
| display: inline-block; | ||
| margin-right: -2rem; | ||
| padding-right: 2rem; | ||
| text-align-last: center; | ||
| background: none; | ||
| border: none; | ||
| border-radius: 0em; | ||
| box-shadow: none; | ||
| font-family: inherit; | ||
| font-size: 1em; | ||
| font-weight: normal; | ||
| color: inherit; | ||
| cursor: pointer; | ||
| appearance: none; | ||
|
|
||
| &:hover, &:active, &:focus { | ||
| background: rgba(255, 255, 255, .1); | ||
| color: rgba(255, 255, 255, .5); | ||
| } | ||
|
|
||
| option { | ||
| color: black; | ||
| } | ||
| } | ||
|
|
||
| &:has(> select):after { | ||
| display: inline-block; | ||
| width: 1.5em; | ||
| height: 100%; | ||
| padding: .1em; | ||
| content: "\f0d7"; | ||
| font-size: 1em; | ||
| line-height: 1.2em; | ||
| font-family: FontAwesome; | ||
| text-align: center; | ||
| pointer-events: none; | ||
| box-sizing: border-box; | ||
| } | ||
| } | ||
| } | ||
| `); | ||
| document.adoptedStyleSheets.push(cssStyleSheet); | ||
|
|
||
| let currentVersion = DOCUMENTATION_OPTIONS.VERSION; | ||
| if (!versions.includes(currentVersion)) { | ||
| versions = [ | ||
| { name: currentVersion, root_url: contentRoot }, | ||
| ...versions, | ||
| ]; | ||
| } | ||
|
|
||
| for (let { name, root_url: rootURL } of versions) { | ||
| rootURL = new URL(rootURL, window.location.href); | ||
|
|
||
| let versionOptionElement = document.createElement('option'); | ||
| versionOptionElement.textContent = name; | ||
| versionOptionElement.dataset.url = rootURL; | ||
|
|
||
| if (name === currentVersion) { | ||
| versionOptionElement.selected = true; | ||
| } | ||
|
|
||
| versionSwitchSelect.appendChild(versionOptionElement); | ||
| } | ||
|
|
||
| versionSwitchSelect.addEventListener('change', (event) => { | ||
| let option = event.target.selectedIndex; | ||
| let item = event.target.options[option]; | ||
| window.location.href = item.dataset.url; | ||
| }); | ||
|
|
||
| versionElement.replaceWith(switchMenus); | ||
| } | ||
|
|
||
| fetch(new URL('../versions.json', contentRoot)).then(async (response) => { | ||
| if (response.status !== 200) return; | ||
| let versions = await response.json(); | ||
| insertVersionSwitch(versions); | ||
| }); | ||
| }); | ||
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.
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.