Skip to content

Commit 2079bda

Browse files
committed
Fix build issue
1 parent 72f9e55 commit 2079bda

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

src/pages/[...permalink].astro

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ import BlogPost from '../layouts/BlogPost.astro';
44
55
export 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
}

src/pages/blog/[slug].astro

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ import BlogPost from '../../layouts/BlogPost.astro';
44
55
export 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
}
1216
type Props = CollectionEntry<'blog'>;
1317

0 commit comments

Comments
 (0)