diff options
author | Patryk Niedźwiedziński <pniedzwiedzinski19@gmail.com> | 2019-10-12 15:40:51 +0200 |
---|---|---|
committer | Patryk Niedźwiedziński <pniedzwiedzinski19@gmail.com> | 2019-10-12 15:40:51 +0200 |
commit | d92f1a2a1bac3039434a16c504cc1d54c6d0409a (patch) | |
tree | c0c5b9d4539512b44a4c99a114d3ef523cc92e73 | |
parent | 7a17a28220a84c294728f572932b1619d92c1d95 (diff) | |
download | puszcza-d92f1a2a1bac3039434a16c504cc1d54c6d0409a.tar.gz puszcza-d92f1a2a1bac3039434a16c504cc1d54c6d0409a.zip |
Change posts location
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | api/api.js | 21 | ||||
-rw-r--r-- | nuxt.config.js | 2 | ||||
-rw-r--r-- | pages/kronika/_year/_month/_day/_title/index.vue | 65 | ||||
-rwxr-xr-x | scripts/prebuild.sh | 6 |
5 files changed, 80 insertions, 16 deletions
diff --git a/.gitignore b/.gitignore index 83c10f2..53c3292 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -kronika +content # Created by .ignore support plugin (hsz.mobi) ### Node template diff --git a/api/api.js b/api/api.js index a704912..1675d7e 100644 --- a/api/api.js +++ b/api/api.js @@ -1,12 +1,12 @@ const fs = require('fs') const frontmatter = require('front-matter') -const POSTS_PATH = './kronika/wpisy' +const POSTS_PATH = './content/wpisy' function getPostAttributes(filePath) { - const fileContent = fs.readFileSync(filePath, "utf-8") + const fileContent = fs.readFileSync(filePath, 'utf-8') - const post = frontmatter(fileContent); + const post = frontmatter(fileContent) return post.attributes } @@ -14,15 +14,15 @@ function getPosts() { const routesArray = [] try { const years = fs.readdirSync(`${POSTS_PATH}`) - years.forEach((year) => { + years.forEach(year => { const months = fs.readdirSync(`${POSTS_PATH}/${year}`) - months.forEach((month) => { + months.forEach(month => { const days = fs.readdirSync(`${POSTS_PATH}/${year}/${month}`) - days.forEach((day) => { + days.forEach(day => { const files = fs.readdirSync(`${POSTS_PATH}/${year}/${month}/${day}`) - files.forEach((file) => { + files.forEach(file => { const title = file.substr(0, file.lastIndexOf('.')) - const route = `/kronika/${year}/${month}/${day}/${title}` + const route = `/kronika/${year}/${month}/${day}/${title}/` const fsRoute = `${POSTS_PATH}/${year}/${month}/${day}/${file}` const attributes = getPostAttributes(fsRoute) @@ -41,8 +41,7 @@ function getPosts() { }) }) }) - } - finally { + } finally { return routesArray } } @@ -55,4 +54,4 @@ function createRoutesArray() { module.exports = { getPosts, createRoutesArray -} \ No newline at end of file +} diff --git a/nuxt.config.js b/nuxt.config.js index a98a7c7..7f66b21 100644 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -34,7 +34,7 @@ export default { ] }, generate: { - routes: createRoutesArray + routes: createRoutesArray() }, /* ** Customize the progress-bar color diff --git a/pages/kronika/_year/_month/_day/_title/index.vue b/pages/kronika/_year/_month/_day/_title/index.vue new file mode 100644 index 0000000..1148f61 --- /dev/null +++ b/pages/kronika/_year/_month/_day/_title/index.vue @@ -0,0 +1,65 @@ +<template> + <div> + <div v-if="notFound"> + <h1>404</h1> + <p>Nie znaleziono wpisu</p> + </div> + <div v-else class="article"> + <!-- <h1>{{ params.title }}</h1> + <span>{{ `${params.year}-${params.month}-${params.day}` }}</span>--> + <div class="content" v-html="content"></div> + </div> + </div> +</template> + +<script> +const md = require('markdown-it')() +import frontmatter from 'front-matter' + +export default { + async asyncData({ params }) { + console.log(params) + const fileContent = await import( + `~/content/wpisy/${params.year}/${params.month}/${ + params.day + }/${params.title.toLowerCase()}.md` + ).catch(e => console.log(e)) + + if (fileContent === undefined) return { notFound: true } + + let post = frontmatter(fileContent.default) + console.log(post.attributes) + return { + params, + attributes: post.attributes, + content: md.render(post.body) + } + }, + data() { + return { + notFound: false + } + } +} +</script> + +<style> +.article { + padding: 20px 80px 20px 80px; + width: 100%; + max-width: 1000px; + flex: 1; + background: #ffffff; + box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.25); + z-index: -1; +} +.article img { + width: 100%; + border-radius: 5px; +} +@media (max-width: 720px) { + .article { + padding: 20px 40px 20px 40px; + } +} +</style> \ No newline at end of file diff --git a/scripts/prebuild.sh b/scripts/prebuild.sh index 22d8e00..937bf5f 100755 --- a/scripts/prebuild.sh +++ b/scripts/prebuild.sh @@ -3,10 +3,10 @@ set -x set -eou pipefail -if [ -d ./kronika ]; then - cd kronika +if [ -d ./content ]; then + cd content git pull cd .. else - git clone https://github.com/19pdh/kronika + git clone https://github.com/19pdh/kronika content fi |