Skip to content

Commit

Permalink
fix: Resolve an issue where the homepage did not get listed correctly…
Browse files Browse the repository at this point in the history
… in the sitemap
  • Loading branch information
Dobefu committed Feb 13, 2025
1 parent 3a0e146 commit 03de941
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/app/sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
})

const mdFiles = files.filter((file) => {
// Exclude catch-all routes.
// Exclude catch-all routes and parallel routes.
if (file.includes('[...') || file.startsWith('@')) return false

return file.endsWith('page.mdx') || file.endsWith('page.tsx')
Expand All @@ -24,21 +24,23 @@ export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
const paths = mdFiles.map((file) => file.replace(/(\/page|)\.(mdx|tsx)$/, ''))

return paths.map((path) => {
const appUrl = process.env.NEXT_PUBLIC_APP_URL
const cleanPath = path
.replaceAll(/\(.{1,25}?\)/g, '')
.replaceAll(/\/\//g, '/')
.replace(/^page$/, '')
const languages: Record<string, string> = {}

localeCodes
.filter((localeCode) => localeCode !== defaultLocale)
.forEach(
(localeCode) =>
(languages[localeCode] =
`${process.env.NEXT_PUBLIC_APP_URL}/${localeCode}/${cleanPath}`),
`${appUrl}/${localeCode}/${cleanPath}`.replace(/\/$/, '')),
)

return {
url: `${process.env.NEXT_PUBLIC_APP_URL}/${defaultLocale}/${cleanPath}`,
url: `${appUrl}/${defaultLocale}/${cleanPath}`.replace(/\/$/, ''),
alternates: { languages },
priority: 1,
}
Expand Down

0 comments on commit 03de941

Please sign in to comment.