Fix for routerhandlers.ts

This commit is contained in:
2026-10-13 23:59:51 +02:00
parent e7ad64230a
commit 65437a144b
5 changed files with 40 additions and 38 deletions
+1 -1
View File
@@ -84,6 +84,6 @@ export declare function createContentHelpers({ baseUrl, config, content, i18n, p
resolveRoute: (locale: string, segments: string[] | undefined, page: number) => Promise<null | ResolvedRoute>;
robots: () => RobotsRules;
sitemap: () => Promise<SitemapEntry[]>;
sitemapRoute: (req?: Request) => Promise<Response>;
sitemapRoute: (req: Request) => Promise<Response>;
};
export {};
+10 -10
View File
@@ -22,28 +22,28 @@ import { type SitemapStyleOptions } from './sitemapStyle.js';
* baseUrl: process.env.NEXT_PUBLIC_SERVER_URL!, full: true })
*/
export declare function createLlmsTxtRoute(opts: {
getCachedPayload: () => Promise<BasePayload>;
config: I18nConfig;
baseUrl: string;
pagesSlug?: string;
settingsSlug?: string;
config: I18nConfig;
/** Inline every page's full Markdown (llms-full.txt). Default false. */
full?: boolean;
getCachedPayload: () => Promise<BasePayload>;
pagesSlug?: string;
settingsSlug?: string;
/** Field holding a richer AI summary (buildSummaryField) to prefer as description. */
summaryField?: string;
}): () => Promise<Response>;
export type SitemapRouteOptions = {
/** Legacy: your own stylesheet URL (e.g. '/sitemap.css'). Overrides `style`. */
cssUrl?: string;
/**
* Built-in browser look (default ON): the XML points at `<this route>?style`
* and the same handler serves the CSS — nothing to copy into /public.
* `false` = raw XML. Object = header/credit/accent (SitemapStyleOptions);
* `title` may be async (sitemapRoute passes the Site Settings name).
*/
style?: false | (Omit<SitemapStyleOptions, 'title'> & {
title?: string | (() => Promise<string | undefined>);
});
/** Legacy: your own stylesheet URL (e.g. '/sitemap.css'). Overrides `style`. */
cssUrl?: string;
style?: ({
title?: (() => Promise<string | undefined>) | string;
} & Omit<SitemapStyleOptions, 'title'>) | false;
};
/**
* Ready-made Next route handler for /sitemap.xml, styled for humans out of the box.
@@ -56,4 +56,4 @@ export type SitemapRouteOptions = {
* `GET /sitemap.xml` → XML (crawlers), `GET /sitemap.xml?style` → its CSS.
* Don't keep app/sitemap.ts next to it — two sitemaps confuse crawlers.
*/
export declare function createSitemapRouteHandler(sitemap: () => Promise<SitemapEntry[]>, opts?: SitemapRouteOptions): (req?: Request) => Promise<Response>;
export declare function createSitemapRouteHandler(sitemap: () => Promise<SitemapEntry[]>, opts?: SitemapRouteOptions): (req: Request) => Promise<Response>;
+8 -8
View File
@@ -24,12 +24,12 @@ import { buildSitemapCss, SITEMAP_STYLE_PARAM } from './sitemapStyle.js';
try {
const payload = await opts.getCachedPayload();
const body = await buildLlmsTxt({
payload,
config: opts.config,
baseUrl: opts.baseUrl,
pagesSlug: opts.pagesSlug,
settingsSlug: opts.settingsSlug,
config: opts.config,
full: opts.full,
pagesSlug: opts.pagesSlug,
payload,
settingsSlug: opts.settingsSlug,
summaryField: opts.summaryField
});
return new Response(body, {
@@ -62,8 +62,8 @@ import { buildSitemapCss, SITEMAP_STYLE_PARAM } from './sitemapStyle.js';
*/ export function createSitemapRouteHandler(sitemap, opts = {}) {
const style = opts.cssUrl ? false : opts.style === false ? false : opts.style ?? {};
return async (req)=>{
const url = req ? new URL(req.url) : null;
if (style && url?.searchParams.has(SITEMAP_STYLE_PARAM)) {
const url = new URL(req.url);
if (style && url.searchParams.has(SITEMAP_STYLE_PARAM)) {
let title;
try {
title = typeof style.title === 'function' ? await style.title() : style.title;
@@ -75,13 +75,13 @@ import { buildSitemapCss, SITEMAP_STYLE_PARAM } from './sitemapStyle.js';
title
}), {
headers: {
'Content-Type': 'text/css; charset=utf-8',
'Cache-Control': 'public, max-age=3600',
'Content-Type': 'text/css; charset=utf-8',
'X-Robots-Tag': 'noindex'
}
});
}
const cssUrl = opts.cssUrl ?? (style ? `${url?.pathname ?? '/sitemap.xml'}?${SITEMAP_STYLE_PARAM}` : undefined);
const cssUrl = opts.cssUrl ?? (style ? `${url.pathname}?${SITEMAP_STYLE_PARAM}` : undefined);
try {
const entries = await sitemap();
const xml = buildSitemapXml(entries, {
File diff suppressed because one or more lines are too long