From 62ed146b539df0bbab5194260f5c3b89034818a0 Mon Sep 17 00:00:00 2001 From: Dominic Reich Date: Mon, 10 Apr 2023 09:50:54 +0200 Subject: [PATCH] adds githook for lastmod line --- .githooks/pre-commit | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100755 .githooks/pre-commit diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 0000000..2629212 --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,11 @@ +#!/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/ + +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 + mv tmp $b + git add $b +done +