about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--api/api.js49
-rw-r--r--netlify.toml2
-rw-r--r--nuxt.config.js7
-rw-r--r--package.json6
5 files changed, 61 insertions, 5 deletions
diff --git a/.gitignore b/.gitignore
index 8c6652c..83c10f2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,5 @@
+kronika
+
 # Created by .ignore support plugin (hsz.mobi)
 ### Node template
 # Logs
diff --git a/api/api.js b/api/api.js
new file mode 100644
index 0000000..f0d3894
--- /dev/null
+++ b/api/api.js
@@ -0,0 +1,49 @@
+const fs = require('fs')
+
+const POSTS_PATH = './kronika/wpisy'
+
+function getPosts() {
+  const routesArray = []
+  try {
+    const years = fs.readdirSync(`${POSTS_PATH}`)
+    years.forEach((year) => {
+      const months = fs.readdirSync(`${POSTS_PATH}/${year}`)
+      months.forEach((month) => {
+        const days = fs.readdirSync(`${POSTS_PATH}/${year}/${month}`)
+        days.forEach((day) => {
+          const files = fs.readdirSync(`${POSTS_PATH}/${year}/${month}/${day}`)
+          files.forEach((file) => {
+            const title = file.substr(0, file.lastIndexOf('.'))
+            const route = `/kronika/${year}/${month}/${day}/${name}`
+            const fsRoute = `${POSTS_PATH}/${year}/${month}/${day}/${file}`
+            routesArray.push({
+              year,
+              month,
+              day,
+              title,
+              file,
+              fsRoute,
+              route
+            })
+          })
+        })
+      })
+    })
+  }
+  finally {
+    console.log(routesArray)
+    return routesArray
+  }
+}
+
+function createRoutesArray() {
+  let posts = getPosts()
+  return posts.map(post => post.route)
+}
+
+createRoutesArray()
+
+module.exports = {
+  getPosts,
+  createRoutesArray
+}
\ No newline at end of file
diff --git a/netlify.toml b/netlify.toml
index 3a88ace..080dfa8 100644
--- a/netlify.toml
+++ b/netlify.toml
@@ -1,4 +1,4 @@
 [build]
 
 publish = "dist/"
-command = "npm run generate"
\ No newline at end of file
+command = "npm run build"
\ No newline at end of file
diff --git a/nuxt.config.js b/nuxt.config.js
index a0ae413..caccc2b 100644
--- a/nuxt.config.js
+++ b/nuxt.config.js
@@ -1,3 +1,5 @@
+import { createRoutesArray } from './api/api.js'
+
 export default {
   mode: 'universal',
   /*
@@ -31,6 +33,9 @@ export default {
       }
     ]
   },
+  generate: {
+    routes: createRoutesArray
+  },
   /*
    ** Customize the progress-bar color
    */
@@ -67,6 +72,6 @@ export default {
     /*
      ** You can extend webpack config here
      */
-    extend(config, ctx) {}
+    extend(config, ctx) { }
   }
 }
diff --git a/package.json b/package.json
index 0237ed5..722d911 100644
--- a/package.json
+++ b/package.json
@@ -6,9 +6,9 @@
   "private": true,
   "scripts": {
     "dev": "nuxt",
-    "build": "nuxt build",
+    "prebuild": "git clone https://github.com/19pdh/kronika && rm -rf kronika/.git",
+    "build": "nuxt generate",
     "start": "nuxt start",
-    "generate": "nuxt generate",
     "test": "jest"
   },
   "dependencies": {
@@ -43,4 +43,4 @@
       "jest-serializer-vue"
     ]
   }
-}
+}
\ No newline at end of file