This commit is contained in:
Mrrp 2025-01-04 11:45:02 -08:00
parent c7f546f58a
commit b62a50b12e
12 changed files with 444 additions and 638 deletions

View file

@ -10,13 +10,19 @@ export interface Page {
hash: string;
}
export interface PageCategory {
posts: Page[];
title: string;
description: string;
tags: string[];
}
export interface PageList {
last_generated: string;
posts: Page[];
categories: Record<string, PageCategory>;
}
// Function to generate the page list
function generatePageList(pagesInfo: Record<string, any>): PageList {
function generatePageCategory(pagesInfo: Record<string, any>): PageCategory {
const pageList: Page[] = [];
for (const [path, page] of Object.entries(pagesInfo)) {
@ -35,16 +41,49 @@ function generatePageList(pagesInfo: Record<string, any>): PageList {
}
});
const pageListDict: PageList = {
last_generated: format(new Date(), 'yyyy-MM-dd HH:mm:ss'),
posts: pageList
const pageListDict: PageCategory = {
posts: pageList,
title: "",
description: "",
tags: []
};
return pageListDict;
}
// Get the page list and print it
const postList = generatePageList(pages.getPagesInfo("", "content/blog"));
const postDirectories: pages.PageLocation[] = [
{
title: "Blog",
description: "A collection of blog posts",
tags: ["blog"],
map: "blog",
root: "content/blog"
}
]
var postList: PageList = {
last_generated: format(new Date(), 'yyyy-MM-dd HH:mm:ss'),
categories: {}
}
for (const postDirectory of postDirectories) {
const pagesInfo = pages.getPagesInfo("", postDirectory);
postList.categories[postDirectory.title] = generatePageCategory(pagesInfo);
}
// Sort the posts by date
for (const category of Object.values(postList.categories)) {
category.posts.sort((a, b) => {
if (!a.metadata.date) {
return 1;
}
if (!b.metadata.date) {
return -1;
}
return new Date(b.metadata.date).getTime() - new Date(a.metadata.date).getTime();
});
}
console.log(JSON.stringify(postList, null, 2));
// Output to assets/blog_list.json (overwriting)