about summary refs log tree commit diff
path: root/components/Posts/PostList/index.js
blob: 7e0b1f49510a88c83eda743c0a6688ea9e606f06 (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 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,
    image: post.content.meta.image,
    description: post.content.description,
    route: post.route,
  }))

export default PostList