about summary refs log tree commit diff
path: root/components/Posts/PostList/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'components/Posts/PostList/index.js')
-rw-r--r--components/Posts/PostList/index.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/components/Posts/PostList/index.js b/components/Posts/PostList/index.js
new file mode 100644
index 0000000..11d44ff
--- /dev/null
+++ b/components/Posts/PostList/index.js
@@ -0,0 +1,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