From 9941550fa8c66c8dacc1708c6872a432dde350a1 Mon Sep 17 00:00:00 2001 From: Colin Powell Date: Fri, 29 Aug 2025 11:41:02 -0400 Subject: [PATCH] [bin] Order html page for timelapses by latest first --- bin/.bin/webcam-build-timelapses | 61 +++++++++++++------------------- 1 file changed, 25 insertions(+), 36 deletions(-) diff --git a/bin/.bin/webcam-build-timelapses b/bin/.bin/webcam-build-timelapses index 66de1e1..c4134db 100755 --- a/bin/.bin/webcam-build-timelapses +++ b/bin/.bin/webcam-build-timelapses @@ -32,7 +32,7 @@ WEBCAMS=( TIMELAPSE_SCRIPT="/usr/local/bin/make_timelapse" NTFY_URL="https://ntfy.unbl.ink/timelapse" -WEB_PREFIX="https://files.lab.unbl.ink" +WEB_PREFIX="https://files.lab.unbl.ink/webcams" # ---------------- # Yesterday's date @@ -63,56 +63,45 @@ for cam in "${WEBCAMS[@]}"; do fi done -# --- Update HTML index --- -mkdir -p "$BASE_DIR" -if [[ ! -f "$INDEX_FILE" ]]; then - cat >"$INDEX_FILE" < "$INDEX_HTML" < - + Webcam Timelapses -

Webcam Timelapses

+
+
EOF fi -# Insert new section for yesterday at the top -TMP=$(mktemp) -{ - echo "

$YESTERDAY

" - echo "
    " - for entry in "${LINKS[@]}"; do - cam="${entry%%]*}" - cam="${cam#[}" - url="${entry#* }" - echo "
  • $cam
  • " - done - echo "
" - echo "
" -} >"$TMP" +# Build new day's section +NEW_SECTION="

$YESTERDAY

    " +for link in "${LINKS[@]}"; do + cam=\$(echo "\$link" | cut -d']' -f1 | tr -d '[]') + url=\$(echo "\$link" | awk '{print \$2}') + NEW_SECTION+="
  • \$cam
  • " +done +NEW_SECTION+="
" -# Place new block after

line -awk -v block="$(cat "$TMP")" ' - /

/ { print; getline; print; print block; next } +# Insert at the top of
+tmpfile=\$(mktemp) +awk -v section="\$NEW_SECTION" ' + /
/ { print; print section; next } { print } -' "$INDEX_FILE" >"$INDEX_FILE.new" +' "\$INDEX_HTML" > "\$tmpfile" +mv "\$tmpfile" "\$INDEX_HTML" -mv "$INDEX_FILE.new" "$INDEX_FILE" -rm "$TMP" - -echo "📄 Updated HTML index: $INDEX_FILE" +echo "📝 Updated index with $YESTERDAY timelapses (newest on top)" # --- Send combined notification --- if [[ -n "$NTFY_URL" ]] && [[ ${#LINKS[@]} -gt 0 ]]; then