about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPatryk Niedźwiedziński <pniedzwiedzinski19@gmail.com>2019-10-14 21:57:50 +0200
committerPatryk Niedźwiedziński <pniedzwiedzinski19@gmail.com>2019-10-14 21:57:50 +0200
commit4fe5fef70b111ab0e10d91ee7060302a52ca3b76 (patch)
treeb0d93c439bd9050938344cf4534a1ff4b4e3cc55
parentccb84eca016c8b81c074f17f188f4df47fa770ce (diff)
downloadpuszcza-4fe5fef70b111ab0e10d91ee7060302a52ca3b76.tar.gz
puszcza-4fe5fef70b111ab0e10d91ee7060302a52ca3b76.zip
Revert "Add kronikarz"
This reverts commit d400b53bee9ba563810171c217710d4176b7c367.
-rw-r--r--api/api.js65
-rw-r--r--api/index.js7
-rw-r--r--nuxt.config.js4
-rw-r--r--package-lock.json38
-rw-r--r--package.json2
-rw-r--r--pages/kronika/_year/_month/_day/_title/index.vue17
-rwxr-xr-xscripts/generateApi.js12
-rwxr-xr-xscripts/postbuild.sh2
8 files changed, 84 insertions, 63 deletions
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(`<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
+}
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 @@
 <script>
 const md = require('markdown-it')()
 import frontmatter from 'front-matter'
-import k from '~/api'
+import { getPostAttributes } from '~/api/api'
 
 export default {
   async asyncData({ params }) {
-    const { year, month, day, title } = params
-    const post = k.getPost(year, month, day, title)
+    const fileContent = await import(
+      `~/content/wpisy/${params.year}/${params.month}/${
+        params.day
+      }/${params.title.toLowerCase()}.md`
+    ).catch(e => console.log(e))
 
-    if (post === undefined) return { notFound: true }
+    if (fileContent === undefined) return { notFound: true }
+
+    const post = getPostAttributes(fileContent.default)
 
     return {
       params,
-      attributes: post.content.meta,
-      content: post.content.html
+      attributes: post.attributes,
+      content: post.body
     }
   },
   data() {
diff --git a/scripts/generateApi.js b/scripts/generateApi.js
index f72745e..128387c 100755
--- a/scripts/generateApi.js
+++ b/scripts/generateApi.js
@@ -1,16 +1,14 @@
-import fs from 'fs'
-import k from '../api'
+const fs = require('fs')
 
-let posts = k.getPosts()
+let { getPosts } = require('../api/api')
 
-posts = posts.map(({ date, title, content, route }) => {
-  const { year, month, day } = date
-  const { description, meta } = content
+let posts = getPosts()
 
+posts = posts.map(({ year, month, day, title, data, route }) => {
   return {
     date: `${year}-${month}-${day}`,
     title,
-    content: { description, meta },
+    data,
     route
   }
 })
diff --git a/scripts/postbuild.sh b/scripts/postbuild.sh
index 85e35f9..749bfdd 100755
--- a/scripts/postbuild.sh
+++ b/scripts/postbuild.sh
@@ -2,5 +2,5 @@
 
 mkdir ./dist/api
 
-node -r esm ./scripts/generateApi.js
+node ./scripts/generateApi.js