28 lines
918 B
TypeScript
28 lines
918 B
TypeScript
export async function getSitemapRoutes() {
|
|
const CMS_BASE_URL = process.env.NUXT_PUBLIC_CMS_BASE_URL
|
|
const CMS_TOKEN = process.env.NUXT_PUBLIC_CMS_TOKEN
|
|
|
|
if (!CMS_BASE_URL || !CMS_TOKEN) {
|
|
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]
|
|
}
|
|
|