Created
May 20, 2017 01:10
-
-
Save gbabiars/18c633e418ebac96075d371caaa2ae38 to your computer and use it in GitHub Desktop.
A script to migrate posts from Ghost's exported json to Gatsby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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