Notes

Bash Script to Convert Jekyll Front matter to Hugo

Edit on GitHub

Jekyll
2 minutes

Changes

  • slug is now slug
  • date (creation time) is now date
  • lastmod (modification time) is now lastmod
  • rename all collection folders to remove the underscore (_commands should now be commands)
  • 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

1# Find and replace metadata tags
2grep -rl --null mtime . | xargs -0 sed -i '' 's/mtime/lastmod/g'
3grep -rl --null ctime . | xargs -0 sed -i '' 's/ctime/date/g'
4grep -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

Batch rename folders on macOS

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..

1# find all files containing 'layout: post'
2# and replace 'layout: post' with an empty line
3grep -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

1# find files based on pattern (date at the beginning)
2# open them files one by one and update metadata
3# rename files