Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 52 additions & 2 deletions app/sitemap.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import type { MetadataRoute } from "next"

import { getFullUrl } from "@/lib/utils/url"
import { getFullUrl, slugify } from "@/lib/utils/url"

import { DEFAULT_LOCALE } from "@/lib/constants"
import { appsCategories } from "@/data/apps/categories"

import { DEFAULT_LOCALE, SITE_URL } from "@/lib/constants"

import { DEV_TOOL_CATEGORIES } from "./[locale]/developers/tools/constants"

import { getAppsData } from "@/lib/data"
import { getAllPagesWithTranslations } from "@/lib/i18n/translationRegistry"

// Slugs that canonicalize elsewhere and should not appear in the sitemap
const EXCLUDED_SLUGS = ["/developers/tutorials/ipfs-decentralized-ui/"]

export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
const pages = await getAllPagesWithTranslations()

Expand All @@ -29,6 +37,9 @@ export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
}
: undefined

// Skip excluded slugs
if (EXCLUDED_SLUGS.includes(normalizedSlug)) continue

for (const locale of translatedLocales) {
const url = getFullUrl(locale, normalizedSlug)

Expand All @@ -45,5 +56,44 @@ export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
}
}

// Add app category pages
for (const category of Object.values(appsCategories)) {
entries.push({
url: `${SITE_URL}/apps/categories/${category.slug}/`,
changeFrequency: "weekly",
priority: 0.6,
lastModified: new Date(),
})
}

// Add developer tools category pages (dynamic route: /developers/tools/[category])
for (const { slug } of DEV_TOOL_CATEGORIES) {
entries.push({
url: `${SITE_URL}/developers/tools/${slug}/`,
changeFrequency: "monthly",
priority: 0.6,
lastModified: new Date(),
})
}

// Add individual app pages
const appsData = await getAppsData()
if (appsData) {
const appSlugs = new Set<string>()
for (const apps of Object.values(appsData)) {
for (const app of apps) {
appSlugs.add(slugify(app.name))
}
}
for (const slug of appSlugs) {
entries.push({
url: `${SITE_URL}/apps/${slug}/`,
changeFrequency: "monthly",
priority: 0.5,
lastModified: new Date(),
})
}
}

return entries
}
5 changes: 1 addition & 4 deletions src/lib/i18n/translationRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,7 @@ export async function getAllPagesWithTranslations(): Promise<
const pages: PageWithTranslations[] = []

const mdSlugs = await getPostSlugs("/")
const intlPaths = [
...getStaticPagePaths(),
...getDynamicIntlPagePaths(),
]
const intlPaths = [...getStaticPagePaths(), ...getDynamicIntlPagePaths()]
const uniqueIntlPaths = Array.from(new Set(intlPaths))

for (const slug of mdSlugs) {
Expand Down
Loading