Skip to content

Commit dfe2637

Browse files
committed
update sitemap and metadata to new url structure
1 parent 25a7b20 commit dfe2637

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

next-sitemap.config.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
11
const i18nConfig = require("./i18n.config.json")
22
const locales = i18nConfig.map(({ code }) => code)
33

4+
const defaultLocale = "en"
5+
46
/** @type {import('next-sitemap').IConfig} */
57
module.exports = {
68
siteUrl: process.env.SITE_URL || "https://ethereum.org",
79
generateRobotsTxt: true,
810
transform: async (_, path) => {
911
const rootPath = path.split("/")[1]
1012
if (path.endsWith("/404")) return null
11-
const isDefaultLocale = !locales.includes(rootPath) || rootPath === "en"
13+
const isDefaultLocale =
14+
!locales.includes(rootPath) || rootPath === defaultLocale
15+
16+
// Strip default-locale (en) prefix from paths; drop the `/en` root entry
17+
let loc = path
18+
if (rootPath === defaultLocale) {
19+
// Drop the `/en` root entry to avoid duplicating `/`
20+
if (path === `/${defaultLocale}` || path === `/${defaultLocale}/`)
21+
return null
22+
const defaultLocalePrefix = new RegExp(`^/${defaultLocale}(/|$)`)
23+
loc = path.replace(defaultLocalePrefix, "/")
24+
}
25+
1226
return {
13-
loc: path,
27+
loc,
1428
changefreq: isDefaultLocale ? "weekly" : "monthly",
1529
priority: isDefaultLocale ? 0.7 : 0.5,
1630
}

src/lib/utils/url.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ export const addSlashes = (href: string): string => {
5050
}
5151

5252
export const getFullUrl = (locale: string | undefined, path: string) =>
53-
addSlashes(new URL(join(locale || DEFAULT_LOCALE, path), SITE_URL).href)
53+
DEFAULT_LOCALE === locale || !locale
54+
? addSlashes(new URL(path, SITE_URL).href)
55+
: addSlashes(new URL(join(locale, path), SITE_URL).href)
5456

5557
// Remove trailing slash from slug and add leading slash
5658
export const normalizeSlug = (slug: string) => {

0 commit comments

Comments
 (0)