Skip to content

Commit af94674

Browse files
committed
fix(blog): ensure unique and valid slugs for tag pages
- fix: improve slugifyTag to support non-ASCII characters (Japanese/etc) - fix: filter empty slugs in getStaticPaths to prevent build errors - fix: eliminate duplicate slugs in tag page generation
1 parent ba4f0fd commit af94674

4 files changed

Lines changed: 31 additions & 16 deletions

File tree

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919
- **fix(search):** Removed unused test file `EnhancedSearchEngine.test.ts`.
2020
- **fix(blog):** Corrected the blog tags link generation to point to the new static tag pages instead of using query parameters, ensuring distinct URLs for each tag view.
2121
- **fix(api):** Updated the `/api/get-posts` endpoint to return server-rendered HTML fragments (using `BlogCard`) instead of JSON, aligning with the client-side consumption model.
22+
- **fix(blog):** Resolved "Missing parameter: tag" build error by enhancing `slugifyTag` to support non-ASCII characters and filtering out empty slugs in `getStaticPaths`.
2223
## [1.0.6] - 2026-01-10
2324

2425
### Changed

src/i18n/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,10 @@ export function isValidLanguage(lang: string): lang is keyof typeof ui {
8787
export function slugifyTag(tag: string) {
8888
return tag
8989
.toLowerCase()
90+
.trim()
9091
.replace(/\s+/g, '-')
9192
.replace(/\//g, '-')
92-
.replace(/[^\w-]+/g, '')
93+
.replace(/[!"#$%&'()*+,.:;<=>?@\[\\\]^`{|}~]/g, '') // Remove common symbols except hyphen
9394
.replace(/--+/g, '-')
9495
.replace(/^-+/, '')
9596
.replace(/-+$/, '');

src/pages/[lang]/blog/tags/[tag].astro

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,22 @@ import { ui } from '@/i18n/ui';
88
export async function getStaticPaths() {
99
const allPosts = await getCollection('blog');
1010
const uniqueTags = [...new Set(allPosts.flatMap(post => post.data.tags || []))];
11-
const validTags = uniqueTags.filter(tag => tag && tag.trim().length > 0);
1211
const languages = ['es', 'ja']; // en is handled separately
1312
14-
return languages.flatMap(lang =>
15-
validTags.map(tag => ({
16-
params: {
17-
lang,
18-
tag: slugifyTag(tag)
19-
},
20-
props: { tag }
21-
}))
22-
);
13+
return languages.flatMap(lang => {
14+
const paths = uniqueTags
15+
.map(tag => {
16+
const slug = slugifyTag(tag);
17+
return {
18+
params: { lang, tag: slug },
19+
props: { tag }
20+
};
21+
})
22+
.filter(path => path.params.tag.length > 0);
23+
24+
// Eliminate duplicate slugs per language
25+
return Array.from(new Map(paths.map(p => [p.params.tag, p])).values());
26+
});
2327
}
2428
2529
const { tag } = Astro.props;

src/pages/en/blog/tags/[tag].astro

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,21 @@ import { useTranslations, slugifyTag } from '@/i18n/utils';
77
export async function getStaticPaths() {
88
const allPosts = await getCollection('blog');
99
const uniqueTags = [...new Set(allPosts.flatMap(post => post.data.tags || []))];
10-
const validTags = uniqueTags.filter(tag => tag && tag.trim().length > 0);
1110
12-
return validTags.map(tag => ({
13-
params: { tag: slugifyTag(tag) },
14-
props: { tag }
15-
}));
11+
const paths = uniqueTags
12+
.map(tag => {
13+
const slug = slugifyTag(tag);
14+
return {
15+
params: { tag: slug },
16+
props: { tag }
17+
};
18+
})
19+
.filter(path => path.params.tag.length > 0);
20+
21+
// Eliminate duplicate slugs
22+
const uniquePaths = Array.from(new Map(paths.map(p => [p.params.tag, p])).values());
23+
24+
return uniquePaths;
1625
}
1726
1827
const { tag } = Astro.props;

0 commit comments

Comments
 (0)