update git hook 'pre-commit' to select between YAML or TOML frontmatter
This commit is contained in:
parent
db1e3ff33b
commit
8d06534e7b
1 changed files with 5 additions and 1 deletions
|
@ -2,9 +2,13 @@
|
||||||
# Contents of .git/hooks/pre-commit
|
# Contents of .git/hooks/pre-commit
|
||||||
# Replace `last_modified_at` timestamp with current time
|
# Replace `last_modified_at` timestamp with current time
|
||||||
# https://mademistakes.com/notes/adding-last-modified-timestamps-with-git/
|
# 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
|
git diff --cached --name-status | egrep -i "^(A|M).*\.(md)$" | while read a b; do
|
||||||
cat $b | sed "/---.*/,/---.*/s/^lastmod:.*$/lastmod: $(date -u "+%Y-%m-%dT%H:%M:%S%z")/" > tmp
|
# 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
|
mv tmp $b
|
||||||
git add $b
|
git add $b
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue