1
1
#! /bin/bash
2
-
3
2
# 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.
6
4
# It checks all HTML files in the specified directory and its subdirectories.
7
5
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
11
15
exit 1
12
16
fi
13
17
14
18
# Directory containing HTML files (passed as the first argument to the script)
15
19
HTML_DIR=$1
16
-
17
20
# URL of the navigation bar HTML file (passed as the second argument to the script)
18
21
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
19
41
20
42
# Download the navigation bar HTML content
21
43
NAVBAR_HTML=$( curl -s $NAVBAR_URL )
@@ -26,8 +48,26 @@ if [ -z "$NAVBAR_HTML" ]; then
26
48
exit 1
27
49
fi
28
50
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
+
29
63
# Process each HTML file in the directory and its subdirectories
30
64
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
+
31
71
# Remove the existing navbar HTML section if present
32
72
if grep -q " <!-- NAVBAR START -->" " $file " ; then
33
73
awk ' /<!-- NAVBAR START -->/{flag=1;next}/<!-- NAVBAR END -->/{flag=0;next}!flag' " $file " > temp && mv temp " $file "
@@ -47,6 +87,5 @@ $NAVBAR_HTML
47
87
48
88
# Remove trailing blank lines immediately after the navbar
49
89
awk ' BEGIN {RS=""; ORS="\n\n"} {gsub(/\n+$/, ""); print}' " $file " > temp_cleaned && mv temp_cleaned " $file "
50
-
51
90
echo " Inserted new navbar into $file "
52
91
done
0 commit comments