Compare commits

...
2 Commits
Author SHA1 Message Date
radoslaw.smolinski 0f6bbd597b 1.8.7 2026-10-13 23:59:56 +02:00
radoslaw.smolinski 65437a144b Fix for routerhandlers.ts 2026-10-13 23:59:51 +02:00
6 changed files with 41 additions and 39 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>; resolveRoute: (locale: string, segments: string[] | undefined, page: number) => Promise<null | ResolvedRoute>;
robots: () => RobotsRules; robots: () => RobotsRules;
sitemap: () => Promise<SitemapEntry[]>; sitemap: () => Promise<SitemapEntry[]>;
sitemapRoute: (req?: Request) => Promise<Response>; sitemapRoute: (req: Request) => Promise<Response>;
}; };
export {}; export {};
+10 -10
View File
@@ -22,28 +22,28 @@ import { type SitemapStyleOptions } from './sitemapStyle.js';
* baseUrl: process.env.NEXT_PUBLIC_SERVER_URL!, full: true }) * baseUrl: process.env.NEXT_PUBLIC_SERVER_URL!, full: true })
*/ */
export declare function createLlmsTxtRoute(opts: { export declare function createLlmsTxtRoute(opts: {
getCachedPayload: () => Promise<BasePayload>;
config: I18nConfig;
baseUrl: string; baseUrl: string;
pagesSlug?: string; config: I18nConfig;
settingsSlug?: string;
/** Inline every page's full Markdown (llms-full.txt). Default false. */ /** Inline every page's full Markdown (llms-full.txt). Default false. */
full?: boolean; full?: boolean;
getCachedPayload: () => Promise<BasePayload>;
pagesSlug?: string;
settingsSlug?: string;
/** Field holding a richer AI summary (buildSummaryField) to prefer as description. */ /** Field holding a richer AI summary (buildSummaryField) to prefer as description. */
summaryField?: string; summaryField?: string;
}): () => Promise<Response>; }): () => Promise<Response>;
export type SitemapRouteOptions = { 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` * 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. * and the same handler serves the CSS — nothing to copy into /public.
* `false` = raw XML. Object = header/credit/accent (SitemapStyleOptions); * `false` = raw XML. Object = header/credit/accent (SitemapStyleOptions);
* `title` may be async (sitemapRoute passes the Site Settings name). * `title` may be async (sitemapRoute passes the Site Settings name).
*/ */
style?: false | (Omit<SitemapStyleOptions, 'title'> & { style?: ({
title?: string | (() => Promise<string | undefined>); title?: (() => Promise<string | undefined>) | string;
}); } & Omit<SitemapStyleOptions, 'title'>) | false;
/** Legacy: your own stylesheet URL (e.g. '/sitemap.css'). Overrides `style`. */
cssUrl?: string;
}; };
/** /**
* Ready-made Next route handler for /sitemap.xml, styled for humans out of the box. * 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. * `GET /sitemap.xml` → XML (crawlers), `GET /sitemap.xml?style` → its CSS.
* Don't keep app/sitemap.ts next to it — two sitemaps confuse crawlers. * 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 { try {
const payload = await opts.getCachedPayload(); const payload = await opts.getCachedPayload();
const body = await buildLlmsTxt({ const body = await buildLlmsTxt({
payload,
config: opts.config,
baseUrl: opts.baseUrl, baseUrl: opts.baseUrl,
pagesSlug: opts.pagesSlug, config: opts.config,
settingsSlug: opts.settingsSlug,
full: opts.full, full: opts.full,
pagesSlug: opts.pagesSlug,
payload,
settingsSlug: opts.settingsSlug,
summaryField: opts.summaryField summaryField: opts.summaryField
}); });
return new Response(body, { return new Response(body, {
@@ -62,8 +62,8 @@ import { buildSitemapCss, SITEMAP_STYLE_PARAM } from './sitemapStyle.js';
*/ export function createSitemapRouteHandler(sitemap, opts = {}) { */ export function createSitemapRouteHandler(sitemap, opts = {}) {
const style = opts.cssUrl ? false : opts.style === false ? false : opts.style ?? {}; const style = opts.cssUrl ? false : opts.style === false ? false : opts.style ?? {};
return async (req)=>{ return async (req)=>{
const url = req ? new URL(req.url) : null; const url = new URL(req.url);
if (style && url?.searchParams.has(SITEMAP_STYLE_PARAM)) { if (style && url.searchParams.has(SITEMAP_STYLE_PARAM)) {
let title; let title;
try { try {
title = typeof style.title === 'function' ? await style.title() : style.title; title = typeof style.title === 'function' ? await style.title() : style.title;
@@ -75,13 +75,13 @@ import { buildSitemapCss, SITEMAP_STYLE_PARAM } from './sitemapStyle.js';
title title
}), { }), {
headers: { headers: {
'Content-Type': 'text/css; charset=utf-8',
'Cache-Control': 'public, max-age=3600', 'Cache-Control': 'public, max-age=3600',
'Content-Type': 'text/css; charset=utf-8',
'X-Robots-Tag': 'noindex' '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 { try {
const entries = await sitemap(); const entries = await sitemap();
const xml = buildSitemapXml(entries, { const xml = buildSitemapXml(entries, {
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@intecion/ipal-kit", "name": "@intecion/ipal-kit",
"version": "1.8.6", "version": "1.8.7",
"description": "Intecion Payload Advanced Library — a Payload CMS 3 plugin: i18n, SEO, forms, consent, analytics, blog/archives.", "description": "Intecion Payload Advanced Library — a Payload CMS 3 plugin: i18n, SEO, forms, consent, analytics, blog/archives.",
"license": "MIT", "license": "MIT",
"repository": { "repository": {
+20 -18
View File
@@ -1,8 +1,10 @@
import type { BasePayload } from 'payload' import type { BasePayload } from 'payload'
import type { I18nConfig } from '../i18n/index.js' import type { I18nConfig } from '../i18n/index.js'
import type { SitemapEntry } from './buildSitemapEntries.js'
import { buildLlmsTxt } from './buildLlmsTxt.js' import { buildLlmsTxt } from './buildLlmsTxt.js'
import { buildSitemapXml } from './buildSitemapXml.js' import { buildSitemapXml } from './buildSitemapXml.js'
import type { SitemapEntry } from './buildSitemapEntries.js'
import { buildSitemapCss, SITEMAP_STYLE_PARAM, type SitemapStyleOptions } from './sitemapStyle.js' import { buildSitemapCss, SITEMAP_STYLE_PARAM, type SitemapStyleOptions } from './sitemapStyle.js'
/** /**
@@ -25,13 +27,13 @@ import { buildSitemapCss, SITEMAP_STYLE_PARAM, type SitemapStyleOptions } from '
* baseUrl: process.env.NEXT_PUBLIC_SERVER_URL!, full: true }) * baseUrl: process.env.NEXT_PUBLIC_SERVER_URL!, full: true })
*/ */
export function createLlmsTxtRoute(opts: { export function createLlmsTxtRoute(opts: {
getCachedPayload: () => Promise<BasePayload>
config: I18nConfig
baseUrl: string baseUrl: string
pagesSlug?: string config: I18nConfig
settingsSlug?: string
/** Inline every page's full Markdown (llms-full.txt). Default false. */ /** Inline every page's full Markdown (llms-full.txt). Default false. */
full?: boolean full?: boolean
getCachedPayload: () => Promise<BasePayload>
pagesSlug?: string
settingsSlug?: string
/** Field holding a richer AI summary (buildSummaryField) to prefer as description. */ /** Field holding a richer AI summary (buildSummaryField) to prefer as description. */
summaryField?: string summaryField?: string
}): () => Promise<Response> { }): () => Promise<Response> {
@@ -39,12 +41,12 @@ export function createLlmsTxtRoute(opts: {
try { try {
const payload = await opts.getCachedPayload() const payload = await opts.getCachedPayload()
const body = await buildLlmsTxt({ const body = await buildLlmsTxt({
payload,
config: opts.config,
baseUrl: opts.baseUrl, baseUrl: opts.baseUrl,
pagesSlug: opts.pagesSlug, config: opts.config,
settingsSlug: opts.settingsSlug,
full: opts.full, full: opts.full,
pagesSlug: opts.pagesSlug,
payload,
settingsSlug: opts.settingsSlug,
summaryField: opts.summaryField, summaryField: opts.summaryField,
}) })
return new Response(body, { return new Response(body, {
@@ -62,15 +64,15 @@ export function createLlmsTxtRoute(opts: {
} }
export type SitemapRouteOptions = { 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` * 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. * and the same handler serves the CSS — nothing to copy into /public.
* `false` = raw XML. Object = header/credit/accent (SitemapStyleOptions); * `false` = raw XML. Object = header/credit/accent (SitemapStyleOptions);
* `title` may be async (sitemapRoute passes the Site Settings name). * `title` may be async (sitemapRoute passes the Site Settings name).
*/ */
style?: false | (Omit<SitemapStyleOptions, 'title'> & { title?: string | (() => Promise<string | undefined>) }) style?: ({ title?: (() => Promise<string | undefined>) | string } & Omit<SitemapStyleOptions, 'title'>) | false
/** Legacy: your own stylesheet URL (e.g. '/sitemap.css'). Overrides `style`. */
cssUrl?: string
} }
/** /**
@@ -87,13 +89,13 @@ export type SitemapRouteOptions = {
export function createSitemapRouteHandler( export function createSitemapRouteHandler(
sitemap: () => Promise<SitemapEntry[]>, sitemap: () => Promise<SitemapEntry[]>,
opts: SitemapRouteOptions = {}, opts: SitemapRouteOptions = {},
): (req?: Request) => Promise<Response> { ): (req: Request) => Promise<Response> {
const style = opts.cssUrl ? false : opts.style === false ? false : (opts.style ?? {}) const style = opts.cssUrl ? false : opts.style === false ? false : (opts.style ?? {})
return async (req?: Request) => { return async (req: Request) => {
const url = req ? new URL(req.url) : null const url = new URL(req.url)
if (style && url?.searchParams.has(SITEMAP_STYLE_PARAM)) { if (style && url.searchParams.has(SITEMAP_STYLE_PARAM)) {
let title: string | undefined let title: string | undefined
try { try {
title = typeof style.title === 'function' ? await style.title() : style.title title = typeof style.title === 'function' ? await style.title() : style.title
@@ -102,14 +104,14 @@ export function createSitemapRouteHandler(
} }
return new Response(buildSitemapCss({ ...style, title }), { return new Response(buildSitemapCss({ ...style, title }), {
headers: { headers: {
'Content-Type': 'text/css; charset=utf-8',
'Cache-Control': 'public, max-age=3600', 'Cache-Control': 'public, max-age=3600',
'Content-Type': 'text/css; charset=utf-8',
'X-Robots-Tag': 'noindex', '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 { try {
const entries = await sitemap() const entries = await sitemap()
const xml = buildSitemapXml(entries, { cssUrl }) const xml = buildSitemapXml(entries, { cssUrl })