diff options
author | nea <nea@nea.moe> | 2023-08-04 23:02:20 +0200 |
---|---|---|
committer | nea <nea@nea.moe> | 2023-08-04 23:02:20 +0200 |
commit | 2563bf526aa47b2a3e2ec3b30eff9b9f808dd270 (patch) | |
tree | 4d45199fd00419dc888035114e9339bec986dadc | |
parent | 5945696d0752cfb70ecf0c1e410547cf1c7471e3 (diff) | |
download | echowebsite-2563bf526aa47b2a3e2ec3b30eff9b9f808dd270.tar.gz echowebsite-2563bf526aa47b2a3e2ec3b30eff9b9f808dd270.tar.bz2 echowebsite-2563bf526aa47b2a3e2ec3b30eff9b9f808dd270.zip |
Add papercss
-rw-r--r-- | index.ts | 38 | ||||
-rw-r--r-- | posts/my-first-felony.md | 5 | ||||
-rw-r--r-- | template.html | 35 |
3 files changed, 63 insertions, 15 deletions
@@ -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> |