Watch a live product demo 👀 See how Sanity powers richer commerce experiences

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:
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

The Sanity Composable Content Cloud is the 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.

Categorized in

Related answers

Get more help in the community Slack

TopicCategoriesFeaturedRepliesLast Updated
After adding the subtitle and running this code npm run graphql-deploy It does nothingSep 15, 2020
how to limit a reference to just one entry in Studio reference input side versus the default as-many-entries-as-you-fill-in-an-array...Sep 18, 2020
Is it possible to fetch more than one "_type" using GROQ?Nov 2, 2020
I want to add a view with the Structure builder (S.view.component) where I list similar documents based on the title. What...Sep 23, 2020
Is there a structure builder example where the format of each preview for the document list is modified?Feb 3, 2021
I have an array of references to a country schema type but it always just returns NULL values for meJan 30, 2021
Hi, I need help with a query for getting the url of an image asset. Here is what I've been trying, but I only get the _ref...Dec 1, 2020
Sanity UI looks brilliant :smiley: Is something like the current date picker possible at the moment? I’m not sure if anicon...Dec 21, 2020
Hey everyone. I have been coding and may have potentially accidentally deleted something. Does anyone know how to resolve...Dec 26, 2020
Hello everyone and happy new year :raised_hands::skin-tone-2:, I have a problem with outputting Portable Text :disappointed:...Jan 1, 2021

Related contributions

Clean Next.js + Sanity app
- Template

Official(made by Sanity team)

A clean example of Next.js with embedded Sanity ready for recomposition.

Cody Olsen
Go to Clean Next.js + Sanity app

Blog with Built-in Content Editing
- Template

Official(made by Sanity team)

A Sanity-powered blog with built-in content editing and instant previews.

Go to Blog with Built-in Content Editing