You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
#!/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)
|
|
|
|
|
|
|
|
git diff --cached --name-status | egrep -i "^(A|M).*\.(md)$" | while read a b; do
|
|
|
|
# YAML or TOML frontmatter?
|
|
|
|
(egrep "^---$" $b > /dev/null) && (cat $b | sed "/---.*/,/---.*/s/^lastmod:.*$/lastmod: $(date -u "+%Y-%m-%dT%H:%M:%S%z")/" > tmp)
|
|
|
|
(egrep "^\+\+\+$" $b > /dev/null) && (cat $b | sed "/+++.*/,/+++.*/s/^lastmod.*$/lastmod = '$(date -u "+%Y-%m-%dT%H:%M:%S%z")'/" > tmp)
|
|
|
|
mv tmp $b
|
|
|
|
git add $b
|
|
|
|
done
|
|
|
|
|