Created
November 28, 2025 03:00
-
-
Save dewomser/6cbc629bc34bed2874a5e29ce58f326d to your computer and use it in GitHub Desktop.
Jekyll frontmatter variable auf now setzen. Bash -Vibecode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # nicht getestet | |
| # Dateiname des Jekyll-Posts als Argument übergeben | |
| POST_FILE="$1" | |
| if [[ -z "$POST_FILE" ]]; then | |
| echo "Bitte gib den Pfad zur Post-Datei an." | |
| echo "Beispiel: ./update_date.sh _posts/2024-05-10-mein-post.md" | |
| exit 1 | |
| fi | |
| # Prüfen, ob die Datei existiert | |
| if [[ ! -f "$POST_FILE" ]]; then | |
| echo "Datei nicht gefunden: $POST_FILE" | |
| exit 1 | |
| fi | |
| # Aktuelles Datum für Jekyll im richtigen Format (z.B. 2025-11-28 14:30:00 +0100) | |
| NOW=$(date +"%Y-%m-%d %H:%M:%S %z") | |
| # Das "date: ..." Feld im YAML-Frontmatter ersetzen, nur im oberen Bereich (vor erstem "---" nach der ersten Zeile) | |
| awk -v datum="$NOW" ' | |
| BEGIN { found=0 } | |
| # Innerhalb des ersten Frontmatters | |
| /^---$/ && found==0 { found++ ; print; next } | |
| found==1 && /^date:/ { print "date: " datum; next } | |
| /^---$/ && found==1 { found++; print; next } | |
| { print } | |
| ' "$POST_FILE" > "$POST_FILE.tmp" && mv "$POST_FILE.tmp" "$POST_FILE" | |
| echo "Das Frontmatter-Feld 'date' in $POST_FILE wurde auf '$NOW' gesetzt." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment