Skip to content

Commit 3bdbccd

Browse files
Add versioned documentation
They are added under /en/<version>/ This might be helpful, before adding new supported languages. #1105
1 parent 11f7132 commit 3bdbccd

3 files changed

Lines changed: 126 additions & 11 deletions

File tree

.github/workflows/documentation.yaml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ jobs:
1212
steps:
1313
- name: "Checkout repository"
1414
uses: actions/checkout@v3
15+
with:
16+
fetch-depth: 0 # Need full history.
17+
fetch-tags: true # Need tags.
18+
1519

1620
- name: "Install cmake"
1721
uses: lukka/get-cmake@latest
@@ -30,19 +34,23 @@ jobs:
3034
sudo apt-get install graphviz;
3135
3236
- name: "Build documentation"
37+
run: |
38+
./tools/build_multiversion_doc.sh
39+
40+
- name: "Build examples"
3341
run: >
42+
mkdir -p multiversion_docs/main/examples;
3443
mkdir build;
3544
cd build;
3645
emcmake cmake ..
3746
-DCMAKE_BUILD_TYPE=Release
38-
-DFTXUI_BUILD_DOCS=ON
47+
-DFTXUI_BUILD_DOCS=OFF
3948
-DFTXUI_BUILD_EXAMPLES=ON
4049
-DFTXUI_BUILD_TESTS=OFF
4150
-DFTXUI_BUILD_TESTS_FUZZER=OFF
4251
-DFTXUI_ENABLE_INSTALL=OFF
4352
-DFTXUI_DEV_WARNINGS=OFF;
4453
cmake --build . --target doc;
45-
cmake --build . ;
4654
rsync -amv
4755
--include='*/'
4856
--include='*.html'
@@ -52,13 +60,13 @@ jobs:
5260
--include='*.wasm'
5361
--exclude='*'
5462
examples
55-
doc/doxygen/html;
63+
../multiversion_docs/main/examples;
5664
5765
- name: "Deploy"
5866
uses: peaceiris/actions-gh-pages@v3
5967
with:
6068
github_token: ${{ secrets.GITHUB_TOKEN }}
61-
publish_dir: build/doc/doxygen/html/
69+
publish_dir: multiversion_docs
6270
enable_jekyll: false
6371
allow_empty_commit: false
6472
force_orphan: true

doc/footer.html

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,9 @@
22
<!-- start footer part -->
33
<!--BEGIN GENERATE_TREEVIEW-->
44
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
5-
<ul>
6-
$navpath
7-
<li class="footer">$generatedby <a href="https://www.doxygen.org/index.html"><img class="footer" src="$relpath^doxygen.svg" width="104" height="31" alt="doxygen"/></a> $doxygenversion </li>
8-
</ul>
95
</div>
106
<!--END GENERATE_TREEVIEW-->
117
<!--BEGIN !GENERATE_TREEVIEW-->
12-
<hr class="footer"/><address class="footer"><small>
13-
$generatedby&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="$relpath^doxygen.svg" width="104" height="31" alt="doxygen"/></a> $doxygenversion
14-
</small></address>
158
<!--END !GENERATE_TREEVIEW-->
169
</body>
1710
</html>

tools/build_multiversion_doc.sh

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#!/bin/bash
2+
3+
set -ex
4+
5+
# Get the list of versions to build.
6+
VERSIONS="main $(git tag --list 'v*')"
7+
8+
echo "Versions to build: $VERSIONS"
9+
10+
# Create a temporary directory for the build.
11+
BUILD_DIR=$(mktemp -d)
12+
ROOT_DIR=$(pwd)
13+
OUTPUT_DIR="$ROOT_DIR/multiversion_docs"
14+
rm -rf "$OUTPUT_DIR"
15+
mkdir -p "$OUTPUT_DIR"
16+
17+
# Build the documentation for each version.
18+
for VERSION in $VERSIONS; do
19+
echo "Building documentation for version $VERSION"
20+
21+
# Checkout the version.
22+
git checkout "$VERSION"
23+
24+
# Create a build subdirectory for the version.
25+
mkdir -p "$BUILD_DIR/$VERSION"
26+
cd "$BUILD_DIR/$VERSION"
27+
28+
# Build the documentation and examples with Emscripten.
29+
cmake "$ROOT_DIR" -DFTXUI_BUILD_DOCS=ON -DFTXUI_BUILD_EXAMPLES=ON
30+
make doc
31+
32+
# Check if the documentation was generated.
33+
if [ ! -d "doc/doxygen/html" ]; then
34+
echo "Error: Doxygen documentation not found for version $VERSION"
35+
exit 1
36+
fi
37+
38+
# Move the generated documentation to the output directory.
39+
mkdir -p "$OUTPUT_DIR/en/$VERSION"
40+
mv doc/doxygen/html/* "$OUTPUT_DIR/en/$VERSION/"
41+
42+
# Move the generated examples to the output directory.
43+
mkdir -p "$OUTPUT_DIR/en/$VERSION/examples"
44+
mv examples/* "$OUTPUT_DIR/en/$VERSION/examples/"
45+
46+
cd "$ROOT_DIR"
47+
done
48+
49+
# Clean up the build directory.
50+
rm -rf "$BUILD_DIR"
51+
52+
VERSIONS_IN_JS="$(echo $VERSIONS | sed "s/ /', '/g")"
53+
54+
# Inject the version switcher into the documentation.
55+
for VERSION in $VERSIONS; do
56+
cat > "$OUTPUT_DIR/en/$VERSION/version-switcher.js" <<EOL
57+
document.addEventListener('DOMContentLoaded', function() {
58+
const projectNumber = document.getElementById('projectnumber');
59+
if (!projectNumber) {
60+
return;
61+
}
62+
63+
const version = '$VERSION';
64+
const versions = ['$VERSIONS_IN_JS'];
65+
66+
// Sort the versions in descending order (latest first)
67+
versions.sort((a, b) => {
68+
if (a === 'main') return -1;
69+
if (b === 'main') return 1;
70+
return b.localeCompare(a, undefined, { numeric: true, sensitivity: 'base' });
71+
});
72+
73+
const select = document.createElement('select');
74+
select.onchange = function() {
75+
// Replace `version` by the selected version in the URL.
76+
const selectedVersion = this.value;
77+
const currentUrl = window.location.href;
78+
const newUrl = currentUrl.replace(/$version/.*, selectedVersion);
79+
80+
// Navigate to the new URL.
81+
window.location = newUrl;
82+
};
83+
84+
for (const v of versions) {
85+
const option = document.createElement('option');
86+
option.value = v;
87+
option.text = v;
88+
if (v === version) {
89+
option.selected = true;
90+
}
91+
select.appendChild(option);
92+
}
93+
94+
projectNumber.replaceWith(select);
95+
96+
// Style to blend in with the existing theme.
97+
select.style.backgroundColor = 'rgba(0, 0, 0, 0.8)';
98+
select.style.color = 'white';
99+
select.style.border = '1px solid rgba(255, 255, 255, 0.2)';
100+
select.style.padding = '5px';
101+
select.style.borderRadius = '5px';
102+
select.style.fontSize = '14px';
103+
select.style.fontFamily = 'inherit';
104+
select.style.marginLeft = '10px';
105+
select.style.cursor = 'pointer';
106+
});
107+
EOL
108+
109+
# Inject the script into all HTML files.
110+
find "$OUTPUT_DIR/en/$VERSION/" -name "*.html" -exec sed -i 's|</body>|<script src="version-switcher.js"></script></body>|' {} +
111+
done
112+
113+
echo "Multi-version documentation generated successfully in $OUTPUT_DIR"
114+
git checkout main

0 commit comments

Comments
 (0)