diff --git a/blog.tsx b/blog.tsx index bdd8880..db0f598 100644 --- a/blog.tsx +++ b/blog.tsx @@ -27,6 +27,7 @@ import { UnoCSS, walk, } from "./deps.ts"; +import { pooledMap } from "https://deno.land/std@0.187.0/async/pool.ts"; import { Index, PostPage } from "./components.tsx"; import type { ConnInfo, FeedItem } from "./deps.ts"; import type { @@ -36,6 +37,7 @@ import type { BlogState, Post, } from "./types.d.ts"; +import { WalkEntry } from "https://deno.land/std@0.176.0/fs/walk.ts"; export { Fragment, h }; @@ -192,15 +194,23 @@ async function loadContent(blogDirectory: string, isDev: boolean) { // Read posts from the current directory and store them in memory. const postsDirectory = join(blogDirectory, "posts"); - // TODO(@satyarohith): not efficient for large number of posts. - for await ( - const entry of walk(postsDirectory) - ) { + const traversal: WalkEntry[] = []; + for await (const entry of walk(postsDirectory)) { if (entry.isFile && entry.path.endsWith(".md")) { - await loadPost(postsDirectory, entry.path); + traversal.push(entry); } } + const pool = pooledMap( + 25, + traversal, + (entry) => loadPost(postsDirectory, entry.path), + ); + + for await (const _ of pool) { + // noop + } + if (isDev) { watchForChanges(postsDirectory).catch(() => {}); }