Skip to content

Commit a7c1f47

Browse files
added script and html for Documenter Navigation (#77)
* added script and html for Documenter Navigation * fixed NAVBAR URL * Update assets/scripts/insert_navbar.sh * Create README.md * removed extra line * Update assets/scripts/navbar.html Co-authored-by: Hong Ge <[email protected]> * Update README.md --------- Co-authored-by: Hong Ge <[email protected]>
1 parent 8bb8500 commit a7c1f47

File tree

3 files changed

+509
-0
lines changed

3 files changed

+509
-0
lines changed

assets/scripts/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
This `scripts` folder contains utilities for building Turing language satellite packages' documentation.
2+
3+
- `insert_navbar.sh`: This function inserts a MultiDocumenter-style top navigation bar to `Documenter.jl` generated sites.
4+
- `navbar.html`: the content of the top navigation bar inserted by `insert_navbar.sh`.
5+
6+
## How to use
7+
8+
Add the following line after `makedocs()` function in `docs/make.jl` of each package:
9+
10+
```julia
11+
# Insert navbar in each html file
12+
run(`sh -c "curl -s https://raw.githubusercontent.com/TuringLang/turinglang.github.io/main/assets/scripts/insert_navbar.sh | bash -s docs/build"`)
13+
```
14+
15+
See https://github.com/TuringLang/AbstractMCMC.jl/pull/141 for an example.

assets/scripts/insert_navbar.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
# This script inserts a top navigation bar (e.g., `navbar.html`) into Documenter.jl generated sites.
4+
# The resulting output is similar to MultiDocumenter's navigation menu. The navigation menu is
5+
# hard-coded at the moment, which could be improved in the future.
6+
7+
# URL of the navigation bar HTML file
8+
NAVBAR_URL="https://raw.githubusercontent.com/TuringLang/turinglang.github.io/main/assets/scripts/navbar.html"
9+
10+
# Directory containing HTML files (passed as the first argument to the script)
11+
HTML_DIR=$1
12+
13+
# Download the navigation bar HTML content
14+
NAVBAR_HTML=$(curl -s $NAVBAR_URL)
15+
16+
# Check if the download was successful
17+
if [ -z "$NAVBAR_HTML" ]; then
18+
echo "Failed to download navbar HTML"
19+
exit 1
20+
fi
21+
22+
# Process each HTML file in the directory
23+
for file in $(find $HTML_DIR -name "*.html"); do
24+
# Read the contents of the HTML file
25+
file_contents=$(cat "$file")
26+
27+
# Insert the navbar HTML after the <body> tag
28+
updated_contents="${file_contents/$'<body>'/$'<body>\n'$NAVBAR_HTML}"
29+
30+
# Write the updated contents back to the file
31+
echo "$updated_contents" > "$file"
32+
echo "Updated $file"
33+
done

0 commit comments

Comments
 (0)