Migrating from Hexo to Hugo
by Emile `iMil' Heitor - 2020-03-19
Brand new iMil.net!
I’ve wanted to switch from hexo to hugo for quite a long time for various reasons, one of them being I love golang and, well, let’s just say I don’t like javascript / node much. Also, hugo documentation is pretty well done, its author is a well known figure in the golang community, and last but not least, I find the overall workflow more simple and consistent.
I delayed the migration because I wrongly thought articles front-matter modifications would be painful, but it turns out it was pretty much straightforward:
#!/bin/sh
hexodir=$1
hugodir=$2
for f in ${hexodir}/source/_posts/*.md
do
d=$(sed -n -E 's/date:\ ([0-9]{4}).*/\1/p' $f)
pdir="${hugodir}/content/posts/${d}"
mkdir -p ${pdir}
pname="${pdir}/$(basename $f)"
echo "---" > ${pname}
egrep -v '\[tags\].+\[/tags\]' $f > ${pname}
done
Basically, the only thing really missing is the heading ---
separator. While at it, I also organized the posts by year.
The last egrep -v
is here to remove tags I had from a previous migration from Wordpress to hexo, you’ll probably won’t need it.
I later realized that the layout
key, used by hexo to give a specific layout to a post was used differently in hugo, so you might also want to change it to something like categories
:
$ find hugo/content/posts/ -exec sed -i.bak -E 's/^layout:\ (.+)/categories: [\1]/' {} \;
And that’s pretty much it, I actually spent much more time working on the theme than migrating :) Hope you like it!