about summary refs log tree commit diff
path: root/pages/kronika
diff options
context:
space:
mode:
authorPatryk Niedźwiedziński <pniedzwiedzinski19@gmail.com>2020-01-29 12:22:09 +0100
committerGitHub <noreply@github.com>2020-01-29 12:22:09 +0100
commit3e5f329cd8c9692e24f5fd56a5e4189bf2202e0d (patch)
tree8f9140f2326df571a6990df6e9cbd1525f19e374 /pages/kronika
parent3c2ac6715dfffc2eda38e014ed0b4986ccc7f75a (diff)
parent0a8355312990db95de3aa4e946b907ed0abf5a12 (diff)
downloadpuszcza-3e5f329cd8c9692e24f5fd56a5e4189bf2202e0d.tar.gz
puszcza-3e5f329cd8c9692e24f5fd56a5e4189bf2202e0d.zip
Merge pull request #26 from 19pdh/feature/json-api
Feature/json api
Diffstat (limited to 'pages/kronika')
-rw-r--r--pages/kronika/_year/_month/_day/_title/index.vue66
1 files changed, 37 insertions, 29 deletions
diff --git a/pages/kronika/_year/_month/_day/_title/index.vue b/pages/kronika/_year/_month/_day/_title/index.vue
index 331ed7a..d67acbc 100644
--- a/pages/kronika/_year/_month/_day/_title/index.vue
+++ b/pages/kronika/_year/_month/_day/_title/index.vue
@@ -17,47 +17,55 @@
 </template>
 
 <script>
-const md = require('markdown-it')()
-import frontmatter from 'front-matter'
-import k from '~/api'
+import axios from 'axios'
+
+import { apiUrl } from '~/api'
 
 export default {
   head() {
-    return {
-      meta: [
-        {
-          hid: 'og:title',
-          property: 'og:title',
-          content: this.attributes.title,
-        },
-        {
-          hid: 'og:type',
-          property: 'og:type',
-          content: 'article',
-        },
-        {
-          hid: 'og:article:author',
-          property: 'og:article:author',
-          content: this.attributes.author,
-        },
-        {
-          hid: 'og:image',
-          property: 'og:image',
-          content: this.attributes.image,
-        },
-      ],
+    if (!this.notFound && this.attributes) {
+      return {
+        meta: [
+          {
+            hid: 'og:title',
+            property: 'og:title',
+            content: this.title,
+          },
+          {
+            hid: 'og:type',
+            property: 'og:type',
+            content: 'article',
+          },
+          {
+            hid: 'og:article:author',
+            property: 'og:article:author',
+            content: this.author,
+          },
+          {
+            hid: 'og:image',
+            property: 'og:image',
+            content: this.attributes.image,
+          },
+        ],
+      }
     }
   },
   async asyncData({ params }) {
     const { year, month, day, title } = params
-    const post = k.getPost(year, month, day, title)
+    const response = await axios
+      .get(`${apiUrl}/posts/${year}/${month}/${day}/${title}.json`)
+      .catch((err) => ({ notFound: true }))
+
+    const post = response.data
 
     if (post === undefined) return { notFound: true }
 
     return {
       params,
-      attributes: post.content.meta,
-      content: post.content.html,
+      title: post.title,
+      author: post.author,
+      attributes: post.meta,
+      content: post.content,
     }
   },
   data() {