about summary refs log tree commit diff
path: root/scripts/generateApi.js
blob: 128387c9189b9caa36ab4c4d2bd1e4db700c6e08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const fs = require('fs')

let { getPosts } = require('../api/api')

let posts = getPosts()

posts = posts.map(({ year, month, day, title, data, route }) => {
  return {
    date: `${year}-${month}-${day}`,
    title,
    data,
    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)