From 5855198867cc0586b71b6d64f4581dffc7fe6cbb Mon Sep 17 00:00:00 2001 From: Patryk Niedźwiedziński Date: Fri, 11 Oct 2019 19:33:24 +0200 Subject: Add api endpoint --- scripts/postbuild.sh | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100755 scripts/postbuild.sh (limited to 'scripts/postbuild.sh') diff --git a/scripts/postbuild.sh b/scripts/postbuild.sh new file mode 100755 index 0000000..6a0d1df --- /dev/null +++ b/scripts/postbuild.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +mkdir ./dist/api + +node ./script/generateApi.js > ./dist/api/posts.json + -- cgit 1.4.1 From c29fcbdf765e36023985996334ad711f4bc2b6fa Mon Sep 17 00:00:00 2001 From: Patryk Niedźwiedziński Date: Fri, 11 Oct 2019 19:35:27 +0200 Subject: Fix typo --- scripts/postbuild.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts/postbuild.sh') diff --git a/scripts/postbuild.sh b/scripts/postbuild.sh index 6a0d1df..53a1702 100755 --- a/scripts/postbuild.sh +++ b/scripts/postbuild.sh @@ -2,5 +2,5 @@ mkdir ./dist/api -node ./script/generateApi.js > ./dist/api/posts.json +node ./scripts/generateApi.js > ./dist/api/posts.json -- cgit 1.4.1 From 293388bf6c338fb5a2bc2d05ff526750f28bb4bc Mon Sep 17 00:00:00 2001 From: Patryk Niedźwiedziński Date: Fri, 11 Oct 2019 20:25:43 +0200 Subject: Add attribute parsing --- api/api.js | 16 +++++++++++++--- package-lock.json | 10 +++++++++- package.json | 7 ++++--- scripts/generateApi.js | 8 ++++++-- scripts/postbuild.sh | 2 +- 5 files changed, 33 insertions(+), 10 deletions(-) (limited to 'scripts/postbuild.sh') 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 diff --git a/package-lock.json b/package-lock.json index 538b1bb..18ec963 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "puszcza", + "name": "Puszcza", "version": "1.0.0", "lockfileVersion": 1, "requires": true, @@ -5334,6 +5334,14 @@ } } }, + "front-matter": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/front-matter/-/front-matter-3.0.2.tgz", + "integrity": "sha512-iBGZaWyzqgsrPGsqrXZP6N4hp5FzSKDi18nfAoYpgz3qK5sAwFv/ojmn3VS60SOgLvq6CtojNqy0y6ZNz05IzQ==", + "requires": { + "js-yaml": "^3.13.1" + } + }, "fs-extra": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-7.0.1.tgz", diff --git a/package.json b/package.json index e99735d..f85c87c 100644 --- a/package.json +++ b/package.json @@ -13,9 +13,10 @@ "test": "jest" }, "dependencies": { - "nuxt": "^2.0.0", "@nuxtjs/axios": "^5.3.6", - "@nuxtjs/pwa": "^3.0.0-0" + "@nuxtjs/pwa": "^3.0.0-0", + "front-matter": "^3.0.2", + "nuxt": "^2.0.0" }, "devDependencies": { "@vue/test-utils": "^1.0.0-beta.27", @@ -44,4 +45,4 @@ "jest-serializer-vue" ] } -} \ No newline at end of file +} diff --git a/scripts/generateApi.js b/scripts/generateApi.js index f439252..82bd583 100755 --- a/scripts/generateApi.js +++ b/scripts/generateApi.js @@ -1,13 +1,17 @@ +const fs = require('fs') + let { getPosts } = require('../api/api') let posts = getPosts() -posts = posts.map(({ year, month, day, title, route }) => { +posts = posts.map(({ year, month, day, title, attributes, route }) => { return { date: `${year}-${month}-${day}`, title, + attributes, route } }) -console.log(posts) \ No newline at end of file +fs.writeFile('./dist/api/posts.json', JSON.stringify(posts), (err) => err ? console.log(err) : null) +console.log(posts) diff --git a/scripts/postbuild.sh b/scripts/postbuild.sh index 53a1702..749bfdd 100755 --- a/scripts/postbuild.sh +++ b/scripts/postbuild.sh @@ -2,5 +2,5 @@ mkdir ./dist/api -node ./scripts/generateApi.js > ./dist/api/posts.json +node ./scripts/generateApi.js -- cgit 1.4.1 From d400b53bee9ba563810171c217710d4176b7c367 Mon Sep 17 00:00:00 2001 From: Patryk Niedźwiedziński Date: Mon, 14 Oct 2019 10:03:47 +0200 Subject: Add kronikarz --- 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, 63 insertions(+), 84 deletions(-) delete mode 100644 api/api.js create mode 100644 api/index.js (limited to 'scripts/postbuild.sh') 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 -} diff --git a/api/index.js b/api/index.js new file mode 100644 index 0000000..5658365 --- /dev/null +++ b/api/index.js @@ -0,0 +1,7 @@ +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 016f39f..6ef4e09 100644 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -1,4 +1,4 @@ -import { createRoutesArray } from './api/api.js' +import k from './api' export default { mode: 'universal', @@ -34,7 +34,7 @@ export default { ] }, generate: { - routes: createRoutesArray() + routes: k.getPosts().map(post => post.route) }, /* ** Customize the progress-bar color diff --git a/package-lock.json b/package-lock.json index 1609932..ef76df3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1944,6 +1944,28 @@ "@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", @@ -1955,6 +1977,11 @@ "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", @@ -7593,6 +7620,17 @@ "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 5e9991c..e6ceb92 100644 --- a/package.json +++ b/package.json @@ -15,8 +15,10 @@ "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 f4d5cc0..a8a086a 100644 --- a/pages/kronika/_year/_month/_day/_title/index.vue +++ b/pages/kronika/_year/_month/_day/_title/index.vue @@ -15,24 +15,19 @@