diff options
author | Patryk Niedźwiedziński <pniedzwiedzinski19@gmail.com> | 2019-10-11 20:25:43 +0200 |
---|---|---|
committer | Patryk Niedźwiedziński <pniedzwiedzinski19@gmail.com> | 2019-10-11 20:25:43 +0200 |
commit | 293388bf6c338fb5a2bc2d05ff526750f28bb4bc (patch) | |
tree | 98065e7cdd518f095634be903d48a6f898df4348 /api | |
parent | c29fcbdf765e36023985996334ad711f4bc2b6fa (diff) | |
download | puszcza-293388bf6c338fb5a2bc2d05ff526750f28bb4bc.tar.gz puszcza-293388bf6c338fb5a2bc2d05ff526750f28bb4bc.zip |
Add attribute parsing
Diffstat (limited to 'api')
-rw-r--r-- | api/api.js | 16 |
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 |