diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/posts.ts | 2 | ||||
-rw-r--r-- | src/templates.ts | 55 |
2 files changed, 32 insertions, 25 deletions
diff --git a/src/posts.ts b/src/posts.ts index c727e12..5276c6c 100644 --- a/src/posts.ts +++ b/src/posts.ts @@ -18,7 +18,7 @@ export type Post = { }; export async function getPost(filename: string): Promise<MatterFile> { - return matter(await Bun.file(filename).text()); + return matter(await fs.readFile(filename, "utf8")); } export async function readPosts( diff --git a/src/templates.ts b/src/templates.ts index ac58a2c..d4642e1 100644 --- a/src/templates.ts +++ b/src/templates.ts @@ -34,22 +34,22 @@ export async function layout( $(".p-name").text(pageTitle); $("head") .children("style") - .text(await Bun.file("templates/style.css").text()); + .text(await fs.readFile("templates/style.css", "utf-8")); return $; } async function render404Page(): Promise<string> { const $ = await layout( - cheerio.load(await Bun.file("templates/404.html").text()), + cheerio.load(await fs.readFile("templates/404.html", "utf-8")), "404 Not Found", ); return $.html(); } async function renderHomepage(posts: Array<Post>): Promise<string> { - const file = matter(await Bun.file("content/_index.md").text()); + const file = matter(await fs.readFile("content/_index.md", "utf-8")); const $ = await layout( - cheerio.load(await Bun.file("templates/homepage.html").text()), + cheerio.load(await fs.readFile("templates/homepage.html", "utf-8")), config.title, ); @@ -84,7 +84,7 @@ async function renderHomepage(posts: Array<Post>): Promise<string> { async function renderPost(file: Post, content: string) { const $ = await layout( - cheerio.load(await Bun.file("templates/post.html").text()), + cheerio.load(await fs.readFile("templates/post.html", "utf-8")), file.title, ); @@ -112,7 +112,7 @@ async function renderPost(file: Post, content: string) { async function renderListPage(tag: string, posts: Post[]) { const $ = await layout( - cheerio.load(await Bun.file("templates/list.html").text()), + cheerio.load(await fs.readFile("templates/list.html", "utf-8")), tag || config.title, ); const $feed = $(".h-feed"); @@ -139,7 +139,7 @@ async function renderListPage(tag: string, posts: Post[]) { async function renderTags(tags: string[]) { const $ = await layout( - cheerio.load(await Bun.file("templates/tags.html").text()), + cheerio.load(await fs.readFile("templates/tags.html", "utf-8")), config.title, ); const $tags = $(".tags"); @@ -157,7 +157,7 @@ const makeTagURI = (specific: string) => `tag:${config.original_domain},${config.domain_start_date}:${specific}`; async function renderFeed(title: string, posts: Post[], tag?: string) { - const $ = cheerio.load(await Bun.file("templates/feed.xml").text(), { + const $ = cheerio.load(await fs.readFile("templates/feed.xml", "utf-8"), { xml: true, }); const $feed = $("feed"); @@ -186,10 +186,13 @@ async function renderFeed(title: string, posts: Post[], tag?: string) { } async function renderFeedStyles() { - const $ = cheerio.load(await Bun.file("templates/feed-styles.xsl").text(), { - xml: true, - }); - $("style").text(await Bun.file("templates/style.css").text()); + const $ = cheerio.load( + await fs.readFile("templates/feed-styles.xsl", "utf-8"), + { + xml: true, + }, + ); + $("style").text(await fs.readFile("templates/style.css", "utf-8")); return $.xml(); } @@ -202,13 +205,13 @@ export default async function generateSite() { await fs.mkdir(`public/post/${post.basename}`, { recursive: true }); tasks.push(async () => { log.debug(`Rendering post ${post.basename} to ${post.output}`); - return Bun.write(post.output, await renderPost(post, content)); + return fs.writeFile(post.output, await renderPost(post, content)); }); } await fs.mkdir("public/tags", { recursive: true }); tasks.push(async () => { log.debug("Rendering tags page to public/tags/index.html"); - return Bun.write("public/tags/index.html", await renderTags([...tags])); + return fs.writeFile("public/tags/index.html", await renderTags([...tags])); }); for (const tag of tags) { log.debug(`Processing tag ${tag}`); @@ -216,7 +219,7 @@ export default async function generateSite() { await fs.mkdir(`public/tags/${tag}`, { recursive: true }); tasks.push(async () => { log.debug(`Rendering tag ${tag} to public/tags/${tag}/index.html`); - return Bun.write( + return fs.writeFile( `public/tags/${tag}/index.html`, await renderListPage(tag, matchingPosts), ); @@ -224,7 +227,7 @@ export default async function generateSite() { tasks.push(async () => { log.debug(`Rendering tag ${tag} feed to public/tags/${tag}/atom.xml`); - return Bun.write( + return fs.writeFile( `public/tags/${tag}/atom.xml`, await renderFeed(`${config.title} - ${tag}`, matchingPosts), ); @@ -232,28 +235,32 @@ export default async function generateSite() { } tasks.push(async () => { log.debug("Rendering posts page to public/post/index.html"); - return Bun.write("public/post/index.html", await renderListPage("", posts)); + return fs.writeFile( + "public/post/index.html", + await renderListPage("", posts), + ); }); tasks.push(async () => { log.debug("Rendering site feed to public/atom.xml"); - return Bun.write("public/atom.xml", await renderFeed(config.title, posts)); + return fs.writeFile( + "public/atom.xml", + await renderFeed(config.title, posts), + ); }); tasks.push(async () => { log.debug("Rendering feed styles to public/feed-styles.xsl"); - return Bun.write("public/feed-styles.xsl", await renderFeedStyles()); + return fs.writeFile("public/feed-styles.xsl", await renderFeedStyles()); }); tasks.push(async () => { log.debug("Rendering homepage to public/index.html"); - return Bun.write( + return fs.writeFile( "public/index.html", await renderHomepage(posts.slice(0, 3)), ); }); tasks.push(async () => { log.debug("Rendering 404 page to public/404.html"); - return Bun.write("public/404.html", await render404Page()); + return fs.writeFile("public/404.html", await render404Page()); }); - for (const task of tasks) { - await task(); - } + return Promise.all(tasks.map((f) => f())); } |