Skip to content

Commit c9eede9

Browse files
exclude option in DocsNav
1 parent a56dde2 commit c9eede9

File tree

2 files changed

+56
-14
lines changed

2 files changed

+56
-14
lines changed

assets/scripts/DocsNav.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,21 @@ jobs:
3232
3333
# Define the URL of the navbar to be used
3434
NAVBAR_URL="https://raw.githubusercontent.com/TuringLang/turinglang.github.io/main/assets/scripts/TuringNavbar.html"
35-
36-
# Update all HTML files in the current directory (gh-pages root)
37-
./insert_navbar.sh . $NAVBAR_URL
38-
35+
36+
# Define file & folder to exclude (comma-separated list), Un-Comment the below line for excluding anything!
37+
# EXCLUDE_PATHS="file.extension,folder,nested/folder,nestes/file.extension"
38+
39+
# Update all HTML files in the current directory (gh-pages root), use `--exclude` only if requred!
40+
./insert_navbar.sh . $NAVBAR_URL --exclude "$EXCLUDE_PATHS"
41+
3942
# Remove the insert_navbar.sh file
4043
rm insert_navbar.sh
41-
44+
4245
# Check if there are any changes
4346
if [[ -n $(git status -s) ]]; then
4447
git add .
4548
git commit -m "Added navbar and removed insert_navbar.sh"
4649
git push "https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" gh-pages
4750
else
4851
echo "No changes to commit"
49-
fi
52+
fi

assets/scripts/insert_navbar.sh

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,43 @@
11
#!/bin/bash
2-
32
# This script inserts a top navigation bar 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.
3+
# The resulting output is similar to MultiDocumenter's navigation menu.
64
# It checks all HTML files in the specified directory and its subdirectories.
75

8-
# Check if the correct number of arguments are provided
9-
if [ "$#" -ne 2 ]; then
10-
echo "Usage: $0 <html-directory> <navbar-url>"
6+
# Function to print usage
7+
print_usage() {
8+
echo "Usage: $0 <html-directory> <navbar-url> [--exclude <path1,path2,...>]"
9+
echo " --exclude: Optional comma-separated list of paths to exclude"
10+
}
11+
12+
# Check if the minimum number of arguments are provided
13+
if [ "$#" -lt 2 ]; then
14+
print_usage
1115
exit 1
1216
fi
1317

1418
# Directory containing HTML files (passed as the first argument to the script)
1519
HTML_DIR=$1
16-
1720
# URL of the navigation bar HTML file (passed as the second argument to the script)
1821
NAVBAR_URL=$2
22+
# Initialize exclude list
23+
EXCLUDE_LIST=""
24+
25+
# Parse optional arguments
26+
shift 2
27+
while [[ $# -gt 0 ]]; do
28+
key="$1"
29+
case $key in
30+
--exclude)
31+
EXCLUDE_LIST="$2"
32+
shift 2
33+
;;
34+
*)
35+
echo "Unknown option: $1"
36+
print_usage
37+
exit 1
38+
;;
39+
esac
40+
done
1941

2042
# Download the navigation bar HTML content
2143
NAVBAR_HTML=$(curl -s $NAVBAR_URL)
@@ -26,8 +48,26 @@ if [ -z "$NAVBAR_HTML" ]; then
2648
exit 1
2749
fi
2850

51+
# Function to check if a file should be excluded
52+
should_exclude() {
53+
local file="$1"
54+
IFS=',' read -ra EXCLUDE_PATHS <<< "$EXCLUDE_LIST"
55+
for exclude_path in "${EXCLUDE_PATHS[@]}"; do
56+
if [[ "$file" == *"$exclude_path"* ]]; then
57+
return 0 # Should exclude
58+
fi
59+
done
60+
return 1 # Should not exclude
61+
}
62+
2963
# Process each HTML file in the directory and its subdirectories
3064
find "$HTML_DIR" -name "*.html" | while read file; do
65+
# Check if the file should be excluded
66+
if [ ! -z "$EXCLUDE_LIST" ] && should_exclude "$file"; then
67+
echo "Skipping excluded file: $file"
68+
continue
69+
fi
70+
3171
# Remove the existing navbar HTML section if present
3272
if grep -q "<!-- NAVBAR START -->" "$file"; then
3373
awk '/<!-- NAVBAR START -->/{flag=1;next}/<!-- NAVBAR END -->/{flag=0;next}!flag' "$file" > temp && mv temp "$file"
@@ -47,6 +87,5 @@ $NAVBAR_HTML
4787

4888
# Remove trailing blank lines immediately after the navbar
4989
awk 'BEGIN {RS=""; ORS="\n\n"} {gsub(/\n+$/, ""); print}' "$file" > temp_cleaned && mv temp_cleaned "$file"
50-
5190
echo "Inserted new navbar into $file"
5291
done

0 commit comments

Comments
 (0)