Skip to content

added script and html for Documenter Navigation #77

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

Merged
merged 7 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions assets/scripts/README.md
Original file line number Diff line number Diff line change
@@ -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.
33 changes: 33 additions & 0 deletions assets/scripts/insert_navbar.sh
Original file line number Diff line number Diff line change
@@ -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 <body> tag
updated_contents="${file_contents/$'<body>'/$'<body>\n'$NAVBAR_HTML}"

# Write the updated contents back to the file
echo "$updated_contents" > "$file"
echo "Updated $file"
done
Loading