oe7drt-website/.githooks/pre-commit

15 lines
691 B
Text
Raw Normal View History

2023-04-10 09:50:54 +02:00
#!/bin/sh
# Contents of .git/hooks/pre-commit
# Replace `last_modified_at` timestamp with current time
# https://mademistakes.com/notes/adding-last-modified-timestamps-with-git/
# enhanced the script to either update the YAML or TOML frontmatter (as i used both O_o)
2023-04-10 09:50:54 +02:00
git diff --cached --name-status | grep -E -i "^(A|M).*\.(md)$" | while read a b; do
# YAML or TOML frontmatter?
(grep -E "^---$" $b > /dev/null) && (cat $b | sed "/---.*/,/---.*/s/^lastmod:.*$/lastmod: $(date -u "+%Y-%m-%dT%H:%M:%S%z")/" > tmp)
(grep -E "^\+\+\+$" $b > /dev/null) && (cat $b | sed "/+++.*/,/+++.*/s/^lastmod.*$/lastmod = '$(date -u "+%Y-%m-%dT%H:%M:%S%z")'/" > tmp)
2023-04-10 09:50:54 +02:00
mv tmp $b
git add -p $b
2023-04-10 09:50:54 +02:00
done