Skip to content

Commit

Permalink
Try lib helper ts file agian...
Browse files Browse the repository at this point in the history
  • Loading branch information
matekdev committed Nov 11, 2023
1 parent e8fb090 commit f4e899d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/lib/utils/SlugFromPath.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const slugFromPath = (path: string) =>
path.match(/([\w-]+)\.(svelte\.md|md|svx)/i)?.[1] ?? null;
20 changes: 20 additions & 0 deletions src/routes/blog/[slug]/+page.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { EntryGenerator } from './$types';
import { slugFromPath } from '$lib/utils/SlugFromPath';

// https://kit.svelte.dev/docs/page-options#prerender-troubleshooting
export const entries: EntryGenerator = async () => {
const modules = import.meta.glob(`/src/blogs/*.{md,svx,svelte.md}`);
const postPromises = Object.entries(modules).map(([path, resolver]) =>
resolver().then(
(post) =>
({
slug: slugFromPath(path),
...(post as unknown as App.MdsvexFile).metadata
}) as App.BlogPost
)
);

const posts = await Promise.all(postPromises);
return posts;
};
export const prerender = true;

0 comments on commit f4e899d

Please sign in to comment.