about summary refs log tree commit diff
path: root/scripts/generateApi.js
blob: f72745e70b853ba726e52262aa8ac3e3a92e7f69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
)
console.log(posts)