Bash Script to Convert Jekyll Front matter to Hugo
Changes
slug
is nowslug
date
(creation time) is nowdate
lastmod
(modification time) is nowlastmod
- rename all collection folders to remove the underscore (
_commands
should now becommands
) - update filenames to remove date + add that date to post metadata
- remove
layout:post
from front matter (post metadata)
Find and update existing meta tags
# 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..
# 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
# find files based on pattern (date at the beginning)
# open them files one by one and update metadata
# rename files