Skip to content

Commit 7596dcc

Browse files
Update insert_navbar.sh
1 parent 5f7f81c commit 7596dcc

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

Diff for: assets/scripts/insert_navbar.sh

+9-7
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,16 @@ find "$HTML_DIR" -name "*.html" | while read file; do
7878
file_contents=$(cat "$file")
7979

8080
# Insert the navbar HTML after the <body> tag
81-
updated_contents="${file_contents/<body>/<body>
82-
$NAVBAR_HTML
83-
}"
84-
85-
# Write the updated contents back to the file
86-
echo "$updated_contents" > "$file"
81+
awk -v nav="$NAVBAR_HTML" '
82+
/<body>/ {
83+
print $0
84+
print nav
85+
next
86+
}
87+
{ print }
88+
' "$file" > temp && mv temp "$file"
8789

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

0 commit comments

Comments
 (0)