From 3c5dafdc5379dacc9a188aeaef565525b0b12cca Mon Sep 17 00:00:00 2001 From: Shravan Goswami <123811742+shravanngoswamii@users.noreply.github.com> Date: Sat, 21 Dec 2024 20:00:23 +0530 Subject: [PATCH 1/2] updated and optimized insert_navbar.sh --- assets/scripts/insert_navbar.sh | 49 +++++++++++++++++---------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/assets/scripts/insert_navbar.sh b/assets/scripts/insert_navbar.sh index 80ca7c497..25a527cba 100644 --- a/assets/scripts/insert_navbar.sh +++ b/assets/scripts/insert_navbar.sh @@ -1,7 +1,8 @@ #!/bin/bash -# This script inserts a top navigation bar into Documenter.jl generated sites. +# This script inserts a top navigation bar into Documenter.jl-generated sites. # The resulting output is similar to MultiDocumenter's navigation menu. -# It checks all HTML files in the specified directory and its subdirectories. +# It checks all HTML files in the specified directory and its subdirectories, +# removes any existing navbar, then inserts the new navbar right after . # Function to print usage print_usage() { @@ -15,15 +16,17 @@ if [ "$#" -lt 2 ]; then exit 1 fi -# Directory containing HTML files (passed as the first argument to the script) +# Directory containing HTML files HTML_DIR=$1 -# URL of the navigation bar HTML file (passed as the second argument to the script) +# URL of the navigation bar HTML file NAVBAR_URL=$2 +# Shift off the first two arguments so we can parse the rest +shift 2 + # Initialize exclude list EXCLUDE_LIST="" # Parse optional arguments -shift 2 while [[ $# -gt 0 ]]; do key="$1" case $key in @@ -40,11 +43,11 @@ while [[ $# -gt 0 ]]; do done # Download the navigation bar HTML content -NAVBAR_HTML=$(curl -s $NAVBAR_URL) +NAVBAR_HTML=$(curl -s "$NAVBAR_URL") # Check if the download was successful if [ -z "$NAVBAR_HTML" ]; then - echo "Failed to download navbar HTML" + echo "Failed to download navbar HTML from '$NAVBAR_URL'" exit 1 fi @@ -60,32 +63,32 @@ should_exclude() { return 1 # Should not exclude } -# Process each HTML file in the directory and its subdirectories -find "$HTML_DIR" -name "*.html" | while read file; do +# Find and process each HTML file +find "$HTML_DIR" -type f -name "*.html" | while read -r file; do # Check if the file should be excluded - if [ ! -z "$EXCLUDE_LIST" ] && should_exclude "$file"; then + if [ -n "$EXCLUDE_LIST" ] && should_exclude "$file"; then echo "Skipping excluded file: $file" continue fi - # Remove the existing navbar HTML section if present + # Remove existing navbar (if any) between and if grep -q "" "$file"; then awk '//{flag=1;next}//{flag=0;next}!flag' "$file" > temp && mv temp "$file" echo "Removed existing navbar from $file" fi - # Read the contents of the HTML file - file_contents=$(cat "$file") - - # Insert the navbar HTML after the tag - updated_contents="${file_contents// -$NAVBAR_HTML -}" + # Insert the new navbar right after the first tag using awk + awk -v nav="$NAVBAR_HTML" ' + // { + print $0 + print nav + next + } + { print } + ' "$file" > temp && mv temp "$file" - # Write the updated contents back to the file - echo "$updated_contents" > "$file" - - # Remove trailing blank lines immediately after the navbar + # Remove excessive trailing blank lines after insertion awk 'BEGIN {RS=""; ORS="\n\n"} {gsub(/\n+$/, ""); print}' "$file" > temp_cleaned && mv temp_cleaned "$file" + echo "Inserted new navbar into $file" -done \ No newline at end of file +done From c11b23bb585076a26a96f45b7c10d44f2776e042 Mon Sep 17 00:00:00 2001 From: Shravan Goswami <123811742+shravanngoswamii@users.noreply.github.com> Date: Sat, 21 Dec 2024 20:14:31 +0530 Subject: [PATCH 2/2] Update insert_navbar.sh --- assets/scripts/insert_navbar.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/assets/scripts/insert_navbar.sh b/assets/scripts/insert_navbar.sh index 25a527cba..4e5e26df1 100644 --- a/assets/scripts/insert_navbar.sh +++ b/assets/scripts/insert_navbar.sh @@ -42,8 +42,12 @@ while [[ $# -gt 0 ]]; do esac done -# Download the navigation bar HTML content -NAVBAR_HTML=$(curl -s "$NAVBAR_URL") +# Determine if NAVBAR_SOURCE is a URL (starts with http or https) or a file path +if [[ $NAVBAR_SOURCE == http* ]]; then + NAVBAR_HTML=$(curl -s "$NAVBAR_SOURCE") +else + NAVBAR_HTML=$(cat "$NAVBAR_SOURCE") +fi # Check if the download was successful if [ -z "$NAVBAR_HTML" ]; then