-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
50 lines (43 loc) · 1.14 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const GhostContentAPI = require('@tryghost/content-api')
const fs = require('fs').promises
const path = require('path')
const mkdirp = require('mkdirp')
if (!process.env.GHOST_KEY) {
throw (new Error('GHOST_KEY environement variable required'))
}
const api = new GhostContentAPI({
host: 'https://osaos.codeforscience.org',
key: process.env.GHOST_KEY,
version: 'v2'
})
api.posts
.browse({include: 'tags,authors', limit: 'all'})
.then(async (posts) => {
// console.log(posts[0])
posts.map(async (post) => {
await writePost(post)
})
})
.catch((err) => {
console.error(err)
})
async function writePost(post) {
const fileName = path.join(__dirname, 'content', post.primary_tag.slug, post.slug, 'index.txt')
console.log('wrritingFile', fileName)
// console.log(post)
mkdirp.sync(path.join(__dirname, 'content', post.primary_tag.slug, post.slug))
const content = `
title: ${post.title}
----
content:
${post.html}
`
fs.writeFile(fileName, content)
.then(() =>{
return
})
.catch((err) => {
console.error(err)
return
})
}