Hi! I have a bunch of articles in markdown, and I’d like to import them to Ghost. Is there a good way to do it?
So far the closest I found is manually creating new articles on Ghost, switching to markdown via
/md and copy-pasting the existing markdown articles. This is suboptimal however, since the markdown blocks in ghost are hard to edit when they are long - you double-click it and the cursor is always at the end of the article. Also, doing it one-by-one is too long if you have many articles.
Any tools to automate the process?
There’s a set of migration tools in the @tryghost repo. It includes tools for markdown.
I did a markdown import (posts were coming from Hugo) recently. I converted markdown to HTML with showdown, parsed the resulting HTML for image src attributes, converted images to webp, uploaded modified images to Ghost, and rewrote the image srcs. Then fed the HTML into Ghost’s Admin API, along with extracted post attributes like title, tags, publication date, etc. That let Ghost do the HTML → Lexical conversion automatically, and fidelity was great, with one exception: Markdown tables. There were a few posts with markdown tables, and I didn’t see them in my initial sampling. So if you’ve got tables, watch out! :) (There are several possible workarounds, but I didn’t know we needed one until I was done, and my client just fixed them while checking the migration import.)
The flow above means that everything is native in the Ghost editor (ignoring tables), which makes editing later a breeze!
Did you use the repo you referenced? I can’t see any markdown mentions there…
Not sure if this is of use to you because you’re looking for a less cut and paste process, but I regularly do posts that are produced by a script that produces a plain text file with markdown codes in place, and I just cut and paste that into the editor.
I do not use the Markdown block.
The editor just knows what to do with the markdown, and then it’s an editable post in the normal way.
Note: I’m doing very simple markdown for headings and links only.
You mean, you just copy-paste from a markdown file into the editor? When I tried doing the same, my editor pasted everything as plain text - that is, a link didn’t get interpreted as a link but got pasted as text.
I didn’t (I was rolling my own because it was complicated in other ways), but take a look at the tooling for Jekyll - that’s taking in markdown and could be a good starting point.
Obsidian - a markdown note taking/writing app, available for all platforms - has a plugin that talks via the API to Ghost. It only appears to handle posts (not pages) but it works well. The stuff that ends up in Ghost is imported natively i.e. not as a markdown block. That may or not suit your needs.
In use you just complete your writing and then select the little Ghost symbol in the left margin and - bingo - the draft appears in Ghost.
I think you can change the frontmatter and make is published/featured etc … but I tweak it once uploaded.
It appears to handle the majority of markdown formatting.
Which editor were you copy/pasting from? Unfortunately some editors (e.g. vscode) store markdown contents as plain text HTML when copying so our editor doesn’t see it as real plain text when pasting in order to treat it as markdown.
Right, I was copy-pasting from VS Code. I just tried doing the same from Obsidian, and the formatting was preserved. Thank you, good catch!
Thank you for the pointer - this is exactly what I was looking for! Life-saver!
Doing a full scripted workflow is going to depend a lot on the consistency of the source postings and the selection of a lowest common denominator for the target postings. But you’ll find pandoc—the Swiss Army Knife for text format conversion something that will be of great help even if you aren’t a CLI wizard.