Skip to content

Commit f4e899d

Browse files
committed
Try lib helper ts file agian...
1 parent e8fb090 commit f4e899d

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/lib/utils/SlugFromPath.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const slugFromPath = (path: string) =>
2+
path.match(/([\w-]+)\.(svelte\.md|md|svx)/i)?.[1] ?? null;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import type { EntryGenerator } from './$types';
2+
import { slugFromPath } from '$lib/utils/SlugFromPath';
3+
4+
// https://kit.svelte.dev/docs/page-options#prerender-troubleshooting
5+
export const entries: EntryGenerator = async () => {
6+
const modules = import.meta.glob(`/src/blogs/*.{md,svx,svelte.md}`);
7+
const postPromises = Object.entries(modules).map(([path, resolver]) =>
8+
resolver().then(
9+
(post) =>
10+
({
11+
slug: slugFromPath(path),
12+
...(post as unknown as App.MdsvexFile).metadata
13+
}) as App.BlogPost
14+
)
15+
);
16+
17+
const posts = await Promise.all(postPromises);
18+
return posts;
19+
};
20+
export const prerender = true;

0 commit comments

Comments
 (0)