Skip to content

Commit 3cf1552

Browse files
authored
Support versioning docs (#259)
* Setup versioned docs * changelog * correct version number
1 parent e287cca commit 3cf1552

File tree

5 files changed

+76
-1
lines changed

5 files changed

+76
-1
lines changed

.github/workflows/docs.yml renamed to .github/workflows/docs-latest.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ jobs:
2424
github_token: ${{ secrets.GITHUB_TOKEN }}
2525
keep_files: true
2626
publish_dir: ./book
27-
destination_dir: ./
27+
destination_dir: ./latest

.github/workflows/docs-release.yml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Build docs
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
deploy:
9+
runs-on: ubuntu-20.04
10+
steps:
11+
- uses: actions/checkout@v2
12+
13+
- name: Get release tag
14+
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
15+
16+
- name: Setup mdBook
17+
uses: peaceiris/actions-mdbook@v1
18+
with:
19+
mdbook-version: '0.4.11'
20+
21+
- name: Set version of docs
22+
run: echo 'window.HOOKSHOT_VERSION = "${{ env.RELEASE_VERSION }}";' > ./docs/_site/version.js
23+
24+
- run: mdbook build
25+
26+
- name: Deploy latest
27+
uses: peaceiris/actions-gh-pages@v3
28+
with:
29+
github_token: ${{ secrets.GITHUB_TOKEN }}
30+
keep_files: true
31+
publish_dir: ./book
32+
destination_dir: ./${{ env.RELEASE_VERSION }}

book.toml

+5
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,8 @@ git-repository-url = "https://github.com/matrix-org/matrix-hookshot"
2222
additional-css = [
2323
"docs/_site/style.css"
2424
]
25+
26+
additional-js = [
27+
"docs/_site/main.js",
28+
"docs/_site/version.js"
29+
]

docs/_site/main.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
window.addEventListener("load", () => {
2+
const scrollbox = document.querySelector(".sidebar-scrollbox");
3+
scrollbox.innerHTML = `<div class="version-box"><span>Version: </span></div>${scrollbox.innerHTML}`;
4+
const currentVersion = window.HOOKSHOT_VERSION || 'latest';
5+
6+
const selectElement = document.createElement("select");
7+
8+
fetch("https://api.github.com/repos/matrix-org/matrix-hookshot/releases", {
9+
cache: "force-cache",
10+
}).then(res =>
11+
res.json()
12+
).then(releases => {
13+
selectElement.innerHTML = "";
14+
for (const version of ['latest', ...releases.map(r => r.tag_name).filter(s => s !== "0.1.0")]) {
15+
const option = document.createElement("option");
16+
option.innerHTML = version;
17+
selectElement.add(option);
18+
if (currentVersion === version) {
19+
option.setAttribute('selected', '');
20+
}
21+
}
22+
}).catch(ex => {
23+
console.error("Failed to fetch version data", ex);
24+
})
25+
26+
const option = document.createElement("option");
27+
option.innerHTML = 'loading...';
28+
selectElement.add(option);
29+
30+
selectElement.addEventListener('change', (event) => {
31+
const versionlessPath = window.location.pathname.split('/').slice(2).join('/');
32+
window.location = `${window.location.origin}/${event.target.value}/${versionlessPath}`;
33+
});
34+
35+
document.querySelector(".version-box").appendChild(selectElement);
36+
});

docs/_site/version.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// This is modified by the build script
2+
window.HOOKSHOT_VERSION = "latest";

0 commit comments

Comments
 (0)