From 4fe5fef70b111ab0e10d91ee7060302a52ca3b76 Mon Sep 17 00:00:00 2001 From: Patryk Niedźwiedziński Date: Mon, 14 Oct 2019 21:57:50 +0200 Subject: Revert "Add kronikarz" This reverts commit d400b53bee9ba563810171c217710d4176b7c367. --- api/api.js | 65 ++++++++++++++++++++++++ api/index.js | 7 --- nuxt.config.js | 4 +- package-lock.json | 38 -------------- package.json | 2 - pages/kronika/_year/_month/_day/_title/index.vue | 17 ++++--- scripts/generateApi.js | 12 ++--- scripts/postbuild.sh | 2 +- 8 files changed, 84 insertions(+), 63 deletions(-) create mode 100644 api/api.js delete mode 100644 api/index.js diff --git a/api/api.js b/api/api.js new file mode 100644 index 0000000..9603f3f --- /dev/null +++ b/api/api.js @@ -0,0 +1,65 @@ +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 +} diff --git a/api/index.js b/api/index.js deleted file mode 100644 index 5658365..0000000 --- a/api/index.js +++ /dev/null @@ -1,7 +0,0 @@ -import Kronikarz from 'kronikarz' - -const POSTS_PATH = './content/wpisy' - -const k = new Kronikarz(POSTS_PATH) - -export default k diff --git a/nuxt.config.js b/nuxt.config.js index 6ef4e09..016f39f 100644 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -1,4 +1,4 @@ -import k from './api' +import { createRoutesArray } from './api/api.js' export default { mode: 'universal', @@ -34,7 +34,7 @@ export default { ] }, generate: { - routes: k.getPosts().map(post => post.route) + routes: createRoutesArray() }, /* ** Customize the progress-bar color diff --git a/package-lock.json b/package-lock.json index ef76df3..1609932 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1944,28 +1944,6 @@ "@types/istanbul-lib-report": "*" } }, - "@types/jsdom": { - "version": "12.2.4", - "resolved": "https://registry.npmjs.org/@types/jsdom/-/jsdom-12.2.4.tgz", - "integrity": "sha512-q+De3S/Ri6U9uPx89YA1XuC+QIBgndIfvBaaJG0pRT8Oqa75k4Mr7G9CRZjIvlbLGIukO/31DFGFJYlQBmXf/A==", - "requires": { - "@types/node": "*", - "@types/tough-cookie": "*", - "parse5": "^4.0.0" - }, - "dependencies": { - "parse5": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/parse5/-/parse5-4.0.0.tgz", - "integrity": "sha512-VrZ7eOd3T1Fk4XWNXMgiGBK/z0MG48BWG2uQNU4I72fkQuKUTZpl+u9k+CxEG0twMVzSmXEEz12z5Fnw1jIQFA==" - } - } - }, - "@types/node": { - "version": "12.7.12", - "resolved": "https://registry.npmjs.org/@types/node/-/node-12.7.12.tgz", - "integrity": "sha512-KPYGmfD0/b1eXurQ59fXD1GBzhSQfz6/lKBxkaHX9dKTzjXbK68Zt7yGUxUsCS1jeTy/8aL+d9JEr+S54mpkWQ==" - }, "@types/q": { "version": "1.5.2", "resolved": "https://registry.npmjs.org/@types/q/-/q-1.5.2.tgz", @@ -1977,11 +1955,6 @@ "integrity": "sha512-l42BggppR6zLmpfU6fq9HEa2oGPEI8yrSPL3GITjfRInppYFahObbIQOQK3UGxEnyQpltZLaPe75046NOZQikw==", "dev": true }, - "@types/tough-cookie": { - "version": "2.3.5", - "resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-2.3.5.tgz", - "integrity": "sha512-SCcK7mvGi3+ZNz833RRjFIxrn4gI1PPR3NtuIS+6vMkvmsGjosqTJwRt5bAEFLRz+wtJMWv8+uOnZf2hi2QXTg==" - }, "@types/yargs": { "version": "13.0.2", "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-13.0.2.tgz", @@ -7620,17 +7593,6 @@ "integrity": "sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==", "dev": true }, - "kronikarz": { - "version": "0.1.3", - "resolved": "https://registry.npmjs.org/kronikarz/-/kronikarz-0.1.3.tgz", - "integrity": "sha512-isj1P/hI1Sd4Lp/rug8Tb3TrFbnSKUdiamAFvFBAuDQhe2xkm2mjMoHiGjSvYCUHdBPYKllCpthEoHfsJhYRHA==", - "requires": { - "@types/jsdom": "^12.2.4", - "front-matter": "^3.0.2", - "jsdom": "^15.1.1", - "markdown-it": "^10.0.0" - } - }, "last-call-webpack-plugin": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/last-call-webpack-plugin/-/last-call-webpack-plugin-3.0.0.tgz", diff --git a/package.json b/package.json index e6ceb92..5e9991c 100644 --- a/package.json +++ b/package.json @@ -15,10 +15,8 @@ "dependencies": { "@nuxtjs/axios": "^5.3.6", "@nuxtjs/pwa": "^3.0.0-0", - "esm": "^3.2.25", "front-matter": "^3.0.2", "jsdom": "^15.1.1", - "kronikarz": "^0.1.3", "markdown-it": "^10.0.0", "nuxt": "^2.0.0", "raw-loader": "^3.1.0" diff --git a/pages/kronika/_year/_month/_day/_title/index.vue b/pages/kronika/_year/_month/_day/_title/index.vue index 750b498..f6169b2 100644 --- a/pages/kronika/_year/_month/_day/_title/index.vue +++ b/pages/kronika/_year/_month/_day/_title/index.vue @@ -15,19 +15,24 @@