From 65437a144b1d2a4031dbb7fbc7e7b6e6ca0a7d90 Mon Sep 17 00:00:00 2001 From: rasm-its Date: Tue, 13 Oct 2026 23:59:51 +0200 Subject: [PATCH] Fix for routerhandlers.ts --- .../frontend/createContentHelpers.d.ts | 2 +- dist/modules/seo/routeHandlers.d.ts | 20 +++++----- dist/modules/seo/routeHandlers.js | 16 ++++---- dist/modules/seo/routeHandlers.js.map | 2 +- src/modules/seo/routeHandlers.ts | 38 ++++++++++--------- 5 files changed, 40 insertions(+), 38 deletions(-) diff --git a/dist/modules/frontend/createContentHelpers.d.ts b/dist/modules/frontend/createContentHelpers.d.ts index 1d3fc64..931a6e4 100644 --- a/dist/modules/frontend/createContentHelpers.d.ts +++ b/dist/modules/frontend/createContentHelpers.d.ts @@ -84,6 +84,6 @@ export declare function createContentHelpers({ baseUrl, config, content, i18n, p resolveRoute: (locale: string, segments: string[] | undefined, page: number) => Promise; robots: () => RobotsRules; sitemap: () => Promise; - sitemapRoute: (req?: Request) => Promise; + sitemapRoute: (req: Request) => Promise; }; export {}; diff --git a/dist/modules/seo/routeHandlers.d.ts b/dist/modules/seo/routeHandlers.d.ts index 5f71078..1a3b16b 100644 --- a/dist/modules/seo/routeHandlers.d.ts +++ b/dist/modules/seo/routeHandlers.d.ts @@ -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; - 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; + pagesSlug?: string; + settingsSlug?: string; /** Field holding a richer AI summary (buildSummaryField) to prefer as description. */ summaryField?: string; }): () => Promise; 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 `?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 & { - title?: string | (() => Promise); - }); - /** Legacy: your own stylesheet URL (e.g. '/sitemap.css'). Overrides `style`. */ - cssUrl?: string; + style?: ({ + title?: (() => Promise) | string; + } & Omit) | 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, opts?: SitemapRouteOptions): (req?: Request) => Promise; +export declare function createSitemapRouteHandler(sitemap: () => Promise, opts?: SitemapRouteOptions): (req: Request) => Promise; diff --git a/dist/modules/seo/routeHandlers.js b/dist/modules/seo/routeHandlers.js index 1c14fe1..442f3bb 100644 --- a/dist/modules/seo/routeHandlers.js +++ b/dist/modules/seo/routeHandlers.js @@ -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, { diff --git a/dist/modules/seo/routeHandlers.js.map b/dist/modules/seo/routeHandlers.js.map index 7aedd57..003742d 100644 --- a/dist/modules/seo/routeHandlers.js.map +++ b/dist/modules/seo/routeHandlers.js.map @@ -1 +1 @@ -{"version":3,"sources":["../../../src/modules/seo/routeHandlers.ts"],"sourcesContent":["import type { BasePayload } from 'payload'\nimport type { I18nConfig } from '../i18n/index.js'\nimport { buildLlmsTxt } from './buildLlmsTxt.js'\nimport { buildSitemapXml } from './buildSitemapXml.js'\nimport type { SitemapEntry } from './buildSitemapEntries.js'\nimport { buildSitemapCss, SITEMAP_STYLE_PARAM, type SitemapStyleOptions } from './sitemapStyle.js'\n\n/**\n * Ready-made Next route handler for /llms.txt. Replaces the ~60-line try/catch\n * every project was copying. buildLlmsTxt already handles collections without\n * drafts, so no workaround is needed here.\n *\n * // app/llms.txt/route.ts\n * import { createLlmsTxtRoute } from '@intecion/ipal-kit'\n * import { getCachedPayload } from '@/lib/content'\n * import { i18nConfig } from '@/i18n.config'\n * export const dynamic = 'force-dynamic'\n * export const GET = createLlmsTxtRoute({ getCachedPayload, config: i18nConfig,\n * baseUrl: process.env.NEXT_PUBLIC_SERVER_URL! })\n *\n * For the full-content variant, add a second route with `full: true`:\n *\n * // app/llms-full.txt/route.ts\n * export const GET = createLlmsTxtRoute({ getCachedPayload, config: i18nConfig,\n * baseUrl: process.env.NEXT_PUBLIC_SERVER_URL!, full: true })\n */\nexport function createLlmsTxtRoute(opts: {\n getCachedPayload: () => Promise\n config: I18nConfig\n baseUrl: string\n pagesSlug?: string\n settingsSlug?: string\n /** Inline every page's full Markdown (llms-full.txt). Default false. */\n full?: boolean\n /** Field holding a richer AI summary (buildSummaryField) to prefer as description. */\n summaryField?: string\n}): () => Promise {\n return async () => {\n try {\n const payload = await opts.getCachedPayload()\n const body = await buildLlmsTxt({\n payload,\n config: opts.config,\n baseUrl: opts.baseUrl,\n pagesSlug: opts.pagesSlug,\n settingsSlug: opts.settingsSlug,\n full: opts.full,\n summaryField: opts.summaryField,\n })\n return new Response(body, {\n headers: { 'Content-Type': 'text/plain; charset=utf-8' },\n })\n } catch (err) {\n // DB unreachable at build (container) — return a minimal valid file so the\n // route doesn't 500; it fills in at runtime. No per-project try/catch.\n console.warn('[ipal] createLlmsTxtRoute: could not build llms.txt:', err)\n return new Response('# llms.txt\\n', {\n headers: { 'Content-Type': 'text/plain; charset=utf-8' },\n })\n }\n }\n}\n\nexport type SitemapRouteOptions = {\n /**\n * Built-in browser look (default ON): the XML points at `?style`\n * and the same handler serves the CSS — nothing to copy into /public.\n * `false` = raw XML. Object = header/credit/accent (SitemapStyleOptions);\n * `title` may be async (sitemapRoute passes the Site Settings name).\n */\n style?: false | (Omit & { title?: string | (() => Promise) })\n /** Legacy: your own stylesheet URL (e.g. '/sitemap.css'). Overrides `style`. */\n cssUrl?: string\n}\n\n/**\n * Ready-made Next route handler for /sitemap.xml, styled for humans out of the box.\n * Usually you don't call this — `createContentHelpers` returns `sitemapRoute`:\n *\n * // app/sitemap.xml/route.ts — the whole file\n * export { sitemapRoute as GET } from '@/lib/content'\n * export const dynamic = 'force-dynamic'\n *\n * `GET /sitemap.xml` → XML (crawlers), `GET /sitemap.xml?style` → its CSS.\n * Don't keep app/sitemap.ts next to it — two sitemaps confuse crawlers.\n */\nexport function createSitemapRouteHandler(\n sitemap: () => Promise,\n opts: SitemapRouteOptions = {},\n): (req?: Request) => Promise {\n const style = opts.cssUrl ? false : opts.style === false ? false : (opts.style ?? {})\n\n return async (req?: Request) => {\n const url = req ? new URL(req.url) : null\n\n if (style && url?.searchParams.has(SITEMAP_STYLE_PARAM)) {\n let title: string | undefined\n try {\n title = typeof style.title === 'function' ? await style.title() : style.title\n } catch {\n title = undefined // DB down → generic heading, never a broken stylesheet\n }\n return new Response(buildSitemapCss({ ...style, title }), {\n headers: {\n 'Content-Type': 'text/css; charset=utf-8',\n 'Cache-Control': 'public, max-age=3600',\n 'X-Robots-Tag': 'noindex',\n },\n })\n }\n\n const cssUrl = opts.cssUrl ?? (style ? `${url?.pathname ?? '/sitemap.xml'}?${SITEMAP_STYLE_PARAM}` : undefined)\n try {\n const entries = await sitemap()\n const xml = buildSitemapXml(entries, { cssUrl })\n return new Response(xml, {\n headers: { 'Content-Type': 'application/xml; charset=utf-8' },\n })\n } catch (err) {\n console.warn('[ipal] createSitemapRouteHandler: could not build sitemap:', err)\n // Valid empty urlset so the route doesn't 500 during a DB-less build.\n const empty =\n '\\n' +\n ''\n return new Response(empty, {\n headers: { 'Content-Type': 'application/xml; charset=utf-8' },\n })\n }\n }\n}\n"],"names":["buildLlmsTxt","buildSitemapXml","buildSitemapCss","SITEMAP_STYLE_PARAM","createLlmsTxtRoute","opts","payload","getCachedPayload","body","config","baseUrl","pagesSlug","settingsSlug","full","summaryField","Response","headers","err","console","warn","createSitemapRouteHandler","sitemap","style","cssUrl","req","url","URL","searchParams","has","title","undefined","pathname","entries","xml","empty"],"mappings":"AAEA,SAASA,YAAY,QAAQ,oBAAmB;AAChD,SAASC,eAAe,QAAQ,uBAAsB;AAEtD,SAASC,eAAe,EAAEC,mBAAmB,QAAkC,oBAAmB;AAElG;;;;;;;;;;;;;;;;;;CAkBC,GACD,OAAO,SAASC,mBAAmBC,IAUlC;IACC,OAAO;QACL,IAAI;YACF,MAAMC,UAAU,MAAMD,KAAKE,gBAAgB;YAC3C,MAAMC,OA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;QAC7G,IAAI;YACF,MAAME,UAAU,MAAMX;YACtB,MAAMY,MAAMhC,gBAAgB+B,SAAS;gBAAET;YAAO;YAC9C,OAAO,IAAIR,SAASkB,KAAK;gBACvBjB,SAAS;oBAAE,gBAAgB;gBAAiC;YAC9D;QACF,EAAE,OAAOC,KAAK;YACZC,QAAQC,IAAI,CAAC,8DAA8DF;YAC3E,sEAAsE;YACtE,MAAMiB,QACJ,6CACA;YACF,OAAO,IAAInB,SAASmB,OAAO;gBACzBlB,SAAS;oBAAE,gBAAgB;gBAAiC;YAC9D;QACF;IACF;AACF"} \ No newline at end of file +{"version":3,"sources":["../../../src/modules/seo/routeHandlers.ts"],"sourcesContent":["import type { BasePayload } from 'payload'\n\nimport type { I18nConfig } from '../i18n/index.js'\nimport type { SitemapEntry } from './buildSitemapEntries.js'\n\nimport { buildLlmsTxt } from './buildLlmsTxt.js'\nimport { buildSitemapXml } from './buildSitemapXml.js'\nimport { buildSitemapCss, SITEMAP_STYLE_PARAM, type SitemapStyleOptions } from './sitemapStyle.js'\n\n/**\n * Ready-made Next route handler for /llms.txt. Replaces the ~60-line try/catch\n * every project was copying. buildLlmsTxt already handles collections without\n * drafts, so no workaround is needed here.\n *\n * // app/llms.txt/route.ts\n * import { createLlmsTxtRoute } from '@intecion/ipal-kit'\n * import { getCachedPayload } from '@/lib/content'\n * import { i18nConfig } from '@/i18n.config'\n * export const dynamic = 'force-dynamic'\n * export const GET = createLlmsTxtRoute({ getCachedPayload, config: i18nConfig,\n * baseUrl: process.env.NEXT_PUBLIC_SERVER_URL! })\n *\n * For the full-content variant, add a second route with `full: true`:\n *\n * // app/llms-full.txt/route.ts\n * export const GET = createLlmsTxtRoute({ getCachedPayload, config: i18nConfig,\n * baseUrl: process.env.NEXT_PUBLIC_SERVER_URL!, full: true })\n */\nexport function createLlmsTxtRoute(opts: {\n baseUrl: string\n config: I18nConfig\n /** Inline every page's full Markdown (llms-full.txt). Default false. */\n full?: boolean\n getCachedPayload: () => Promise\n pagesSlug?: string\n settingsSlug?: string\n /** Field holding a richer AI summary (buildSummaryField) to prefer as description. */\n summaryField?: string\n}): () => Promise {\n return async () => {\n try {\n const payload = await opts.getCachedPayload()\n const body = await buildLlmsTxt({\n baseUrl: opts.baseUrl,\n config: opts.config,\n full: opts.full,\n pagesSlug: opts.pagesSlug,\n payload,\n settingsSlug: opts.settingsSlug,\n summaryField: opts.summaryField,\n })\n return new Response(body, {\n headers: { 'Content-Type': 'text/plain; charset=utf-8' },\n })\n } catch (err) {\n // DB unreachable at build (container) — return a minimal valid file so the\n // route doesn't 500; it fills in at runtime. No per-project try/catch.\n console.warn('[ipal] createLlmsTxtRoute: could not build llms.txt:', err)\n return new Response('# llms.txt\\n', {\n headers: { 'Content-Type': 'text/plain; charset=utf-8' },\n })\n }\n }\n}\n\nexport type SitemapRouteOptions = {\n /** Legacy: your own stylesheet URL (e.g. '/sitemap.css'). Overrides `style`. */\n cssUrl?: string\n /**\n * Built-in browser look (default ON): the XML points at `?style`\n * and the same handler serves the CSS — nothing to copy into /public.\n * `false` = raw XML. Object = header/credit/accent (SitemapStyleOptions);\n * `title` may be async (sitemapRoute passes the Site Settings name).\n */\n style?: ({ title?: (() => Promise) | string } & Omit) | false\n}\n\n/**\n * Ready-made Next route handler for /sitemap.xml, styled for humans out of the box.\n * Usually you don't call this — `createContentHelpers` returns `sitemapRoute`:\n *\n * // app/sitemap.xml/route.ts — the whole file\n * export { sitemapRoute as GET } from '@/lib/content'\n * export const dynamic = 'force-dynamic'\n *\n * `GET /sitemap.xml` → XML (crawlers), `GET /sitemap.xml?style` → its CSS.\n * Don't keep app/sitemap.ts next to it — two sitemaps confuse crawlers.\n */\nexport function createSitemapRouteHandler(\n sitemap: () => Promise,\n opts: SitemapRouteOptions = {},\n): (req: Request) => Promise {\n const style = opts.cssUrl ? false : opts.style === false ? false : (opts.style ?? {})\n\n return async (req: Request) => {\n const url = new URL(req.url)\n\n if (style && url.searchParams.has(SITEMAP_STYLE_PARAM)) {\n let title: string | undefined\n try {\n title = typeof style.title === 'function' ? await style.title() : style.title\n } catch {\n title = undefined // DB down → generic heading, never a broken stylesheet\n }\n return new Response(buildSitemapCss({ ...style, title }), {\n headers: {\n 'Cache-Control': 'public, max-age=3600',\n 'Content-Type': 'text/css; charset=utf-8',\n 'X-Robots-Tag': 'noindex',\n },\n })\n }\n\n const cssUrl = opts.cssUrl ?? (style ? `${url.pathname}?${SITEMAP_STYLE_PARAM}` : undefined)\n try {\n const entries = await sitemap()\n const xml = buildSitemapXml(entries, { cssUrl })\n return new Response(xml, {\n headers: { 'Content-Type': 'application/xml; charset=utf-8' },\n })\n } catch (err) {\n console.warn('[ipal] createSitemapRouteHandler: could not build sitemap:', err)\n // Valid empty urlset so the route doesn't 500 during a DB-less build.\n const empty =\n '\\n' +\n ''\n return new Response(empty, {\n headers: { 'Content-Type': 'application/xml; charset=utf-8' },\n })\n }\n }\n}\n"],"names":["buildLlmsTxt","buildSitemapXml","buildSitemapCss","SITEMAP_STYLE_PARAM","createLlmsTxtRoute","opts","payload","getCachedPayload","body","baseUrl","config","full","pagesSlug","settingsSlug","summaryField","Response","headers","err","console","warn","createSitemapRouteHandler","sitemap","style","cssUrl","req","url","URL","searchParams","has","title","undefined","pathname","entries","xml","empty"],"mappings":"AAKA,SAASA,YAAY,QAAQ,oBAAmB;AAChD,SAASC,eAAe,QAAQ,uBAAsB;AACtD,SAASC,eAAe,EAAEC,mBAAmB,QAAkC,oBAAmB;AAElG;;;;;;;;;;;;;;;;;;CAkBC,GACD,OAAO,SAASC,mBAAmBC,IAUlC;IACC,OAAO;QACL,IAAI;YACF,MAAMC,UAAU,MAAMD,KAAKE,gBAAgB;YAC3C,MAAMC,OAAO,MAAMR,aAAa;gBAC9BS,SAASJ,KAAKI,OAAO;gBACrBC,QAAQL,KAAKK,MAAM;gBACnBC,MAAMN,KAAKM,IAAI;gBACfC,WAAWP,KAAKO,SAAS;gBACzBN;gBACAO,cAAcR,KAAKQ,YAAY;gBAC/BC,c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OAAOC,KAAK;YACZC,QAAQC,IAAI,CAAC,8DAA8DF;YAC3E,sEAAsE;YACtE,MAAMiB,QACJ,6CACA;YACF,OAAO,IAAInB,SAASmB,OAAO;gBACzBlB,SAAS;oBAAE,gBAAgB;gBAAiC;YAC9D;QACF;IACF;AACF"} \ No newline at end of file diff --git a/src/modules/seo/routeHandlers.ts b/src/modules/seo/routeHandlers.ts index 50df12e..211cb5e 100644 --- a/src/modules/seo/routeHandlers.ts +++ b/src/modules/seo/routeHandlers.ts @@ -1,8 +1,10 @@ import type { BasePayload } from 'payload' + import type { I18nConfig } from '../i18n/index.js' +import type { SitemapEntry } from './buildSitemapEntries.js' + import { buildLlmsTxt } from './buildLlmsTxt.js' import { buildSitemapXml } from './buildSitemapXml.js' -import type { SitemapEntry } from './buildSitemapEntries.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 }) */ export function createLlmsTxtRoute(opts: { - getCachedPayload: () => Promise - 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 + pagesSlug?: string + settingsSlug?: string /** Field holding a richer AI summary (buildSummaryField) to prefer as description. */ summaryField?: string }): () => Promise { @@ -39,12 +41,12 @@ export function createLlmsTxtRoute(opts: { 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,15 +64,15 @@ export function createLlmsTxtRoute(opts: { } 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 `?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 & { title?: string | (() => Promise) }) - /** Legacy: your own stylesheet URL (e.g. '/sitemap.css'). Overrides `style`. */ - cssUrl?: string + style?: ({ title?: (() => Promise) | string } & Omit) | false } /** @@ -87,13 +89,13 @@ export type SitemapRouteOptions = { export function createSitemapRouteHandler( sitemap: () => Promise, opts: SitemapRouteOptions = {}, -): (req?: Request) => Promise { +): (req: Request) => Promise { const style = opts.cssUrl ? false : opts.style === false ? false : (opts.style ?? {}) - return async (req?: Request) => { - const url = req ? new URL(req.url) : null + return async (req: Request) => { + 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 try { title = typeof style.title === 'function' ? await style.title() : style.title @@ -102,14 +104,14 @@ export function createSitemapRouteHandler( } return new Response(buildSitemapCss({ ...style, 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, { cssUrl })