about summary refs log tree commit diff
path: root/scripts/generateApi.js
blob: 7635f028ad2be715fe11611faf6c5dcbd792dc26 (plain)
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
import fs from 'fs'
import k from '../api'

let posts = k.getPosts()

posts = posts.map(({ date, title, content, route }) => {
  const { year, month, day } = date
  const { description, meta } = content

  return {
    date: `${year}-${month}-${day}`,
    title,
    content: { description, meta },
    route
  }
})

posts.sort((a, b) => (a.route > b.route ? 1 : -1))

fs.writeFile('./dist/api/posts.json', JSON.stringify(posts), err =>
  err ? console.log(err) : null
)

fs.writeFile('./static/api/posts.json', JSON.stringify(posts), err =>
  err ? console.log(err) : null
)

console.log(posts)