Skip to content

Instantly share code, notes, and snippets.

@eallion
Last active November 17, 2022 15:52
Show Gist options
  • Save eallion/afdbd8bf7f929a381a95cd8a6adca894 to your computer and use it in GitHub Desktop.
Save eallion/afdbd8bf7f929a381a95cd8a6adca894 to your computer and use it in GitHub Desktop.
rename hugo post filenem format date+slug with front matter
#!/bin/sh
# extracts date from file in the format
# date: 2013-08-23 14:52:59
# and prepends this to the filename
for f in *.md; do
c="$(grep -Eo 'date:\W\"(....-..-..)' $f | cut -d'"' -f2 | xargs)"
s="$(grep -Eo 'slug:\W\"(.+)' $f | cut -d'"' -f2 | xargs)"
mv "$f" "$c-$s.md"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment