commit fc5d1a324b7e7120f1db3cb809ce8867bbe9f2fd
parent d77ad42eeec78338843ade55a4be1512f208e2b4
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date: Sat, 15 Jun 2024 13:08:52 +0200
feat: mark currently active menu link as active
Diffstat:
2 files changed, 19 insertions(+), 0 deletions(-)
diff --git a/assets/js/mark_as_active.js b/assets/js/mark_as_active.js
@@ -0,0 +1,15 @@
+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
@@ -180,6 +180,10 @@ 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 {} \;
+
# Linking Assets ---------------------------------------------------------------
ln -sf "${1}/assets/style.css" "${1}/${2}/${3}/style.css"
ln -sf "${1}/assets/favicon.png" "${1}/${2}/${3}/favicon.png"