🔮 Sanity Create is here. Writing is reinvented. Try now, no developer setup

Migrating from Ghost: Problem Solving

32 replies
Last updated: May 18, 2020
yeah the markdown process is quite daunting. Working on that now myself. I’m considering generating html from the markdown, then to Sanity but not quite sure if that’s better or not than trying to convert markdown directly. This is getting me much of the way: https://www.sanity.io/guides/how-to-migrate-your-html-blog-content-from-ghost
May 14, 2020, 3:10 PM
Great blog post. I was looking at making a lot of very similar decisions, but they took it much further. I wouldn’t mind helping out if you are making your converter open source
May 14, 2020, 5:47 PM
I’d be happt to share once I get it working. Still trying to figure out how to run a node script with modules correctly 🤦
May 14, 2020, 5:53 PM
SyntaxError: Cannot use import statement outside a module
this sorta thing
May 14, 2020, 5:53 PM
ahh just use
const myLib = require('my-package')
May 14, 2020, 5:54 PM
when I do that it eventually fails on importing things inside sanity libraries, etc
May 14, 2020, 6:00 PM
You could also trying running your script with
sanity exec path/to/your-script.js
May 14, 2020, 6:04 PM
oh, interesting, I’ll give that a shot!
May 14, 2020, 6:05 PM
That could fix import errors since it lets you use the
import lib from "package"
May 14, 2020, 6:07 PM
you’re a lifesaver, that did it
May 14, 2020, 6:08 PM
I mean I now have bugs to fix but it’s working
May 14, 2020, 6:08 PM
Haha glad I could help
May 14, 2020, 6:09 PM
In that guide, can you figure out what to do with
once you’ve populated
? I’m not understanding how I get that to a file from here
May 14, 2020, 6:54 PM
I just used
sanity import myfile.ndjson my-dataset-name
May 14, 2020, 6:55 PM
I can’t figure out how to actually write out the ndjson from the processing script though, I’m sure something trivial is escaping me
May 14, 2020, 6:56 PM
I’m not sure where you’re getting
from. What I did was read the
file with node, extract out the content, and write to a
file. From there I used
sanity import
to upload the
May 14, 2020, 7:01 PM
oh sorry, in this guide they generate the ndjson file. I have a similar case where I have a handful of preprocessing I want to do so I have a nice clean ndjson at the end. That post leaves out what to do at the very end to get the file. I can ask in the group here if you aren’t sure, though
May 14, 2020, 7:03 PM
Oh from the article! Let me look again and see
May 14, 2020, 7:04 PM
What do you mean by “get the file”? they also used
sanity dataset import
after generating the ndjson file
May 14, 2020, 7:07 PM
I was expecting the script to at the very end write to disk, somehow
May 14, 2020, 7:08 PM
it’s not clear it actually does that
May 14, 2020, 7:08 PM
I see. They don’t actually show any function calls, they just make the functions
May 14, 2020, 7:11 PM
const ndSerialize = ndjson.serialize();
let ndJsonLines = '';
ndSerialize.on('data', (line) => (ndJsonLines += `${line}`));
const writeJson = (obj) => ndSerialize.write(obj);
and you call
, I get that part, it seems like it’s loading
with each line, but it never seems like that’s closed out and written to disk
May 14, 2020, 7:12 PM
I see, you’re on the right track but your logic is off. They are using the
function for every object in their ``mux-blog.ghost.json`` file
May 14, 2020, 7:14 PM
yep, I’m working on a json export I got from gatsby’s graphql so I don’t have to think too hard about the logic of finding all my posts and associated files
May 14, 2020, 7:15 PM
sure, but where does the ndjson end up? I basically am doing this script, but like is there a file that should be output or?
May 14, 2020, 7:18 PM
You have to decide the path and create the stream to write to a file
May 14, 2020, 7:33 PM
ahhhhhh ok. They write to
May 14, 2020, 7:35 PM
May 14, 2020, 7:35 PM
that’s all the final puzzle pieces, thank you, now to figuring out how to handle the markdown body cleanly
May 14, 2020, 7:35 PM
Awesome! Let me know when you work through it!
May 14, 2020, 7:36 PM
user M
any progress?
May 16, 2020, 5:00 PM
yeah made good progress on the import script last week, about the only think left I have is the markdown/html/body so I think I’ll be tackling that this week
May 18, 2020, 1:33 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?