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
1216fi
1317
1418# Directory containing HTML files (passed as the first argument to the script)
1519HTML_DIR=$1
16-
1720# URL of the navigation bar HTML file (passed as the second argument to the script)
1821NAVBAR_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
2143NAVBAR_HTML=$( curl -s $NAVBAR_URL )
@@ -26,8 +48,26 @@ if [ -z "$NAVBAR_HTML" ]; then
2648 exit 1
2749fi
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
3064find " $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 "
5291done
0 commit comments