File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,13 +4,16 @@ import BlogPost from '../layouts/BlogPost.astro';
44
55export async function getStaticPaths() {
66 const posts = await getCollection (' blog' );
7- const paths = [];
7+ type BlogPermalinkPath = { params: { permalink: string } ; props: CollectionEntry <' blog' > };
8+ const paths: BlogPermalinkPath [] = [];
89
910 for (const post of posts ) {
1011 if (post .data .permalink ) {
1112 // Handle custom permalinks (Jekyll posts)
13+ // [...permalink] accepts a string; Astro will match the rest param internally
14+ const clean = post .data .permalink .replace (/ ^ \/ + / , ' ' );
1215 paths .push ({
13- params: { permalink: post . data . permalink },
16+ params: { permalink: clean },
1417 props: post ,
1518 });
1619 }
Original file line number Diff line number Diff line change @@ -4,10 +4,14 @@ import BlogPost from '../../layouts/BlogPost.astro';
44
55export async function getStaticPaths() {
66 const posts = await getCollection (' blog' );
7- return posts .map ((post ) => ({
8- params: { slug: post .data .permalink || post .id },
9- props: post ,
10- }));
7+ // Only generate /blog/<slug>/ routes for posts WITHOUT a custom permalink.
8+ // Posts with a permalink are handled by the catch-all route at src/pages/[...permalink].astro
9+ return posts
10+ .filter ((post ) => ! post .data .permalink )
11+ .map ((post ) => ({
12+ params: { slug: post .id },
13+ props: post ,
14+ }));
1115}
1216type Props = CollectionEntry <' blog' >;
1317
You can’t perform that action at this time.
0 commit comments