diff options
author | Patryk Niedźwiedziński <pniedzwiedzinski19@gmail.com> | 2019-10-14 10:03:47 +0200 |
---|---|---|
committer | Patryk Niedźwiedziński <pniedzwiedzinski19@gmail.com> | 2019-10-14 10:03:47 +0200 |
commit | d400b53bee9ba563810171c217710d4176b7c367 (patch) | |
tree | 49f339a0c05a51fedcf4d741d9828f63ab0046d3 /api/api.js | |
parent | 5cfbd5b71d149419b0b80056e652ca94d26f1a95 (diff) | |
download | puszcza-d400b53bee9ba563810171c217710d4176b7c367.tar.gz puszcza-d400b53bee9ba563810171c217710d4176b7c367.zip |
Add kronikarz
Diffstat (limited to 'api/api.js')
-rw-r--r-- | api/api.js | 65 |
1 files changed, 0 insertions, 65 deletions
diff --git a/api/api.js b/api/api.js deleted file mode 100644 index 9603f3f..0000000 --- a/api/api.js +++ /dev/null @@ -1,65 +0,0 @@ -const fs = require('fs') -const frontmatter = require('front-matter') -const md = require('markdown-it')() -const { JSDOM } = require('jsdom') - -const POSTS_PATH = './content/wpisy' - -function getPostAttributes(fileContent) { - const post = frontmatter(fileContent) - - const { document } = new JSDOM(`<body>${md.render(post.body)}</body>`).window - const element = document.getElementsByTagName('p') - - post.body = `<div>${md.render(post.body)}</div>` - post.description = element[1].textContent - - return post -} - -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}/${title}/` - const fsRoute = `${POSTS_PATH}/${year}/${month}/${day}/${file}` - - const data = getPostAttributes(fs.readFileSync(fsRoute, 'utf-8')) - - routesArray.push({ - year, - month, - day, - title, - data, - file, - fsRoute, - route - }) - }) - }) - }) - }) - } finally { - return routesArray - } -} - -function createRoutesArray() { - let posts = getPosts() - return posts.map(post => post.route) -} - -module.exports = { - getPosts, - createRoutesArray, - getPostAttributes -} |