feat: HTML sitemap pages and footer link
- the module registers seo-sitemap-<locale> at seo.htmlSitemap.paths (defaults pl /mapa-strony, en /sitemap) and seo-sitemap-group-<locale> at <path>/:group (plus <path>/:group/<segment>/:page in the path form); a path an app page already has stays the app's - SeoHtmlSitemapPage (global, overridable): H1, an H2 per non-empty group, categories nested, a large group's link to its group page, sitemap.empty; group pages with a built trail, page suffix and <SeoPagination>; 404 for an unknown group or a page past the last, 301 for ?page=1, 503 when the sitemap API fails - GET /api/__seo__/sitemap proxies the sitemap plugin's HTML API (only while the CMS has the HTML sitemap on for the locale) - <SeoSitemapLink>: the footer link while the HTML sitemap is on - L3 default styles
This commit is contained in:
@@ -8,7 +8,8 @@
|
||||
// app still uses it: each module reads only its own keys, so the layer's
|
||||
// options never use a name nuxt-seo-utils has (enabled, fallbackTitle …).
|
||||
|
||||
import { addServerTemplate, defineNuxtModule, useLogger } from 'nuxt/kit'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { addServerTemplate, defineNuxtModule, extendPages, useLogger } from 'nuxt/kit'
|
||||
import { findOffenders, guardMessage, noindexRule, type GuardPage } from './guard.ts'
|
||||
import { htmlSitemapOption, paginationOption, type SeoHtmlSitemapOption, type SeoPaginationOption } from './options.ts'
|
||||
import { routePatterns, routesTemplate, staticRoutes, type RoutePage } from './routes.ts'
|
||||
@@ -150,6 +151,30 @@ export default defineNuxtModule<SeoModuleOptions>({
|
||||
guard()
|
||||
})
|
||||
|
||||
// The HTML sitemap pages (D-34, P33-32), one overview and one group
|
||||
// page per locale, each rendering the global SeoHtmlSitemapPage. A path
|
||||
// an app page already has stays the app's.
|
||||
if (htmlSitemap !== false) {
|
||||
const overviewFile = fileURLToPath(new URL('../app/seo-pages/SitemapPage.vue', import.meta.url))
|
||||
const groupFile = fileURLToPath(new URL('../app/seo-pages/SitemapGroupPage.vue', import.meta.url))
|
||||
extendPages((list) => {
|
||||
const taken = new Set(list.map((p) => p.path))
|
||||
for (const [locale, path] of Object.entries(htmlSitemap.paths)) {
|
||||
if (taken.has(path)) {
|
||||
logger.info(`HTML sitemap: the app has its own page at ${path}; the layer's ${locale} sitemap page is not registered`)
|
||||
continue
|
||||
}
|
||||
const meta = { seoSitemap: { locale } }
|
||||
list.push({ name: `seo-sitemap-${locale}`, path, file: overviewFile, meta })
|
||||
list.push({ name: `seo-sitemap-group-${locale}`, path: `${path}/:group`, file: groupFile, meta })
|
||||
if (pagination.form === 'path') {
|
||||
const segment = pagination.segments[locale] || pagination.param
|
||||
list.push({ name: `seo-sitemap-group-page-${locale}`, path: `${path}/:group/${segment}/:page(\\d+)`, file: groupFile, meta })
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// The route artefact (#seo-routes) for the route report and the drift
|
||||
// check: written from the resolved pages when Nitro bundles the
|
||||
// server, so no network call happens at build time.
|
||||
|
||||
Reference in New Issue
Block a user