From 3c418d9229bf4023816fae82e5524ae902c0e982 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Mon, 29 Mar 2021 10:18:51 +0200 Subject: [meta] tag parsing --- components/articleSeperator.tsx | 8 -------- components/image.tsx | 8 ++++---- components/seperator.tsx | 8 ++++++++ pages/index.tsx | 2 +- pages/post/[id].tsx | 37 ++++++++++++++++++++++++++++++++----- posts/index.md | 17 ++++++----------- 6 files changed, 51 insertions(+), 29 deletions(-) delete mode 100644 components/articleSeperator.tsx create mode 100644 components/seperator.tsx diff --git a/components/articleSeperator.tsx b/components/articleSeperator.tsx deleted file mode 100644 index 917d0be..0000000 --- a/components/articleSeperator.tsx +++ /dev/null @@ -1,8 +0,0 @@ -export default function ArticleSeperator() { - return
- - - -
-} - diff --git a/components/image.tsx b/components/image.tsx index 106c2bd..ad84ff6 100644 --- a/components/image.tsx +++ b/components/image.tsx @@ -1,12 +1,12 @@ export default function Image(props: { src: string; - title?: string; + alt?: string; }) { return
- {props.title}/ + {props.alt}/ { - props.title &&
-

{props.title}

+ props.alt &&
+

{props.alt}

}
diff --git a/components/seperator.tsx b/components/seperator.tsx new file mode 100644 index 0000000..5f05aca --- /dev/null +++ b/components/seperator.tsx @@ -0,0 +1,8 @@ +export default function ArticleSeperator() { + return
+ + + +
+} + diff --git a/pages/index.tsx b/pages/index.tsx index 1f44fec..b4f8993 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -1,4 +1,4 @@ -import Seperator from '../components/articleSeperator'; +import Seperator from '../components/seperator'; import Navbar from '../components/navbar'; import Button from '../components/button'; import Image from '../components/image'; diff --git a/pages/post/[id].tsx b/pages/post/[id].tsx index 8a1dce1..f70b21f 100644 --- a/pages/post/[id].tsx +++ b/pages/post/[id].tsx @@ -2,16 +2,17 @@ import ReactMarkdown from 'react-markdown'; import { readdirSync, readFileSync } from 'fs'; import { join } from 'path'; -// import Seperator from '../../components/articleSeperator'; +import Seperator from '../../components/seperator'; import Navbar from '../../components/navbar'; // import Button from '../../components/button'; -// import Image from '../../components/image'; +import Image from '../../components/image'; import Chapters, { chapter } from '../../components/chapters'; interface ArticleMeta { title?: string; subtitle?: string; - date?: Date; + author?: string; + date?: string; chapters?: Array; } @@ -32,15 +33,41 @@ export default function Post(props: {
- +
} +var parseTag = { + "title": (val: string) => val, + "subtitle": (val: string) => val, + "author": (val: string) => val, + "date": (val: string) => new Date(val).toDateString(), +} + +function parseMeta(file: Array) { + var meta: ArticleMeta = {}; + + file.forEach(line => { + if (!line.startsWith("[meta]: ")) return; + var tags = line.match(/\[meta\]:\s+\<(.+?)\>\s+\((.+?)\)/); + if (!tags || !tags[1] || !tags[2]) return; + if (!parseTag.hasOwnProperty(tags[1])) return; + meta[tags[1]] = parseTag[tags[1]](tags[2]); + }); + + return meta; +} + function preprocessor(fileContent: string) { var fileAsArr = fileContent.split("\n"); - var meta: ArticleMeta = {}; + var meta = parseMeta(fileAsArr); var result = fileAsArr.join("\n").trim() return { meta, result } diff --git a/posts/index.md b/posts/index.md index d0db92f..c1032f8 100644 --- a/posts/index.md +++ b/posts/index.md @@ -1,18 +1,15 @@ - - -# Loek’s excruciatingly interesting blog +[meta]: (Loek’s excruciatingly interesting blog) +[meta]: <subtitle> (Loek heeft dit geschreven) +[meta]: <author> (Loek) +[meta]: <date> (March 27 2021) Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Gravida dictum fusce ut placerat orci nulla pellentesque. Laoreet id donec ultrices tincidunt arcu. Tortor aliquam nulla facilisi cras fermentum odio eu feugiat. A scelerisque purus semper eget duis at tellus. A iaculis at erat pellentesque adipiscing commodo elit at imperdiet. Arcu bibendum at varius vel pharetra vel turpis nunc eget. Euismod in pellentesque massa placerat duis. Lorem ipsum dolor sit amet consectetur adipiscing elit. Ultrices in iaculis nunc sed augue lacus. Vestibulum mattis ullamcorper velit sed. Adipiscing diam donec adipiscing [Here's a link](https://github.com/lonkaars) -![](https://external-content.duckduckgo.com/iu/?u=http%3A%2F%2Fbarkpost-assets.s3.amazonaws.com%2Fwp-content%2Fuploads%2F2013%2F11%2FplainDoge.jpg&f=1&nofb=1) +![fonny doge meme big laugh hahaha funni image big fonny me laugh because image fonne](https://external-content.duckduckgo.com/iu/?u=http%3A%2F%2Fbarkpost-assets.s3.amazonaws.com%2Fwp-content%2Fuploads%2F2013%2F11%2FplainDoge.jpg&f=1&nofb=1) -> fonny doge meme big laugh hahaha funni image big fonny me laugh because image fonne +Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Gravida dictum fusce ut placerat orci nulla pellentesque. Laoreet id donec ultrices tincidunt arcu. Tortor aliquam nulla facilisi cras fermentum odio eu feugiat. A scelerisque purus semper eget duis at tellus. A iaculis at erat pellentesque adipiscing commodo elit at imperdiet. Arcu bibendum at varius vel pharetra vel turpis nunc eget. Euismod in pellentesque massa placerat duis. Lorem ipsum dolor sit amet consectetur adipiscing elit. Ultrices in iaculis nunc sed augue lacus. Vestibulum mattis ullamcorper velit sed. Adipiscing diam donec adipiscing --- @@ -20,8 +17,6 @@ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor i Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Gravida dictum fusce ut placerat orci nulla pellentesque. Laoreet id donec ultrices tincidunt arcu. Tortor aliquam nulla facilisi cras fermentum odio eu feugiat. A scelerisque purus semper eget duis at tellus. A iaculis at erat pellentesque adipiscing commodo elit at imperdiet. Arcu bibendum at varius vel pharetra vel turpis nunc eget. Euismod in pellentesque massa placerat duis. Lorem ipsum dolor sit amet consectetur adipiscing elit. Ultrices in iaculis nunc sed augue lacus. Vestibulum mattis ullamcorper velit sed. Adipiscing diam donec adipiscing -Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Gravida dictum fusce ut placerat orci nulla pellentesque. Laoreet id donec ultrices tincidunt arcu. Tortor aliquam nulla facilisi cras fermentum odio eu feugiat. A scelerisque purus semper eget duis at tellus. A iaculis at erat pellentesque adipiscing commodo elit at imperdiet. Arcu bibendum at varius vel pharetra vel turpis nunc eget. Euismod in pellentesque massa placerat duis. Lorem ipsum dolor sit amet consectetur adipiscing elit. Ultrices in iaculis nunc sed augue lacus. Vestibulum mattis ullamcorper velit sed. Adipiscing diam donec adipiscing - # Here's some hierarchy test ## subsection -- cgit v1.2.3