diff options
author | Patryk Niedźwiedziński <pniedzwiedzinski19@gmail.com> | 2019-10-11 19:08:14 +0200 |
---|---|---|
committer | Patryk Niedźwiedziński <pniedzwiedzinski19@gmail.com> | 2019-10-11 19:08:14 +0200 |
commit | 1e248151d5bd60e8c94ab26f272e5e9cf900ca7a (patch) | |
tree | 1202575ae8f069e05b08babe899fb614c02e3366 /api | |
parent | 72549ed7b81fc01445fecdb7889bab4cf2a1590f (diff) | |
download | puszcza-1e248151d5bd60e8c94ab26f272e5e9cf900ca7a.tar.gz puszcza-1e248151d5bd60e8c94ab26f272e5e9cf900ca7a.zip |
Add folder structure parser
Diffstat (limited to 'api')
-rw-r--r-- | api/api.js | 49 |
1 files changed, 49 insertions, 0 deletions
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 |