@agility/create-next-app 1.0.0-beta.3 → 1.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { getSitemapFlat } from "@/lib/cms/getSitemapFlat"
|
|
2
|
+
import { locales, defaultLocale } from "@/lib/i18n/config"
|
|
3
|
+
import type { MetadataRoute } from "next"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Agility CMS Sitemap
|
|
7
|
+
*
|
|
8
|
+
* Generates a sitemap from Agility CMS pages using getSitemapFlat().
|
|
9
|
+
* Iterates through all configured locales and generates entries for each visible page.
|
|
10
|
+
*/
|
|
11
|
+
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
|
|
12
|
+
const allSitemapEntries: MetadataRoute.Sitemap = []
|
|
13
|
+
const baseUrl = process.env.SITE_URL || "https://example.com"
|
|
14
|
+
|
|
15
|
+
// Generate sitemap entries for each locale
|
|
16
|
+
for (const locale of locales) {
|
|
17
|
+
const sitemapData = await getSitemapFlat({
|
|
18
|
+
channelName: process.env.AGILITY_SITEMAP || "website",
|
|
19
|
+
languageCode: locale
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
if (!sitemapData) continue
|
|
23
|
+
|
|
24
|
+
const localeEntries = Object.keys(sitemapData)
|
|
25
|
+
.filter((path) => {
|
|
26
|
+
const node = sitemapData[path]
|
|
27
|
+
|
|
28
|
+
// Skip folders and redirects
|
|
29
|
+
if (node.isFolder || node.redirect) {
|
|
30
|
+
return false
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Skip pages not visible in sitemap
|
|
34
|
+
if (!node.visible?.sitemap) {
|
|
35
|
+
return false
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return true
|
|
39
|
+
})
|
|
40
|
+
.map((path, index) => {
|
|
41
|
+
// For default locale, don't add locale prefix to URL
|
|
42
|
+
const localizedPath = locale === defaultLocale ? path : `/${locale}${path}`
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
url: index === 0 && path === "/" ? baseUrl : `${baseUrl}${localizedPath}`,
|
|
46
|
+
lastModified: new Date(),
|
|
47
|
+
changeFrequency: "daily" as const,
|
|
48
|
+
priority: path === "/" ? 1.0 : 0.8
|
|
49
|
+
}
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
allSitemapEntries.push(...localeEntries)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return allSitemapEntries
|
|
56
|
+
}
|