Skip to content

Instantly share code, notes, and snippets.

@gbabiars
Created May 20, 2017 01:10
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gbabiars/18c633e418ebac96075d371caaa2ae38 to your computer and use it in GitHub Desktop.
Save gbabiars/18c633e418ebac96075d371caaa2ae38 to your computer and use it in GitHub Desktop.
A script to migrate posts from Ghost's exported json to Gatsby
const fs = require('fs');
const path = require('path');
const moment = require('moment');
const json = require('./greg-babiarss-blog.ghost.2017-05-13.json');
json.data.posts
.filter(p => p.status === 'published')
.forEach(({title, slug, published_at: published, markdown}) => {
const date = moment(published).format('YYYY-MM-DD');
const content =
`---
title: ${title.replace(/\:\n/)}
date: "${date}"
path: "/${slug}/"
---
${markdown}
`;
fs.writeFileSync(path.join(__dirname, `/pages/${date}-${slug}.md`), content);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment