|
| 1 | +/// <reference types="quickbeam-types" /> |
1 | 2 | import { marked } from "marked" |
| 3 | +import fs from "node:fs" |
| 4 | +import path from "node:path" |
2 | 5 |
|
3 | | -const { fs, path } = globalThis as any |
4 | | - |
5 | | -declare const Beam: { |
6 | | - call(name: string, data?: unknown): void |
7 | | - callSync(name: string, data?: unknown): any |
8 | | - onMessage(handler: (msg: any) => void): void |
9 | | -} |
| 6 | +declare const contentDir: string |
| 7 | +declare const outputDir: string |
10 | 8 |
|
11 | 9 | interface FrontMatter { |
12 | 10 | title: string |
@@ -84,30 +82,26 @@ function renderIndex(posts: { slug: string; title: string; date: string }[]): st |
84 | 82 | </html>` |
85 | 83 | } |
86 | 84 |
|
87 | | -Beam.onMessage((config: { contentDir: string; outputDir: string }) => { |
88 | | - const { contentDir, outputDir } = config |
89 | | - |
90 | | - fs.mkdirSync(outputDir, { recursive: true }) |
| 85 | +fs.mkdirSync(outputDir, { recursive: true }) |
91 | 86 |
|
92 | | - const files = fs.readdirSync(contentDir).filter((f: string) => f.endsWith(".md")) |
93 | | - const posts: { slug: string; title: string; date: string }[] = [] |
| 87 | +const files = fs.readdirSync(contentDir).filter((f: string) => f.endsWith(".md")) |
| 88 | +const posts: { slug: string; title: string; date: string }[] = [] |
94 | 89 |
|
95 | | - for (const file of files) { |
96 | | - const source = fs.readFileSync(path.join(contentDir, file), "utf-8") |
97 | | - const { meta, body } = parseFrontMatter(source) |
| 90 | +for (const file of files) { |
| 91 | + const source = fs.readFileSync(path.join(contentDir, file), "utf-8") |
| 92 | + const { meta, body } = parseFrontMatter(source) |
98 | 93 |
|
99 | | - if (meta.draft === "true" || meta.draft === true) continue |
| 94 | + if (String(meta.draft) === "true") continue |
100 | 95 |
|
101 | | - const slug = path.basename(file, ".md") |
102 | | - const html = marked.parse(body) as string |
103 | | - const page = renderPage(meta.title, html) |
| 96 | + const slug = path.basename(file, ".md") |
| 97 | + const html = marked.parse(body) as string |
| 98 | + const page = renderPage(meta.title, html) |
104 | 99 |
|
105 | | - fs.writeFileSync(path.join(outputDir, `${slug}.html`), page) |
106 | | - posts.push({ slug, title: meta.title, date: meta.date || "undated" }) |
| 100 | + fs.writeFileSync(path.join(outputDir, `${slug}.html`), page) |
| 101 | + posts.push({ slug, title: meta.title, date: meta.date || "undated" }) |
107 | 102 |
|
108 | | - Beam.call("log", { slug, title: meta.title }) |
109 | | - } |
| 103 | + console.log(` ${slug}.html → ${meta.title}`) |
| 104 | +} |
110 | 105 |
|
111 | | - fs.writeFileSync(path.join(outputDir, "index.html"), renderIndex(posts)) |
112 | | - Beam.call("log", { slug: "index", title: `Index (${posts.length} posts)` }) |
113 | | -}) |
| 106 | +fs.writeFileSync(path.join(outputDir, "index.html"), renderIndex(posts)) |
| 107 | +console.log(` index.html → Index (${posts.length} posts)`) |
0 commit comments