Sitemap.css is now builded in plugin
This commit is contained in:
@@ -5,10 +5,10 @@ import { cache } from 'react'
|
||||
|
||||
import type { ArchiveEntries, ContentOption, ResolvedRoute } from '../content/index.js'
|
||||
import type { I18nConfig } from '../i18n/index.js'
|
||||
import type { PageMetadata, RobotsOptions, RobotsRules, SitemapEntry } from '../seo/index.js'
|
||||
import type { PageMetadata, RobotsOptions, RobotsRules, SitemapEntry, SitemapStyleOptions } from '../seo/index.js'
|
||||
|
||||
import { getArchiveEntries, resolveRoute as resolveRouteRaw } from '../content/index.js'
|
||||
import { buildRobots, buildSitemapEntries, createPageMetadata } from '../seo/index.js'
|
||||
import { buildRobots, buildSitemapEntries, createPageMetadata, createSitemapRouteHandler } from '../seo/index.js'
|
||||
|
||||
type CreateContentHelpersArgs = {
|
||||
/**
|
||||
@@ -39,6 +39,14 @@ type CreateContentHelpersArgs = {
|
||||
robots?: RobotsOptions
|
||||
/** SiteSettings global slug. Defaults to 'site-settings'. */
|
||||
settingsSlug?: string
|
||||
/**
|
||||
* Browser look of `sitemapRoute` (/sitemap.xml). Default: built-in style,
|
||||
* header = Site Settings `siteName` (default locale), credit "Technology by
|
||||
* Intecion.com". `false` = raw XML. `{ credit: false }` hides the credit line.
|
||||
*/
|
||||
sitemapStyle?: { title?: string } & Omit<SitemapStyleOptions, 'title'> | false
|
||||
/** Site Settings field with the site name (sitemap header). Default 'siteName'. */
|
||||
siteNameField?: string
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,6 +83,8 @@ export function createContentHelpers({
|
||||
pagesSlug = 'pages',
|
||||
robots: robotsOptions,
|
||||
settingsSlug = 'site-settings',
|
||||
sitemapStyle,
|
||||
siteNameField = 'siteName',
|
||||
}: CreateContentHelpersArgs) {
|
||||
const origin = baseUrl ?? process.env.NEXT_PUBLIC_SERVER_URL ?? ''
|
||||
const getCachedPayload = cache(
|
||||
@@ -384,6 +394,31 @@ export function createContentHelpers({
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Route handler for app/sitemap.xml/route.ts — XML for crawlers, styled for
|
||||
* people (`?style` serves the CSS from the plugin; nothing in /public):
|
||||
*
|
||||
* export { sitemapRoute as GET } from '@/lib/content'
|
||||
* export const dynamic = 'force-dynamic'
|
||||
*/
|
||||
const sitemapRoute = createSitemapRouteHandler(sitemap, {
|
||||
style:
|
||||
sitemapStyle === false
|
||||
? false
|
||||
: {
|
||||
...sitemapStyle,
|
||||
title:
|
||||
sitemapStyle?.title ??
|
||||
(async () => {
|
||||
const locale = i18n?.defaultLocale
|
||||
if (!locale) {return undefined}
|
||||
const s = (await getSettings(locale)) as Record<string, unknown>
|
||||
const name = s?.[siteNameField]
|
||||
return typeof name === 'string' ? name : undefined
|
||||
}),
|
||||
},
|
||||
})
|
||||
|
||||
return {
|
||||
generatePageMetadata,
|
||||
generateStaticParams,
|
||||
@@ -395,5 +430,6 @@ export function createContentHelpers({
|
||||
resolveRoute,
|
||||
robots,
|
||||
sitemap,
|
||||
sitemapRoute,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user