Bash Script to Convert Jekyll Front matter to Hugo
April 9, 2017
Changes
slugis nowslugdate(creation time) is nowdatelastmod(modification time) is nowlastmod- rename all collection folders to remove the underscore (
_commandsshould now becommands) - update filenames to remove date + add that date to post metadata
- remove
layout:postfrom front matter (post metadata)
Find and update existing meta tags
code
# Find and replace metadata tags
grep -rl --null mtime . | xargs -0 sed -i '' 's/mtime/lastmod/g'
grep -rl --null ctime . | xargs -0 sed -i '' 's/ctime/date/g'
grep -rl --null slug . | xargs -0 sed -i '' 's/slug/slug/g'
Rename collection folders
Renaming folders on macOS was a simple double-click and Rename ** items. Use the Replace Text option from the dropdown, Find _ and replace with nothing. Click Rename and you're done

Remove layout: post from post
Because it was having issues with the Hugo theme, and because adding the same layout to every post is redundant and non-productive. In Hugo, you can set a default layout for all sections via config, unlike Jekyll where I had to add default layout per collection in the config, meaning in order to set default layout for 10 collections, i had to add 10 config blocks.. It didn't matter if they all used the same layout..
code
# find all files containing 'layout: post'
# and replace 'layout: post' with an empty line
grep -irl --null "layout\: post" . | xargs -0 sed -i '' 's/layout\: post//g'
Update filenames and add date to post metadata
For posts, i want to remove the date from the title and add it inside the file as post metadata
code
# find files based on pattern (date at the beginning)
# open them files one by one and update metadata
# rename files