about summary refs log tree commit diff
path: root/components/Posts/PostList/index.js
blob: 11d44ff0361bdff4e90a83d0b3f6272c43be1e11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import axios from 'axios'

import k from '~/api'
import PostList from './PostList'

export const getPosts = async () => {
  if (process.client) {
    let posts = await axios.get(`${window.location.origin}/api/posts.json`)
    return parsePosts(posts.data)
  } else {
    return parsePosts(k.getPosts())
  }
}

export const parsePosts = posts =>
  posts.map(post => ({
    title: post.content.meta.title,
    description: post.content.description,
    route: post.route
  }))

export default PostList