Skip to content

Commit 40343bc

Browse files
Mlaz-codepaperclip-resolver[bot]
andauthored
fix(seo): enable trailingSlash for consistent canonical/hreflang/sitemap URLs (#236)
Semrush flagged 9 hreflang conflicts because Vercel serves both /en and /en/ as 200 (no redirect), so whichever form tags use conflicts with the alternate crawled URL. Fix: enable trailingSlash: true in Next.js config so Vercel redirects /en → /en/ (308). Update page.tsx and sitemap generator to produce trailing-slash URLs consistently across: - <link rel="canonical"> - <link rel="alternate" hreflang> - sitemap.xml <loc> and <xhtml:link> Build tested locally — static export now generates directory-based index.html files (en/index.html instead of en.html). Co-authored-by: paperclip-resolver[bot] <3736210+paperclip-resolver[bot]@users.noreply.github.com>
1 parent 2df01d8 commit 40343bc

3 files changed

Lines changed: 4 additions & 3 deletions

File tree

app/[lang]/[[...mdxPath]]/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ const DEFAULT_LOCALE = 'en'
1010
export async function generateMetadata(props) {
1111
const params = await props.params
1212
const { metadata } = await importPage(params.mdxPath, params.lang)
13-
const path = params.mdxPath ? `/${params.lang}/${params.mdxPath.join('/')}` : `/${params.lang}/`
14-
const subPath = params.mdxPath ? `/${params.mdxPath.join('/')}` : '/'
13+
const path = params.mdxPath ? `/${params.lang}/${params.mdxPath.join('/')}/` : `/${params.lang}/`
14+
const subPath = params.mdxPath ? `/${params.mdxPath.join('/')}/` : '/'
1515
const languages: Record<string, string> = {}
1616
for (const l of LOCALES) {
1717
languages[l] = `https://docs.sharpapi.io/${l}${subPath}`

next.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const withNextra = nextra({
77

88
export default withNextra({
99
output: 'export',
10+
trailingSlash: true,
1011
images: { unoptimized: true },
1112
// Nextra reads i18n config, extracts locales, then removes it (App Router compatible)
1213
i18n: {

scripts/generate-sitemap.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ async function lastmod(file) {
6464
}
6565

6666
function url(locale, route) {
67-
const path = route ? `/${locale}/${route}` : `/${locale}`
67+
const path = route ? `/${locale}/${route}/` : `/${locale}/`
6868
return `${HOST}${path}`
6969
}
7070

0 commit comments

Comments
 (0)