about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--pages/kronika/index.vue20
-rwxr-xr-xscripts/generateApi.js5
-rwxr-xr-xscripts/postbuild.sh1
4 files changed, 17 insertions, 10 deletions
diff --git a/.gitignore b/.gitignore
index 53c3292..02a490c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
 content
+static/api/posts.json
 
 # Created by .ignore support plugin (hsz.mobi)
 ### Node template
diff --git a/pages/kronika/index.vue b/pages/kronika/index.vue
index 4a89a48..d28c2ca 100644
--- a/pages/kronika/index.vue
+++ b/pages/kronika/index.vue
@@ -1,7 +1,7 @@
 <template>
   <div style="padding-top: 20px">
     <h2>Ostatnie wpisy</h2>
-    <div class="post-list">
+    <div v-if="posts" class="post-list">
       <chronicle-post
         v-for="(post, index) in posts"
         :key="index"
@@ -23,20 +23,20 @@ export default {
   },
   async asyncData() {
     return {
-      posts: k.getPosts()
+      posts: process.client ? undefined : k.getPosts()
     }
   },
   mounted() {
-    this.getPosts()
+    if (process.client && this.posts === undefined) {
+      this.getPosts().then(posts => (this.posts = posts))
+    }
   },
   methods: {
-    getPosts() {
-      if (this.posts.length < 1) {
-        this.$axios
-          .get(`${window.location.origin}/api/posts.json`)
-          .then(r => (this.posts = r.data))
-      }
-      console.log(this.posts)
+    async getPosts() {
+      const r = await this.$axios.get(
+        `${window.location.origin}/api/posts.json`
+      )
+      return r.data
     }
   }
 }
diff --git a/scripts/generateApi.js b/scripts/generateApi.js
index f72745e..7635f02 100755
--- a/scripts/generateApi.js
+++ b/scripts/generateApi.js
@@ -20,4 +20,9 @@ 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
 )
+
+fs.writeFile('./static/api/posts.json', JSON.stringify(posts), err =>
+  err ? console.log(err) : null
+)
+
 console.log(posts)
diff --git a/scripts/postbuild.sh b/scripts/postbuild.sh
index 85e35f9..6da3659 100755
--- a/scripts/postbuild.sh
+++ b/scripts/postbuild.sh
@@ -1,6 +1,7 @@
 #!/usr/bin/env bash
 
 mkdir ./dist/api
+mkdir ./static/api
 
 node -r esm ./scripts/generateApi.js