Mastodon hachyterm.io

I’m in the process of migrating from a self-hosted Ghost blog to Hugo on Netlify.

Step 1

Log into your Ghost blog.

http(s)://<your-blog-url>/ghost

Go to the Settings tab and export your content. See documentation on Ghost.org.

Step 2

Go to jbarone/ghostToHugo, install the package and use it to convert the files to a Hugo-compatible format.

You might get errors while converting dates. Try the -d "2006-01-02T15:04:05.000Z" format:

ghostToHugo <your-ghost-backup>.json -d "2006-01-02T15:04:05.000Z" -p <output-directory-name>

Step 3

Navigate to your new Hugo folder. Install a theme. Do further setup, for example for Netlify.

(Optional) Step 4

Use pandoc if you need to convert files from HTML to Markdown.

Let’s say that ghostToHugo converted your json file into a new file with Hugo frontmatter. But the content itself is still HTML.

Like so:

+++
categories = ["actual plays", "solo", "lightweight", "indie"]
date = 2012-12-08T23:00:00Z
draft = false
slug = "wu-sharp-four"
tags = ["actual plays", "solo", "lightweight", "indie"]
title = "Actual Play: Wu# With the 9Qs: Qs 7-9"

+++

<ul>
<li><a href="http://dieheart.net/wu-sharp-one">part 1</a> (setup)</li>
<li><a href="http://dieheart.net/wu-sharp-two">part 2</a> (Qs 1-3)</li>
<li><a href="http://dieheart.net/wu-sharp-three">part 3</a> (Qs 4-6)</li>
</ul>

If you use pandoc to convert the complete file from HTML to Markdown, the program will convert the frontmatter, too.

Unfortunately, you can’t tell pandoc to ignore yaml or toml metadata in HTML.

But you can use sed to tell pandoc which lines to start from. Then you can merge the converted file back together with the frontmatter.

Check on which line your content starts.
Let’s say that you want to convert all files beginning with line 12, using fish shell.

for file in *.html
  begin
    sed -ne '1,12p' "$file"
    sed -ne '12,$p' "$file" | pandoc -f html -t markdown
  end | tee (basename $file .html).md
end

This command loops over all HTML files in a folder.

We use fish’s begin ..end block to run two commands at once.

The first one takes the first 12 lines and leaves them unchanged. The second command takes the lines 12 to the end of the file and pipes them to pandoc.

Bot of these commands go to stdout. We can then use tee to create a file with the file ending .md.

Further Reading