commit 18126624d3a7f8b254df73f608bc7c1b849659a6
parent 623cf6bc64b49b11d06b10749101cfa93ecf5cd8
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date: Tue, 30 Jul 2024 10:59:47 +0200
feat: add automatic dark-mode
Diffstat:
1 file changed, 40 insertions(+), 4 deletions(-)
diff --git a/create_logs_report.sh b/create_logs_report.sh
@@ -1,30 +1,54 @@
#!/usr/bin/env bash
-export LC_TIME=en
+# configuration ----------------------------------------------------------------
+export LC_TIME=en
DB_PATH="$HOME/goaccess/${1}"
HTML_PATH="/var/www/traffic.${1}"
LOG_PATH="/var/log/apache2/${1}_access.log"
-# set dates
+# define functions -------------------------------------------------------------
+
+# HACK: enable automatic dark mode (default is bright)
+function autoTheme() {
+ echo "
+ <script>
+ // Define autoTheme function
+ function autoTheme() {
+ // If browser/client prefers dark color-scheme
+ if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
+ // unwind sidebar to load theme-toggles
+ document.querySelector('.nav-gears').click();
+ // Enable theme: dark-gray
+ document.querySelector('.theme-dark-gray').click();
+ }
+ };
+ // run autoTheme function after 1ms delay
+ setTimeout(autoTheme, 1);
+ </script>
+ " | tee --append "${1}"
+}
+
+# set dates --------------------------------------------------------------------
TODAY=$(date +%Y-%m-%d)
THIS_WEEK=$(date +%V --date "${TODAY}")
THIS_MONTH=$(date +%m --date "${TODAY}")
THIS_YEAR=$(date +%Y --date "${TODAY}")
TODAY=$(date +%d\\/%b\\/%Y --date "${TODAY}")
-# create db-paths
+# create db-paths --------------------------------------------------------------
mkdir -p "${DB_PATH}/all"
mkdir -p "${DB_PATH}/${THIS_YEAR}"
mkdir -p "${DB_PATH}/${THIS_YEAR}/${THIS_MONTH}"
mkdir -p "${DB_PATH}/${THIS_YEAR}/week-${THIS_WEEK}"
-# create output paths
+# create output paths ----------------------------------------------------------
mkdir -p "${HTML_PATH}/all"
mkdir -p "${HTML_PATH}/${THIS_YEAR}"
mkdir -p "${HTML_PATH}/${THIS_YEAR}/${THIS_MONTH}"
mkdir -p "${HTML_PATH}/${THIS_YEAR}/week-${THIS_WEEK}"
+# create logs ------------------------------------------------------------------
# create weekly log
echo "Create this Week's log"
@@ -34,6 +58,9 @@ sed -n '/'${TODAY}'/,$ p' ${LOG_PATH} | goaccess \
--load-from-disk --keep-db-files \
-
+# auto automatic theme to weekly log
+autoTheme "${HTML_PATH}/${THIS_YEAR}/week-${THIS_WEEK}/index.html"
+
# create monthly log
echo "Create this Month's log"
sed -n '/'${TODAY}'/,$ p' ${LOG_PATH} | goaccess \
@@ -42,6 +69,9 @@ sed -n '/'${TODAY}'/,$ p' ${LOG_PATH} | goaccess \
--load-from-disk --keep-db-files \
-
+# auto automatic theme to monthly log
+autoTheme "${HTML_PATH}/${THIS_YEAR}/${THIS_MONTH}/index.html"
+
# create yearly log
echo "Create this Year's log"
sed -n '/'${TODAY}'/,$ p' ${LOG_PATH} | goaccess \
@@ -50,6 +80,9 @@ sed -n '/'${TODAY}'/,$ p' ${LOG_PATH} | goaccess \
--load-from-disk --keep-db-files \
-
+# auto automatic theme to yearly log
+autoTheme "${HTML_PATH}/${THIS_YEAR}/index.html"
+
# create global log
echo "Create global log"
sed -n '/'${TODAY}'/,$ p' ${LOG_PATH} | goaccess \
@@ -58,4 +91,7 @@ sed -n '/'${TODAY}'/,$ p' ${LOG_PATH} | goaccess \
--load-from-disk --keep-db-files \
-
+# auto automatic theme to global log
+autoTheme "${HTML_PATH}/all/index.html"
+
echo "Done!"