Skip to content

Commit e8d7806

Browse files
committed
replace next-sitemap with custom sitemap using translation registry
1 parent 8ab798d commit e8d7806

File tree

6 files changed

+50
-68
lines changed

6 files changed

+50
-68
lines changed

.github/labeler.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
"config ⚙️":
1818
- i18n.config.json
1919
- next.config.js
20-
- next-sitemap.config.js
2120
- tsconfig.json
2221
- .nvmrc
2322
- .eslintignore

CLAUDE.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ pnpm events-import # Import community events
137137

138138
## SEO & Meta
139139

140-
- Sitemap generation with `next-sitemap`
140+
- Sitemap generation in `app/sitemap.ts`
141141
- Meta tags and Open Graph optimization
142142
- Structured data for search engines
143143
- Security headers (X-Frame-Options: DENY)
@@ -210,26 +210,28 @@ The site uses a GDPR-compliant, cookie-less A/B testing system integrated with M
210210
### Adding a New A/B Test
211211

212212
1. **Create experiment in Matomo dashboard**:
213+
213214
- Go to Experiments → Manage Experiments
214215
- Create new experiment with desired name (e.g., "HomepageHero")
215216
- Add variations with weights (original is implicit)
216217
- Set status to "running"
217218

218219
2. **Implement in component**:
220+
219221
```tsx
220222
import ABTestWrapper from "@/components/AB/TestWrapper"
221-
222-
<ABTestWrapper
223-
testKey="HomepageHero" // Must match Matomo experiment name exactly
223+
;<ABTestWrapper
224+
testKey="HomepageHero" // Must match Matomo experiment name exactly
224225
variants={[
225-
<OriginalComponent key="current-hero" />, // Index 0: Original
226-
<NewComponent key="redesigned-hero" /> // Index 1: Variation
226+
<OriginalComponent key="current-hero" />, // Index 0: Original
227+
<NewComponent key="redesigned-hero" />, // Index 1: Variation
227228
]}
228229
fallback={<OriginalComponent />}
229230
/>
230231
```
231232

232233
**Important**:
234+
233235
- Variants matched by **array index**, not names
234236
- Array order must match Matomo experiment order exactly
235237
- JSX `key` props become debug panel labels: `"redesigned-hero"``"Redesigned Hero"`
@@ -244,6 +246,7 @@ The site uses a GDPR-compliant, cookie-less A/B testing system integrated with M
244246
### Environment Variables
245247

246248
Required for Matomo integration:
249+
247250
- `NEXT_PUBLIC_MATOMO_URL` - Matomo instance URL
248251
- `NEXT_PUBLIC_MATOMO_SITE_ID` - Site ID in Matomo
249252
- `MATOMO_API_TOKEN` - API token with experiments access

app/sitemap.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import type { MetadataRoute } from "next"
2+
3+
import { getFullUrl } from "@/lib/utils/url"
4+
5+
import { DEFAULT_LOCALE } from "@/lib/constants"
6+
7+
import { getAllPagesWithTranslations } from "@/lib/i18n/translationRegistry"
8+
9+
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
10+
const pages = await getAllPagesWithTranslations()
11+
12+
const entries: MetadataRoute.Sitemap = []
13+
14+
for (const { slug, translatedLocales } of pages) {
15+
const normalizedSlug = slug.startsWith("/") ? slug : `/${slug}`
16+
17+
for (const locale of translatedLocales) {
18+
const url = getFullUrl(locale, normalizedSlug)
19+
20+
// Drop the `/en` root entry to avoid duplicating `/`
21+
// This happens when slug is "/" and locale is default
22+
if (
23+
locale === DEFAULT_LOCALE &&
24+
(normalizedSlug === "/" || normalizedSlug === "")
25+
) {
26+
continue
27+
}
28+
29+
const isDefaultLocale = locale === DEFAULT_LOCALE
30+
31+
entries.push({
32+
url,
33+
changeFrequency: isDefaultLocale ? "weekly" : "monthly",
34+
priority: isDefaultLocale ? 0.7 : 0.5,
35+
lastModified: new Date(),
36+
})
37+
}
38+
}
39+
40+
return entries
41+
}

next-sitemap.config.js

Lines changed: 0 additions & 31 deletions
This file was deleted.

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"scripts": {
77
"dev": "next dev",
88
"build": "next build",
9-
"postbuild": "next-sitemap",
109
"start": "next start",
1110
"lint": "next lint",
1211
"lint:fix": "next lint --fix",
@@ -82,7 +81,6 @@
8281
"next": "^14.2.32",
8382
"next-intl": "^3.26.3",
8483
"next-mdx-remote": "^5.0.0",
85-
"next-sitemap": "^4.2.3",
8684
"next-themes": "^0.3.0",
8785
"prism-react-renderer": "1.1.0",
8886
"prismjs": "^1.30.0",

pnpm-lock.yaml

Lines changed: 0 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)