aboutsummaryrefslogtreecommitdiff
path: root/pages
diff options
context:
space:
mode:
authorlonkaars <l.leblansch@gmail.com>2021-03-29 10:18:51 +0200
committerlonkaars <l.leblansch@gmail.com>2021-03-29 10:18:51 +0200
commit3c418d9229bf4023816fae82e5524ae902c0e982 (patch)
tree91931e18304a9c03f7fdd8095f377e74f0143bf8 /pages
parent9eb1c1d1eee4286b6e7a124d3f5a32b3af453be0 (diff)
[meta] tag parsing
Diffstat (limited to 'pages')
-rw-r--r--pages/index.tsx2
-rw-r--r--pages/post/[id].tsx37
2 files changed, 33 insertions, 6 deletions
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<chapter>;
}
@@ -32,15 +33,41 @@ export default function Post(props: {
</div>
</div>
<div className="contentWrapper">
- <ReactMarkdown children={props.content}/>
+ <ReactMarkdown
+ children={props.content}
+ renderers={{
+ image: Image,
+ thematicBreak: Seperator,
+ }}/>
</div>
</div>
</div>
}
+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<string>) {
+ 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 }