diff options
Diffstat (limited to 'vhosts/blog/nuldoc-src/generators')
| -rw-r--r-- | vhosts/blog/nuldoc-src/generators/post_list.ts | 48 |
1 files changed, 44 insertions, 4 deletions
diff --git a/vhosts/blog/nuldoc-src/generators/post_list.ts b/vhosts/blog/nuldoc-src/generators/post_list.ts index 67a4b996..b05f7ee6 100644 --- a/vhosts/blog/nuldoc-src/generators/post_list.ts +++ b/vhosts/blog/nuldoc-src/generators/post_list.ts @@ -6,18 +6,58 @@ import { PostPage } from "./post.ts"; export type PostListPage = Page; -export async function generatePostListPage( +export async function generatePostListPages( posts: PostPage[], config: Config, +): Promise<PostListPage[]> { + const postsPerPage = config.blog.postsPerPage; + const totalPages = Math.ceil(posts.length / postsPerPage); + const pages: PostListPage[] = []; + + for (let pageIndex = 0; pageIndex < totalPages; pageIndex++) { + const pagePosts = posts.slice( + pageIndex * postsPerPage, + (pageIndex + 1) * postsPerPage, + ); + + const page = await generatePostListPage( + pagePosts, + config, + pageIndex + 1, + totalPages, + ); + + pages.push(page); + } + + return pages; +} + +async function generatePostListPage( + posts: PostPage[], + config: Config, + currentPage: number, + totalPages: number, ): Promise<PostListPage> { const html = await renderToDOM( - PostListPage(posts, config), + PostListPage( + posts, + config, + currentPage, + totalPages, + ), ); + const destFilePath = currentPage === 1 + ? "/posts/index.html" + : `/posts/${currentPage}/index.html`; + + const href = currentPage === 1 ? "/posts/" : `/posts/${currentPage}/`; + return { root: html, renderer: "html", - destFilePath: "/posts/index.html", - href: "/posts/", + destFilePath, + href, }; } |
