Первый блог + простой генератор RSS-фида (работает в Thunderbird)

This commit is contained in:
Иван Кузьменко 2025-09-19 04:51:27 +03:00
parent 6a60ce55e5
commit 8e09b8f0d9
4 changed files with 72 additions and 0 deletions

30
src/lib/util/Blogs.ts Normal file
View file

@ -0,0 +1,30 @@
import path from 'path';
export async function fetchPostsSorted() {
const allPosts = await fetchPosts();
const sortedPosts = allPosts.sort((a, b) => {
return new Date(b.date).valueOf() - new Date(a.date).valueOf();
});
return sortedPosts;
};
export async function fetchPosts() {
const allPostFiles = import.meta.glob('/src/blogs/*.md');
const iterablePostFiles = Object.entries(allPostFiles);
const allPosts: App.BlogPost[] = await Promise.all(
iterablePostFiles.map(async ([filePath, resolver]) => {
const { metadata }: any = await resolver();
const { name } = path.parse(filePath);
return {
slug: name,
...metadata
};
})
);
return allPosts;
};