diff --git a/assets/scripts/README.md b/assets/scripts/README.md new file mode 100644 index 000000000..7bdf2798b --- /dev/null +++ b/assets/scripts/README.md @@ -0,0 +1,15 @@ +This `scripts` folder contains utilities for building Turing language satellite packages' documentation. + +- `insert_navbar.sh`: This function inserts a MultiDocumenter-style top navigation bar to `Documenter.jl` generated sites. +- `navbar.html`: the content of the top navigation bar inserted by `insert_navbar.sh`. + +## How to use + +Add the following line after `makedocs()` function in `docs/make.jl` of each package: + +```julia +# Insert navbar in each html file +run(`sh -c "curl -s https://raw.githubusercontent.com/TuringLang/turinglang.github.io/main/assets/scripts/insert_navbar.sh | bash -s docs/build"`) +``` + +See https://github.com/TuringLang/AbstractMCMC.jl/pull/141 for an example. diff --git a/assets/scripts/insert_navbar.sh b/assets/scripts/insert_navbar.sh new file mode 100644 index 000000000..127574093 --- /dev/null +++ b/assets/scripts/insert_navbar.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +# This script inserts a top navigation bar (e.g., `navbar.html`) into Documenter.jl generated sites. +# The resulting output is similar to MultiDocumenter's navigation menu. The navigation menu is +# hard-coded at the moment, which could be improved in the future. + +# URL of the navigation bar HTML file +NAVBAR_URL="https://raw.githubusercontent.com/TuringLang/turinglang.github.io/main/assets/scripts/navbar.html" + +# Directory containing HTML files (passed as the first argument to the script) +HTML_DIR=$1 + +# Download the navigation bar HTML content +NAVBAR_HTML=$(curl -s $NAVBAR_URL) + +# Check if the download was successful +if [ -z "$NAVBAR_HTML" ]; then + echo "Failed to download navbar HTML" + exit 1 +fi + +# Process each HTML file in the directory +for file in $(find $HTML_DIR -name "*.html"); do + # Read the contents of the HTML file + file_contents=$(cat "$file") + + # Insert the navbar HTML after the tag + updated_contents="${file_contents/$''/$'\n'$NAVBAR_HTML}" + + # Write the updated contents back to the file + echo "$updated_contents" > "$file" + echo "Updated $file" +done \ No newline at end of file diff --git a/assets/scripts/navbar.html b/assets/scripts/navbar.html new file mode 100644 index 000000000..7a9bb74cf --- /dev/null +++ b/assets/scripts/navbar.html @@ -0,0 +1,461 @@ + + +