about summary refs log tree commit diff
path: root/api
diff options
context:
space:
mode:
Diffstat (limited to 'api')
-rw-r--r--api/api.js16
1 files changed, 13 insertions, 3 deletions
diff --git a/api/api.js b/api/api.js
index 34a53a0..a704912 100644
--- a/api/api.js
+++ b/api/api.js
@@ -1,7 +1,15 @@
 const fs = require('fs')
+const frontmatter = require('front-matter')
 
 const POSTS_PATH = './kronika/wpisy'
 
+function getPostAttributes(filePath) {
+  const fileContent = fs.readFileSync(filePath, "utf-8")
+
+  const post = frontmatter(fileContent);
+  return post.attributes
+}
+
 function getPosts() {
   const routesArray = []
   try {
@@ -14,13 +22,17 @@ function getPosts() {
           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 route = `/kronika/${year}/${month}/${day}/${title}`
             const fsRoute = `${POSTS_PATH}/${year}/${month}/${day}/${file}`
+
+            const attributes = getPostAttributes(fsRoute)
+
             routesArray.push({
               year,
               month,
               day,
               title,
+              attributes,
               file,
               fsRoute,
               route
@@ -40,8 +52,6 @@ function createRoutesArray() {
   return posts.map(post => post.route)
 }
 
-createRoutesArray()
-
 module.exports = {
   getPosts,
   createRoutesArray