commit 3a0908d57956db2c0ba114b6b9ea523aced694c0
parent d7eebea648a492b38ea94b947e9b3394c9f3ff87
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date: Sun, 4 Aug 2024 15:04:35 +0200
feat: mark menu entries as active without JS
Diffstat:
2 files changed, 2 insertions(+), 18 deletions(-)
diff --git a/assets/js/mark_as_active.js b/assets/js/mark_as_active.js
@@ -1,15 +0,0 @@
-function mark_as_active() {
- /* Get current path */
- var currPath = document.location.pathname.replace(/^.*[\\/]/, '')
- /* If current path is not empty, mark all anchros that link to it as active */
- if (currPath != "") {
- document.querySelectorAll("a[href$=\"" + currPath + "\"]").forEach(
- function(x) {
- x.classList.add("active");
- }
- );
- }
-}
-
-/* run function asynchroniously */
-setTimeout(mark_as_active, 0);
diff --git a/bin/git_update_repo_html.sh b/bin/git_update_repo_html.sh
@@ -207,9 +207,8 @@ find "${1}/${2}/${3}/" -type f -name "*.html" -exec sed -E "${INJEXP}" -i {} \;
INJEXP="s/(git\ clone)\ <a href=\"(https:\/\/.*?\.git)\">/<a href='javascript:navigator.clipboard.writeText(\"\1 \2\");alert(\"Copied to your clipboard:\\\n\1 \2\");'>\1 /g"
find "${1}/${2}/${3}/" -type f -name "*.html" -exec sed -E "${INJEXP}" -i {} \;
-# Inject "mark as active" javascript at the end of each html file
-INJEXP="s/(<\/html>)/<script\ async\ src=\"\/assets\/js\/mark_as_active.js\"><\/script>\1/"
-find "${1}/${2}/${3}/" -type f -name "*.html" -exec sed -E "${INJEXP}" -i {} \;
+# Mark menu entries as active if page is opened (needs to be run inside SHELL)
+find "${1}/${2}/${3}/" -type f -name "*.html" -exec sh -c 'sed -E "s/(href=\"[^\"]*$(basename {})\")/\1\ class=\"active\"/g" -i {}' \;
# Linking Assets ---------------------------------------------------------------
ln -sf "${1}/assets/style.css" "${1}/${2}/${3}/style.css"