Script To Put Date Updated Into My Markdown FIles

For a little while now I have been thinking it would be good to have a date modified on my posts and pages. Over the years I have updated quite a few of them, and some of my blog posts are more of a living post.

It is not finished. I want to make it verify there is not an updated date and verify that the date doesn’t match the file’s modified time. That is where it gets the dates from at this point.

I just ran it on my 1900 or so blog posts, and all seemed to go fine with that. As I update the script, I will update the page here too with the changes.

I wanted to post it for myself and also share it in case anyone else possibly finds it useful. If it would help you, feel free to just use it. Just don’t be a dick and claim it’s your own.

#!/bin/sh

for file in "$@"; do
set e 
N="
"
Tax="taxonomies"
t=$(stat -f %Sm -t  "%Y-%m-%dT%H:%M:%S"   $file )
updated=$(echo $N"updated = "$t$N)
sed   -i ''   "/$Tax/i\\
$updated" $file
  #
touch  -m  -d $t $file
echo $updated

done

This works on FreeBSD and doesn’t use anything that is not in the base system.