- seoSitemapPages (lib/sitemapPages.ts) builds the routes per locale; the module adds them from a pages:resolved hook registered on ready, after @nuxtjs/i18n has localised the app's routes, so no cross-locale copies exist and each name ends in the locale's i18n suffix (L4 WR-05) - a path an app catch-all covers is left to it and logged at build unless seo.htmlSitemap.overCatchAll is true (L4 WR-04) - SitemapLink falls back to the i18n locale and renders only when the path resolves to the layer's sitemap page of that locale - an app with only app.vue no longer gets its router turned on by the pages
43 lines
2.1 KiB
Vue
43 lines
2.1 KiB
Vue
<script setup lang="ts">
|
|
// The footer link to the HTML sitemap of the page's locale (UI-SPEC L4,
|
|
// D-34): rendered only while the CMS has the HTML sitemap on for that
|
|
// locale and the layer serves it (seo.htmlSitemap), that is while the path
|
|
// resolves to the layer's sitemap page of that locale (not taken by an app
|
|
// page or a catch-all, L4 WR-04, WR-05). The locale: the prop, the resolve
|
|
// answer, its html_lang, the @nuxtjs/i18n current locale where the app has
|
|
// it (the layer does not depend on i18n), the site default. No style of
|
|
// its own beyond the inherited link colour.
|
|
const props = withDefaults(defineProps<{ locale?: string }>(), { locale: '' })
|
|
|
|
const config = useRuntimeConfig()
|
|
const router = useRouter()
|
|
const answer = useSeoAnswer()
|
|
const { data: site } = await useSeoSite()
|
|
const i18n = (useNuxtApp() as { $i18n?: { locale?: { value?: unknown } } }).$i18n
|
|
const primary = (code: string | undefined | null) => (code ?? '').toLowerCase().split(/[-_]/)[0] ?? ''
|
|
const i18nLocale = () => {
|
|
const value = i18n?.locale?.value
|
|
return typeof value === 'string' ? value : ''
|
|
}
|
|
|
|
const locale = computed(() => props.locale || answer.value?.locale || primary(answer.value?.html_lang) || i18nLocale() || site.value?.default_locale || '')
|
|
const labels = useSeoLabels(locale)
|
|
const href = computed(() => {
|
|
const html = site.value?.html_sitemap
|
|
if (!html || html.enabled !== true || !html.paths || !html.paths[locale.value]) return ''
|
|
const own = (config.public.seo as { htmlSitemap?: { paths?: Record<string, string> } | false } | undefined)?.htmlSitemap
|
|
if (!own || typeof own !== 'object') return ''
|
|
const path = own.paths?.[locale.value] ?? ''
|
|
if (!path) return ''
|
|
// Only the layer's sitemap page of this locale, never an app page or a
|
|
// catch-all at that path, nor another locale's copy.
|
|
const target = router.resolve(path)
|
|
const served = target.matched.some((r) => (r.meta?.seoSitemap as { locale?: string } | undefined)?.locale === locale.value)
|
|
return served ? path : ''
|
|
})
|
|
</script>
|
|
|
|
<template>
|
|
<NuxtLink v-if="href" class="seo-sitemap-link" :to="href">{{ labels.sitemapLink }}</NuxtLink>
|
|
</template>
|