Html to mobiledoc from a .csv

In order to test Ghost as our possible new platform, I want to test-import some existing data. I can get a post imported from a simple json file ok. But, I have lots of old posts so I need to convert lots of existing HTML text to mobiledoc format. The HTML is in a .csv that can be run through javascript to do the conversion (if there is such a library), or using some other external tool.

I have tried to install npm install “@tryghost/migrate -g” but it failed with a raft of deprecated links and things. The result is it is clearly now outdated and doesn’t work.

Does anyone have any suggestions on how I can get simple HTML converted to mobiledoc format?

Hey there @AndrewNZ :wave:

I have tried to install npm install “@tryghost/migrate -g” but it failed with a raft of deprecated links and things. The result is it is clearly now outdated and doesn’t work.

The migrate repo is extremely actively developed and used internally by the Ghost Team every single day. Perhaps you could share the error you ran into, and then we could help figure out why it didn’t install for you?

Beyond that issue, importing posts from JSON and a CSV file are not that different a problem, and there’s not a generic CSV import tool in the migrate repo atm… although there are lots of building blocks to make one.

If you don’t have lots of other processing to do, you could write a small wrapper to load the CSV into Ghost via the Admin API. If you do want to do more post-processing, handling images and so on, then you might want to use a pipeline approach like we do in the migrate repo.

Happy to dive into this more if you provide some more details of what you need.

1 Like

Thank you for your reply Hannah.

I go to my NPM directory and type [install npm install @tryghost/migrate -g]

And I get:

I don’t have python installed and I get another screen saying it couldn’t find python.

Anyway, I found an alternative using javascript since my HTML is very simple.

I’d be interested to know what I’m doing wrong but, since I have an alternative, please don’t spend time on this.

It looks like packages require at least node v16.13, but you’re on v16.6.1. You’ll need to upgrade your version of Node to that minimum version.

An easier solution, though, might be what Hannah suggested: convert the CSV to JSON and then use the Admin API to post the content to Ghost.

Hello,
I run into the same problem with Andrew above.
I want to convert a JSON with HTML fields into MobileDoc fields.
I installed Migrate sucessfully despite some warnings. But when I run “migrate json html import.json” it shows error like this.

My system:

  • Node JS 16.15
  • macOS Venture (not sure if this causes error because I had error with Python3, but resolved)
  • ghost-cli 1.23.1
  • ghost 5.22.4

I’ve tried to search accross the internal but not helpful. Do you know why?
Thanks.

I reached out to our engineer who works on these tools. They updated the package. Can you update to the latest version (0.27.0) and let me know how it goes?

1 Like

Hi Ryan,
It actually did not show any NodeJS error, but still does not generate a MobileDoc file.


I’ve tried a few commands, same results.

@RyanF can you please still comment on this?
I have exactly the same behavior on the latest (0.29.1) version. It seems to fall into try/catch (error) without really indicating what the error is. It is the same behavior for html and html-card, even on as simple file as:

"posts": [
    {
        "html": "<div class=\"center\"><h3>Test</h3></div>"
    }
]

Hi everyone,

I’ve just pushed a fix for this and published a new version to NPM.

Version 0.29.5 is what you need!

1 Like