-
Notifications
You must be signed in to change notification settings - Fork 60
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
[WIP] doc: Make automatic deployment of versioned documentation possible #657
Open
tmadlener
wants to merge
7
commits into
AIDASoft:master
Choose a base branch
from
tmadlener:versioned-docs
base: master
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
7 commits
Select commit
Hold shift + click to select a range
996858a
Try to deploy to different path
tmadlener 66cf634
Create an output folder depending on tag or branch
tmadlener b486f05
Choose better name for contents folder
tmadlener 5180cfa
Add dynamically populated version selection to documentation
tmadlener 9c242d7
Order available versions from newest to oldest
tmadlener bea57c2
Also trigger deployments on new tags
tmadlener db9a569
Add top level index.html and minimal conceptual README
tmadlener 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 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 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,79 @@ | ||
<div class="rst-versions" data-toggle="rst-versions" role="note" aria-label="versions"> | ||
<span class="rst-current-version" data-toggle="rst-current-version" id="current-version-span"> | ||
<span class="fa fa-caret-down"></span> | ||
</span> | ||
<script> | ||
document.getElementById("current-version-span").insertAdjacentText('afterbegin', `Version: ${window.location.href.split('/').at(-2)}`) | ||
</script> | ||
|
||
<div class="rst-other-versions" id="other-versions-div"> | ||
</div> | ||
<script> | ||
/** Parse all available versions from the directory listing content | ||
*/ | ||
function getAvailableVersions(contents) { | ||
// Take a DOMParser to get to the links | ||
let parser = new DOMParser(); | ||
let doc = parser.parseFromString(contents, 'text/html'); | ||
|
||
let links = doc.querySelectorAll('a'); | ||
let availableVersions = []; | ||
links.forEach(link => { | ||
let href = link.getAttribute('href'); | ||
if (href.endsWith('/') && !href.startsWith('/')) { | ||
availableVersions.push(link.textContent.replace(/\/$/, '')); | ||
} | ||
}); | ||
|
||
return availableVersions; | ||
} | ||
|
||
/** Sort versions in descending order, ordering "non-versions" to the top | ||
*/ | ||
function sortVersions(v1, v2) { | ||
const rgx = /^v(\d+)-(\d+)(?:-(\d+))?$/ | ||
const m1 = v1.match(rgx); | ||
const m2 = v2.match(rgx); | ||
|
||
// If only one matches, that has to go down, otherwise we keep the order | ||
if (!m1 && m2) return -1; | ||
if (m1 && !m2) return 1; | ||
if (!m1 && !m2) return 0; | ||
|
||
const intV1 = parseInt(m1[1], 10) * 10000 + parseInt(m1[2], 10) * 100 + parseInt(m1[3] || 0, 10); | ||
const intV2 = parseInt(m2[1], 10) * 10000 + parseInt(m2[2], 10) * 100 + parseInt(m2[3] || 0, 10); | ||
|
||
return intV2 - intV1; | ||
} | ||
|
||
const other_versions = document.getElementById("other-versions-div"); | ||
other_versions.innerHTML = ''; | ||
|
||
// Dynamically determine the versions by checking the directory one | ||
// level up and populate the version list from there | ||
const baseUrl = window.location.href.split('/').slice(0, -2).join('/'); | ||
fetch(baseUrl) | ||
.then(response => response.text()) | ||
.then(contents => { | ||
const availableVersions = getAvailableVersions(contents); | ||
|
||
availableVersions.sort(sortVersions); | ||
|
||
const versionList = document.createElement("dl"); | ||
const header = document.createElement("dt"); | ||
header.textContent = "Versions"; | ||
versionList.appendChild(header) | ||
|
||
availableVersions.forEach(v => { | ||
const vElem = document.createElement("dd"); | ||
const vLink = document.createElement("a"); | ||
vLink.href = `${baseUrl}/${v}`; | ||
vLink.textContent = v; | ||
vElem.appendChild(vLink); | ||
versionList.appendChild(vElem); | ||
}); | ||
|
||
other_versions.appendChild(versionList); | ||
}); | ||
</script> | ||
</div> |
This file contains 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 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,28 @@ | ||||||
# Versioned documentation deployment | ||||||
|
||||||
- Assumed to be deployed via eos using a folder structure like this | ||||||
```console | ||||||
. | ||||||
├── _contents | ||||||
│ ├── vXX-YY | ||||||
│ └── master | ||||||
├── index.html | ||||||
``` | ||||||
- Each version / tag gets a new folder and the `master` / develop version is | ||||||
continually updated | ||||||
- The `_contents` folder has to configured to have *Directory Browsing* enabled | ||||||
since that will be used to determine the available versions (each top-level | ||||||
folder in here will be considered a version). This is achieved via `echo | ||||||
"Options +Indexes > _contents/.htaccess"` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
- The `version.html` "template" fetches the directory from `_contents`, extracts | ||||||
the available directories (via their links) and creates a sorted list of | ||||||
versions before dynamically populating the read-the-docs bit for version | ||||||
selection | ||||||
- gitlab ci takes care of copying the generated contents to the correct | ||||||
subfolder of `_contents` depending on whether it has been triggered by a tag | ||||||
or by a push to master | ||||||
- Documentation for versions that are added post-hoc need a small adaption of | ||||||
their (sphinx generated) `index.html`; the `version.html` template has to be | ||||||
copied verbatim to the bottom, but above the navigation enabling. | ||||||
- The `index.html` in this folder has to be placed into the same folder where | ||||||
also `_contents` is |
This file contains 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,11 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<title>Redirecting to latest release</title> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="refresh" content="0"; url="./_contents/master/index.html"> | ||
<link rel="canonical" href="https://key4hep.web.cern.ch/podio/_contents/master/"> | ||
</head> | ||
|
||
</html> |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leftover from testing / developing