feat: extend blog post indexing

This commit is contained in:
Alexander Daichendt 2022-08-04 13:24:39 +02:00
parent c8061bf98c
commit 3244c4c692

View file

@ -1,7 +1,11 @@
import type { BlogPostFrontmatter, BlogPostMeta } from '../../lib/utils/types';
const removeExtension = (path: string) => path.replace(/\.[^.]*$/g, '').replace('/index', '');
export async function GET() {
const modules = import.meta.glob('./*.svx');
const modulesSVX = import.meta.glob('./**/*.svx');
const modulesMD = import.meta.glob('./**/*.md');
const modules = { ...modulesMD, ...modulesSVX };
const posts: BlogPostMeta[] = [];
const resolved = (await Promise.all(Object.values(modules).map((f) => f()))) as {
metadata: BlogPostFrontmatter;
@ -10,7 +14,7 @@ export async function GET() {
const path = Object.keys(modules)[index];
const { metadata } = file;
if (!metadata.hidden) posts.push({ ...metadata, href: `blog/${path.replace('.svx', '')}` });
if (!metadata.hidden) posts.push({ ...metadata, href: `blog/${removeExtension(path)}` });
});
posts.sort((a, b) => new Date(b.created).valueOf() - new Date(a.created).valueOf());