Compare commits

...
4 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
radoslaw.smolinski e7ad64230a 1.8.6 2026-10-13 23:51:17 +02:00
radoslaw.smolinski 5af5033148 import fix in buildLinkField 2026-10-13 23:51:08 +02:00
12 changed files with 49 additions and 47 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 {};
+2 -2
View File
@@ -1,5 +1,5 @@
import { rowLabel } from 'src/modules/admin-ui/rowLabel.js';
const URL_PATTERN = /^(https?:\/\/|mailto:|tel:|#)/;
import { rowLabel } from '../admin-ui/rowLabel.js';
const URL_PATTERN = /^(?:https?:\/\/|mailto:|tel:|#)/;
/**
* The ONE link shape for a project: a page, an external URL (also mailto:,
* tel:, #anchor) or an uploaded file — plus label, new-tab flag and visual
File diff suppressed because one or more lines are too long
+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
+1 -1
View File
@@ -6,7 +6,7 @@
*/ /** Query parameter on the sitemap URL that returns the stylesheet instead of XML. */ export const SITEMAP_STYLE_PARAM = 'style';
export const DEFAULT_SITEMAP_CREDIT = 'Technology by Intecion.com';
/** CSS `content: "…"` value — escapes backslashes, quotes and newlines. */ const cssString = (s)=>`"${s.replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/[\r\n]+/g, ' ')}"`;
/** Only plain colour values — the option ends up inside a stylesheet. */ const safeColor = (c, fallback)=>c && /^(#[0-9a-f]{3,8}|[a-z]+|(rgb|hsl|oklch)a?\([\d\s.,%/-]+\))$/i.test(c.trim()) ? c.trim() : fallback;
/** Only plain colour values — the option ends up inside a stylesheet. */ const safeColor = (c, fallback)=>c && /^(?:#[0-9a-f]{3,8}|[a-z]+|(?:rgb|hsl|oklch)a?\([\d\s.,%/-]+\))$/i.test(c.trim()) ? c.trim() : fallback;
export function buildSitemapCss({ accent, credit, title } = {}) {
const heading = title?.trim() || 'XML Sitemap';
const note = credit === false ? '' : (credit ?? DEFAULT_SITEMAP_CREDIT).trim();
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@intecion/ipal-kit",
"version": "1.8.5",
"version": "1.8.7",
"description": "Intecion Payload Advanced Library — a Payload CMS 3 plugin: i18n, SEO, forms, consent, analytics, blog/archives.",
"license": "MIT",
"repository": {
+2 -2
View File
@@ -1,6 +1,6 @@
import type { ArrayField, Field, GroupField } from 'payload'
import { rowLabel } from 'src/modules/admin-ui/rowLabel.js'
import { rowLabel } from '../admin-ui/rowLabel.js'
export type LinkAppearance = 'link' | 'primary' | 'secondary'
@@ -18,7 +18,7 @@ export type BuildLinkFieldOptions = {
uploadTo?: string
}
const URL_PATTERN = /^(https?:\/\/|mailto:|tel:|#)/
const URL_PATTERN = /^(?:https?:\/\/|mailto:|tel:|#)/
type SiblingWithType = { type?: string } | undefined
+20 -18
View File
@@ -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<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> {
@@ -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 `<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
}
/**
@@ -87,13 +89,13 @@ export type SitemapRouteOptions = {
export function createSitemapRouteHandler(
sitemap: () => Promise<SitemapEntry[]>,
opts: SitemapRouteOptions = {},
): (req?: Request) => Promise<Response> {
): (req: Request) => Promise<Response> {
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 })
+1 -1
View File
@@ -26,7 +26,7 @@ const cssString = (s: string) => `"${s.replace(/\\/g, '\\\\').replace(/"/g, '\\"
/** Only plain colour values — the option ends up inside a stylesheet. */
const safeColor = (c: string | undefined, fallback: string) =>
c && /^(#[0-9a-f]{3,8}|[a-z]+|(rgb|hsl|oklch)a?\([\d\s.,%/-]+\))$/i.test(c.trim()) ? c.trim() : fallback
c && /^(?:#[0-9a-f]{3,8}|[a-z]+|(?:rgb|hsl|oklch)a?\([\d\s.,%/-]+\))$/i.test(c.trim()) ? c.trim() : fallback
export function buildSitemapCss({ accent, credit, title }: SitemapStyleOptions = {}): string {
const heading = title?.trim() || 'XML Sitemap'