Skip to content

Commit 5a64694

Browse files
committed
WIP
1 parent fc9e4f7 commit 5a64694

File tree

4 files changed

+62
-5
lines changed

4 files changed

+62
-5
lines changed

.github/workflows/documentation.yml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@ name: Documentation
88
# - deploy_docs only run on the next branch when code is pushed. It retrieve
99
# the ocaml and sphinx documentation and deploy them on the gh-pages branch
1010

11-
on: [push, pull_request]
11+
on:
12+
push:
13+
tags:
14+
- "v*.*.*"
15+
branches:
16+
- next
17+
- main
18+
- multidoc
19+
pull_request:
1220

1321
env:
1422
OCAML_DEFAULT_VERSION: 4.10.0
@@ -115,33 +123,38 @@ jobs:
115123
deploy_docs:
116124
name: Deploy documentation
117125

118-
if: github.ref == 'refs/heads/main'
126+
if: ${{ github.event_name == 'push' }}
119127

120128
needs:
121129
- ocaml_docs
122130
- sphinx_docs
123131

124132
runs-on: ubuntu-latest
125133
steps:
134+
- name: Determine version name
135+
id: version-name
136+
run: |
137+
echo "::set-output name=target::${GITHUB_REF#*/*/}"
138+
126139
# Retrieve ocaml documentation artifact
127140
- name: Download ocaml documentation
128141
uses: actions/download-artifact@v4
129142
with:
130143
name: ocaml_doc
131-
path: _build/odoc/dev
144+
path: _build/odoc/${{ steps.version-name.outputs.target }}
132145

133146
# Retrieve sphinx documentation artifact
134147
- name: Download sphinx documentation
135148
uses: actions/download-artifact@v4
136149
with:
137150
name: sphinx_doc
138-
path: _build
151+
path: _build/${{ steps.version-name.outputs.target }}
139152

140153
- name: Add files to bypass nojekyll
141154
run: |
142155
touch _build/.nojekyll
143156
touch _build/odoc/.nojekyll
144-
touch _build/odoc/dev/.nojekyll
157+
touch _build/odoc/${{ steps.version-name.outputs.target }}/.nojekyll
145158
146159
# Deploy files contain in _build directory on gh-pages branch
147160
- name: deploy-doc
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
function renderVersions(versions) {
2+
return `
3+
<dl>
4+
<dt>Versions</dt>${ versions.active.map((version) => `
5+
<dd ${ version.slug == versions.current.slug ? 'class="rtd-current-item"' : '' }>
6+
<a href="${ version.url }">${ version.slug }</a>
7+
</dd>
8+
`).join("\n")}
9+
</dl>
10+
`;
11+
}
12+
13+
document.addEventListener('DOMContentLoaded', function () {
14+
$.getJSON('_static/versions.json', (versions) => {
15+
console.log(versions);
16+
document.body.insertAdjacentHTML("beforeend", `
17+
<div class="rst-versions" data-toggle="rst-versions" role="note" aria-label="Versions">
18+
<span class="rst-current-version" data-toggle="rst-current-version">
19+
<span class="fa fa-book"> Current version</span>
20+
v: ${ versions.current.slug }
21+
<span class="fa fa-caret-down"></span>
22+
</span>
23+
<div class="rst-other-versions">
24+
${renderVersions(versions)}
25+
</div>
26+
</div>
27+
`);
28+
});
29+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"current": {"url": "dev", "slug": "next"},
3+
"active": [
4+
{"url": "dev", "slug": "next"},
5+
{"url": "v2.5.4", "slug": "2.5.4"}
6+
]
7+
}

docs/sphinx_docs/conf.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,11 @@
7070
# relative to this directory. They are copied after the builtin static files,
7171
# so a file named "default.css" will overwrite the builtin "default.css".
7272
html_static_path = ['_static']
73+
74+
# -- Context population (version management and more) ------------------------
75+
76+
html_js_files = ['js/versions.js']
77+
html_context = {
78+
'current_version': 'dev',
79+
'versions': [['2.5.4', 'v2.5.4']],
80+
}

0 commit comments

Comments
 (0)