Skip to content

Instantly share code, notes, and snippets.

@conoro
Created July 10, 2016 09:55
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save conoro/9fcd17f2673fb301ab6a631459d2926e to your computer and use it in GitHub Desktop.
Save conoro/9fcd17f2673fb301ab6a631459d2926e to your computer and use it in GitHub Desktop.
Hexo to Hugo converter
# code is from http://helw.net/2015/07/19/migrating-to-hugo-from-hexo/
# Ran fine on Windows 10 with MSysGit installed
# cd to directory with all the md files from Hexo
# bash hexo2hugo.sh
---
# ensure dates don't start with single quotes
for file in *; do awk '{
if ($1 == "date:") {
gsub("\047", "", $0); print;
} else {
print $0;
}
}' "$file" > temp.md && mv temp.md $file ; done
# fix the dates and add the three dashes as the first line
for file in *; do awk '{
if (NR == 1) { print "---"; }
if ($1 == "date:") {
printf("%s %sT%s+00:00\n", $1, $2, $3);
} else {
print $0;
}
}' "$file" > temp.md && mv temp.md $file ; done
# wrap dates with quotes that aren't wrapped in quotes
for file in *; do awk '{
if ($1 == "date:") {
if ($2 ~ /^"/) {
print $0;
} else {
printf("%s \"%s\"\n", $1, $2);
}
} else { print $0; }
}' "$file" > temp.md && mv temp.md $file; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment