feat: extend blog post indexing
This commit is contained in:
parent
c8061bf98c
commit
3244c4c692
1 changed files with 6 additions and 2 deletions
|
|
@ -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());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue