The machine in Ghost

Information Flaneur 2023-05-21

Summary:

This will probably be my last post published with Ghost. I was a backer of Ghost's original Kickstarter campaign, and I believed the hype. John O'Nolan's promise was that Ghost would be "Just a Blogging Platform", but since then it has changed focus to be "The professional publishing platform". This includes big changes in Ghost 2.0 that include changing the default editing screen from Markdown to WYSIWYG. Far from being 'just a blogging platform', Ghost clearly now wants to be 'WordPress but written in nodejs'. That's fine, but it's not what I signed up for, and I've been eyeing off static site generators for a little while. I'm now about to take the plunge and move from Ghost to ...well, to a static site. But I'll be generating it with Eleventy. More on that in my next post, but this is my September post for GLAM Blog Club and I'm going to share a few of the, well, strange things I've discovered about Ghost while doing some processing on my export file.

Where's the Markdown?

Ghost has a feature - tellingly still in "Labs" in my version - where you can essentially export your database in one big JSON file. If you want your images as well, too bad, but that's not what I want to talk about here. Back in November last year I wrote about a nodejs script I wrote to translate the Ghost JSON data into a WordPress XML import file. I've taken the guts of that script and repurposed it to export all the posts as Markdown files. I could have used ghost-export but I wanted to keep all the metadata with the files - title, tags, and importantly the permalink. More on permalinks later. I may contribute some code to ghost-export at some point to add this as a feature, but in the short term I just rewrote my existing script for my particular needs.

Because Ghost posts are originally written in Markdown, it should theoretically be easy to get the original Markdown back out again. It is relatively straightforward once you know where to look, but the structure of the export file is surprising to say the least. The file comes out Ghost like this (simplified for clarity):

db: [
  {
    "data":{
      "settings": {...},
      "posts": [
        {
          "id": "123456",
          "title": "My Awesome Post",
          "published_at": "2014-02-10T11:48:33.000Z",
          "mobiledoc": "{... \"cards\":[[\"card-markdown\",{\"cardName\":\"card-markdown\",\"markdown\":\"This is where the Markdown is."}"
        }
      ]
    }
  }
]

Haha ๐Ÿ™ƒ what the hell? For reasons I can't quite fathom, not only is the markdown hidden inside a key called "mobiledoc", but the value of "mobiledoc" is a string - not an object. I'm sure there's some logical reason for this, though I can't think what it is. The consequences are that in order to get at the data, you have to de-stringify mobiledoc first:


for (let post of backup.db[0].data.posts) {
  // this doesn't work
  console.log(post.mobiledoc.mdJSON.cards[0][1].markdown)

  // this works by de-stringifying mobiledoc so it can be used as an object
  let mdJSON = JSON.parse(post.

Link:

https://www.hughrundle.net/2018/09/30/the-machine-in-ghost/index.html/

From feeds:

Library ยป Information Flaneur

Tags:

Authors:

hugh

Date tagged:

05/21/2023, 16:19

Date published:

09/30/2018, 04:28