summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--index.ts38
-rw-r--r--posts/my-first-felony.md5
-rw-r--r--template.html35
3 files changed, 63 insertions, 15 deletions
diff --git a/index.ts b/index.ts
index eadab52..13b6e9f 100644
--- a/index.ts
+++ b/index.ts
@@ -18,6 +18,27 @@ function splitPostHeader(postData: string): [string, string] {
await fs.rm("build", { recursive: true });
await fs.mkdir("build");
+declare interface PostMetadata {
+ name: string;
+ unlisted?: boolean;
+ tags?: Array<string>;
+ description?: string;
+}
+
+const baseTemplate = await fs.readFile("template.html", { encoding: "utf-8" });
+
+function makeHtmlForPost(postMetadata: PostMetadata, markdown: string): string {
+ const converter = new showdown.Converter();
+ const htmlPostBody = converter.makeHtml(markdown);
+ const variables = {
+ postBody: htmlPostBody,
+ title: postMetadata.name,
+ };
+ return baseTemplate.replace(
+ /%([a-zA-Z]+)%/g,
+ (_, match) => variables[match] ?? `Missing variable: ${match}`,
+ );
+}
for (let postPath of posts) {
const totalPostPath = `posts/${postPath}`;
@@ -27,19 +48,8 @@ for (let postPath of posts) {
}
const postText = await fs.readFile(totalPostPath, { encoding: "utf-8" });
const [postHeader, postBody] = splitPostHeader(postText);
- const postMetadata = yaml.parse(postHeader);
- const converter = new showdown.Converter();
- const htmlBody = converter.makeHtml(postBody);
-
- const primitiveHtmlDocument = `
-<html>
- <head>
- <title>${postMetadata.name}</title>
- </head>
- <body>
- ${htmlBody}
- </body>
-</html>`;
+ const postMetadata = yaml.parse(postHeader) as PostMetadata;
+ const postHtml = makeHtmlForPost(postMetadata, postBody);
const targetPath = `build/${postPath.replace(".md", ".html")}`;
- fs.writeFile(targetPath, primitiveHtmlDocument, { encoding: "utf-8" });
+ fs.writeFile(targetPath, postHtml, { encoding: "utf-8" });
}
diff --git a/posts/my-first-felony.md b/posts/my-first-felony.md
index 08a9f58..eac6623 100644
--- a/posts/my-first-felony.md
+++ b/posts/my-first-felony.md
@@ -1,7 +1,10 @@
---
name: "whatever"
-
date: today
+tags:
+ - life-stories
+ - nsfw
+unlisted: true
---
# My first felony
diff --git a/template.html b/template.html
new file mode 100644
index 0000000..d8abe1e
--- /dev/null
+++ b/template.html
@@ -0,0 +1,35 @@
+<html>
+ <head>
+ <title>%title%</title>
+ <link
+ rel="stylesheet"
+ href="https://unpkg.com/papercss@1.9.2/dist/paper.min.css"
+ />
+ <link rel="stylesheet" href="style.css" />
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+ <meta http-equiv="X-UA-Compatible" content="ie-edge" />
+ </head>
+ <body>
+ <nav class="border fixed split-nav">
+ <div class="nav-brand">
+ <h3><a href="#">ECHO</a></h3>
+ </div>
+ <div class="collapsible">
+ <input id="collapsible1" type="checkbox" name="collapsible1" />
+ <label for="collapsible1">
+ <div class="bar1"></div>
+ <div class="bar2"></div>
+ <div class="bar3"></div>
+ </label>
+ <div class="collapsible-body">
+ <ul class="inline">
+ <li><a href="#">About</a></li>
+ <li><a href="#">Blog</a></li>
+ <li><a href="https://github.com/exhq">GitHub</a></li>
+ </ul>
+ </div>
+ </div>
+ </nav>
+ <div class="paper container">%postBody%</div>
+ </body>
+</html>