Migrate From GravCMS to Hugo Static Site

27 Oct 2023

So I decided to move away from GravCMS because it did not work as I wanted. Nothing wrong with GravCMS it just didn’t work with my workflow. And I just wanted to port my theme again (previusly from Ghost)..

Convert markdown files

The markdown files from GravCMS does not work in Hugo. It may be possible to make Hugo understand the markdown used in GravCMS. Because it’s only the name of the file and the front matter that’s different.

Front matter from one of my GravCMS posts, and the name is item.md

---
title: 'Gaming on Debian, Lutris and Steam'
slug: debian-install-lutris-for-gaming
date: '2020-08-26 12:36'
publish_date: '2020-08-26 12:36'
date_updated: 1598445410
taxonomy:
    tag:
        - Debian
        - Linux
        - 'Gaming on Linux'
feed:
    limit: 10
---

Front matter for my same post in Hugo, and the name is index.md

---
title: 'Gaming on Debian, Lutris and Steam'
slug: debian-install-lutris-for-gaming
date: '2020-08-26T12:36:00+01:00'
tags:
    - Debian
    - Linux
    - 'Gaming on Linux'
feed:
    limit: 10
---

Not much have changed, the date string and tags have changed. The rest is the same and I can probably remove the “feed” part. But my scripts only converted the date string and tags.

My Tag convert script

#!/bin/bash

for DIR in */; do

  MD="$DIR/item.md"

  echo "======================================"
  echo "DIR: $DIR"
  echo "MD: $MD"

  TAGS=$( cat $MD | grep tags: )

  if [ "$TAGS" == "" ]; then
    echo "No tags"
    continue
  fi

  echo "TAGS: $TAGS"

  NTAG=$(echo "$TAGS" | \
        sed 's|tags:|taxonomy:\\n  tag:\\n    -|g' | \
        sed 's|,|\\n    -|g')

  echo "NTAGS:"
  echo "$NTAG"

  sed -E -i "s|$TAGS|$NTAG|g" "$MD"

done

And my Date convert script, this will also touch the files so it is “created” at the meta data date

#!/bin/bash

BASE_URL="https://blog.raddinox.com"

for DIR in */; do

  MD="$DIR/item.md"

  echo "======================================"
  echo "DIR: $DIR"
  echo "MD: $MD"

  OLD_DATE_TIME=$( cat $MD | grep publish_date: )
  NEW_DATE_TIME=$( cat $MD | grep publish_date: | cut -f2- -d" " )

  NEW_DT="date: $NEW_DATE_TIME\npublish_date: $NEW_DATE_TIME"

  echo "Date: $OLD_DATE_TIME"
  echo "Date: $NEW_DATE_TIME"

  sed -i "s|publish_date:|date: $NEW_DATE_TIME\npublish_date:|g" "$MD"

  # Touch to change create date on file
  T_DATE=$(echo $DATE_TIME | cut -f1 -d"T" | sed 's/-//g' )
  T_TIME=$(echo $DATE_TIME | cut -f2- -d"T" | cut -f1 -d"." | rev | cut -f2- -d":" | rev | sed 's/://g' )

  echo "T_DATE: $T_DATE"
  echo "T_TIME: $T_TIME"

  DT="$T_DATE$T_TIME"

  echo "DT: $DT"

  touch -t "$DT" "$DIR"
  touch -t "$DT" "$MD"
  sed -i "s|^date_published:.*|date_published: $P_DT|g" "$MD"

done

Migrate your theme

So when it comes to the theme, GravCMS is using Twig and Hugo is using Go templates, so the GravCMS theme will not work on Hugo. So you will have to find a new theme, or hack away and port your GravCMS theme to Hugo.

I ended up writing a new theme partly from scratch. I started a new theme from scratch and I ported over my partials from GravCMS.

My GravCMS theme was modified from some other theme and it used a lot of different CSS toolkits. So I decided when I was in the process of re-writing lots of code for my theme I removed everything CSS and started fresh using only Bootstrap and my own customized CSS.