30 lines
688 B
TypeScript
30 lines
688 B
TypeScript
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;
|
|
};
|