test route sitemap
This commit is contained in:
parent
a82afc9463
commit
aa710c944e
@ -56,6 +56,7 @@ export default defineNuxtConfig({
|
|||||||
sitemap: {
|
sitemap: {
|
||||||
siteUrl: process.env.APP_URL || 'https://www.digimedialoop.de',
|
siteUrl: process.env.APP_URL || 'https://www.digimedialoop.de',
|
||||||
trailingSlash: false,
|
trailingSlash: false,
|
||||||
|
ignorePaths: ['/sitemap.xml'],
|
||||||
i18n: true,
|
i18n: true,
|
||||||
async routes() {
|
async routes() {
|
||||||
return await getSitemapRoutes()
|
return await getSitemapRoutes()
|
||||||
|
|||||||
@ -1,28 +1,32 @@
|
|||||||
export async function getSitemapRoutes() {
|
export async function getSitemapRoutes() {
|
||||||
const CMS_BASE_URL = process.env.NUXT_PUBLIC_CMS_BASE_URL
|
const CMS_BASE_URL = process.env.NUXT_PUBLIC_CMS_BASE_URL
|
||||||
const CMS_TOKEN = process.env.NUXT_PUBLIC_CMS_TOKEN
|
const CMS_TOKEN = process.env.NUXT_PUBLIC_CMS_TOKEN
|
||||||
|
|
||||||
if (!CMS_BASE_URL || !CMS_TOKEN) {
|
if (!CMS_BASE_URL || !CMS_TOKEN) {
|
||||||
throw new Error('CMS-Umgebungsvariablen fehlen')
|
throw new Error('CMS-Umgebungsvariablen fehlen')
|
||||||
}
|
|
||||||
|
|
||||||
const headers = {
|
|
||||||
Authorization: `Bearer ${CMS_TOKEN}`,
|
|
||||||
}
|
|
||||||
|
|
||||||
const [projectsRes, articlesRes] = await Promise.all([
|
|
||||||
$fetch(`${CMS_BASE_URL}/api/references?fields=link`, { headers }),
|
|
||||||
$fetch(`${CMS_BASE_URL}/api/newsarticels?fields=slug&locale=all`, { headers }),
|
|
||||||
])
|
|
||||||
|
|
||||||
const projectRoutes = projectsRes.data
|
|
||||||
.filter((p: any) => p.attributes.link)
|
|
||||||
.map((p: any) => `/projekt/${p.attributes.link}`)
|
|
||||||
|
|
||||||
const articleRoutes = articlesRes.data
|
|
||||||
.filter((a: any) => a.attributes.slug)
|
|
||||||
.map((a: any) => `/artikel/${a.attributes.slug}`)
|
|
||||||
|
|
||||||
return [...projectRoutes, ...articleRoutes]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const headers = {
|
||||||
|
Authorization: `Bearer ${CMS_TOKEN}`,
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const [projectsRes, articlesRes] = await Promise.all([
|
||||||
|
fetch(`${CMS_BASE_URL}/api/references?fields=link`, { headers }).then(res => res.json()),
|
||||||
|
fetch(`${CMS_BASE_URL}/api/newsarticels?fields=slug&locale=all`, { headers }).then(res => res.json())
|
||||||
|
])
|
||||||
|
|
||||||
|
const projectRoutes = projectsRes.data
|
||||||
|
?.filter((p: any) => p.attributes.link)
|
||||||
|
.map((p: any) => `/projekt/${p.attributes.link}`) || []
|
||||||
|
|
||||||
|
const articleRoutes = articlesRes.data
|
||||||
|
?.filter((a: any) => a.attributes.slug)
|
||||||
|
.map((a: any) => `/artikel/${a.attributes.slug}`) || []
|
||||||
|
|
||||||
|
return [...projectRoutes, ...articleRoutes]
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Fehler beim Abrufen der CMS-Routen für die Sitemap:', error)
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user