From edb6cb5adc69c8f2131b7b309d91a53e21af2486 Mon Sep 17 00:00:00 2001 From: Patryk Niedźwiedziński Date: Thu, 17 Oct 2019 21:08:25 +0200 Subject: Revert "Revert "Add kronikarz"" This reverts commit 4fe5fef70b111ab0e10d91ee7060302a52ca3b76. --- api/api.js | 65 -------------------------------------------------------------- 1 file changed, 65 deletions(-) delete mode 100644 api/api.js (limited to 'api/api.js') 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(`${md.render(post.body)}`).window - const element = document.getElementsByTagName('p') - - post.body = `
${md.render(post.body)}
` - 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 -} -- cgit 1.4.1