diff options
author | Alan Pearce | 2024-04-17 20:28:04 +0200 |
---|---|---|
committer | Alan Pearce | 2024-04-17 20:53:45 +0200 |
commit | 30fed9da228ef9bab5734e000e598ff380cb55f5 (patch) | |
tree | cfc89a40a12dcc572c0a457b62bdde129690e482 /src/posts.ts | |
parent | 1e05c18ed8e44078e3e102ff5bb8af6e25717fc9 (diff) | |
download | website-30fed9da228ef9bab5734e000e598ff380cb55f5.tar.lz website-30fed9da228ef9bab5734e000e598ff380cb55f5.tar.zst website-30fed9da228ef9bab5734e000e598ff380cb55f5.zip |
bye bye bun
Diffstat (limited to 'src/posts.ts')
-rw-r--r-- | src/posts.ts | 61 |
1 files changed, 0 insertions, 61 deletions
diff --git a/src/posts.ts b/src/posts.ts deleted file mode 100644 index 2b678b9..0000000 --- a/src/posts.ts +++ /dev/null @@ -1,61 +0,0 @@ -import path from "node:path"; -import fs from "node:fs/promises"; - -import { matter } from "toml-matter"; - -type MatterFile = ReturnType<typeof matter>; - -export type Post = { - input: string; - output: string; - basename: string; - url: string; - title: string; - date: Date; - description: string | undefined; - taxonomies: Record<string, string[]>; -}; - -export async function getPost(filename: string): Promise<MatterFile> { - return matter(await fs.readFile(filename, "utf8")); -} - -export async function readPosts( - root: string, - inputDir: string, - outputDir: string, -): Promise<{ posts: Array<Post>; tags: Set<string> }> { - let tags = new Set<string>(); - let posts = new Array<Post>(); - const subdir = path.join(root, inputDir); - for (let pathname of await fs.readdir(subdir)) { - const pathFromRoot = path.join(subdir, pathname); - const stat = await fs.stat(pathFromRoot); - if (stat.isFile() && path.extname(pathname) === ".md") { - if (pathname !== "_index.md") { - const input = pathFromRoot; - const output = pathFromRoot - .replace(root, outputDir) - .replace(".md", "/index.html"); - const url = pathFromRoot.replace(root, "").replace(".md", "/"); - - const file = await getPost(input); - - (file.data["taxonomies"] as any)?.tags?.map((t: string) => - tags.add(t.toLowerCase()), - ); - posts.push({ - input, - output, - basename: path.basename(pathname, ".md"), - url, - ...file.data, - } as Post); - } - } - } - return { - posts: posts.sort((a, b) => b.date.getTime() - a.date.getTime()), - tags, - }; -} |