From ee07531ec2f7708a121b109d33b7f38db7601665 Mon Sep 17 00:00:00 2001 From: "hexlocation's laptop (asiago)" Date: Fri, 29 Mar 2024 15:12:59 -0400 Subject: [PATCH] fix structure --- config.js | 5 --- data/config.json | 5 --- data/default_posts/about.md | 3 -- data/default_posts/contact.md | 7 ---- data/default_posts/hello.md | 1 - data/default_posts/lol.md | 3 -- index.ts | 68 ----------------------------------- 7 files changed, 92 deletions(-) delete mode 100644 config.js delete mode 100644 data/config.json delete mode 100644 data/default_posts/about.md delete mode 100644 data/default_posts/contact.md delete mode 100644 data/default_posts/hello.md delete mode 100644 data/default_posts/lol.md delete mode 100644 index.ts diff --git a/config.js b/config.js deleted file mode 100644 index 7f9061a..0000000 --- a/config.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = { - branding: { - title: "hexlocation's blog" - }, -} diff --git a/data/config.json b/data/config.json deleted file mode 100644 index 5fa9c32..0000000 --- a/data/config.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "branding": { - "title": "hexlocation's blog" - } -} diff --git a/data/default_posts/about.md b/data/default_posts/about.md deleted file mode 100644 index 1f7012d..0000000 --- a/data/default_posts/about.md +++ /dev/null @@ -1,3 +0,0 @@ -# About Me. - -I'm hexlocation, a sys-admin by hobby, backend engineer & foss enjoyer. diff --git a/data/default_posts/contact.md b/data/default_posts/contact.md deleted file mode 100644 index 4e340d6..0000000 --- a/data/default_posts/contact.md +++ /dev/null @@ -1,7 +0,0 @@ -# Contact Information. - -You can find me here: -* Matrix: @hexlocation@clatter.cc -* Telegram: @inimitableX -* Discord: hex.maybe -* Email: hex[at]clatter[dot]cc diff --git a/data/default_posts/hello.md b/data/default_posts/hello.md deleted file mode 100644 index f831228..0000000 --- a/data/default_posts/hello.md +++ /dev/null @@ -1 +0,0 @@ -# This is a test! diff --git a/data/default_posts/lol.md b/data/default_posts/lol.md deleted file mode 100644 index 0585458..0000000 --- a/data/default_posts/lol.md +++ /dev/null @@ -1,3 +0,0 @@ -# Hello there! -## Powered by Markdown! -We love markdown. diff --git a/index.ts b/index.ts deleted file mode 100644 index 310715f..0000000 --- a/index.ts +++ /dev/null @@ -1,68 +0,0 @@ -import marked from "marked"; -import express from "express" -import ejs from "ejs"; -import fs from "fs"; -import path from "path"; -import jsdom from "jsdom"; -import config from "./data/config.json" - -let app = express(); - -// set view engine to ejs -app.set("view engine", "ejs") -app.set('views', path.join(__dirname, 'data','templates')) - -// type for post object -type Post = { - file: string; - title: string; - parsedPost: string; - rawPost: string; - metadata: fs.Stats; -} - -// html stripper, used for title -async function htmlstripper(html: string){ - return new jsdom.JSDOM(html).window.document.body.textContent || " "; -} - -// returns Post array -async function contentScan(){ - let posts: Post[] = [] - let postsDir = path.join(__dirname, 'data',"posts") - let files = await fs.readdirSync(postsDir).filter((name: string) => name.toLowerCase().endsWith(".md")) - for (const file of files) { - let postPath = path.join(postsDir, file) - let metadata = fs.statSync(postPath) - let postContent = fs.readFileSync(postPath, "utf-8") - posts.push( - { - file: file, - title: await htmlstripper( - await marked.parse( - postContent.split("\n")[0] - ) - ), - metadata: metadata, - parsedPost: await marked.parse(postContent), - rawPost: postContent - } - ) - } - return posts; -} - -app.get("/", async (req:express.Request,res:express.Response) => { - res.render("index", {posts: (await contentScan()), config: config}) -}); - -app.use("/post/:post", async (req:express.Request,res:express.Response) => { - let pathToPost = path.join(__dirname, "posts", req.params.post); - if(!fs.existsSync(pathToPost)) return res.end("404."); - let posts = await contentScan(); - let post = posts.filter(post => post.file === req.params.post) - if(!post[0]) return res.end("404.") - res.render("post", {posts: posts, post: post[0], config: config}) -}) - -app.listen(3024)