Compare commits

..
2 Commits
26 changed files with 491 additions and 12 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
import type { Field } from 'payload';
/**
* General site identity fields.
* Consumed by SEO/OG (siteName, defaultShareImage) and frontend (logo).
* Consumed by SEO/OG (siteName, defaultShareImage) and frontend (logo, favicon).
*/
export declare const generalFields: Field[];
+11 -3
View File
@@ -1,6 +1,7 @@
import { validateFaviconField } from '../../../modules/seo/index.js';
/**
* General site identity fields.
* Consumed by SEO/OG (siteName, defaultShareImage) and frontend (logo).
* Consumed by SEO/OG (siteName, defaultShareImage) and frontend (logo, favicon).
*/ export const generalFields = [
{
name: 'siteName',
@@ -63,7 +64,7 @@
name: 'logo',
type: 'upload',
admin: {
description: 'Primary site logo.'
description: 'Primary site logo. Also used for Organization structured data (buildOrganizationJsonLd).'
},
relationTo: 'media'
},
@@ -79,7 +80,14 @@
name: 'favicon',
type: 'upload',
admin: {
description: 'Square source icon (PNG or SVG) for the browser tab. Rendered by the frontend.'
description: 'Square icon, PNG or SVG, min. 48×48px (Google requires this to show it in search). Rendered via buildIconsMetadata.'
},
hooks: {
// Warns the editor at save time if the favicon is too small (<48×48) or
// not square — Google won't display such favicons in search results.
beforeValidate: [
validateFaviconField
]
},
relationTo: 'media'
}
+1 -1
View File
@@ -1 +1 @@
{"version":3,"sources":["../../../../src/globals/SiteSettings/fields/general.ts"],"sourcesContent":["import type { Field } from 'payload'\n\n/**\n * General site identity fields.\n * Consumed by SEO/OG (siteName, defaultShareImage) and frontend (logo).\n */\nexport const generalFields: Field[] = [\n {\n name: 'siteName',\n type: 'text',\n admin: {\n description: 'Used in page titles and Open Graph metadata.',\n },\n localized: true,\n required: true,\n },\n {\n name: 'titleOrder',\n type: 'select',\n admin: {\n description: 'Which comes first in browser tabs.',\n },\n defaultValue: 'page-first',\n options: [\n { label: 'Page first — About Us | Acme', value: 'page-first' },\n { label: 'Site first — Acme | About Us', value: 'site-first' },\n ],\n },\n {\n name: 'titleSeparator',\n type: 'select',\n admin: {\n description: 'Separates the page title from the site name in browser tabs.',\n },\n defaultValue: '|',\n options: [\n { label: 'Pipe — Page | Site', value: '|' },\n { label: 'Dash — Page – Site', value: '–' },\n { label: 'Hyphen — Page - Site', value: '-' },\n { label: 'Bullet — Page · Site', value: '·' },\n { label: 'Slash — Page / Site', value: '/' },\n ],\n },\n {\n name: 'logo',\n type: 'upload',\n admin: {\n description: 'Primary site logo.',\n },\n relationTo: 'media',\n },\n {\n name: 'defaultShareImage',\n type: 'upload',\n admin: {\n description: 'Fallback Open Graph image when a page has none.',\n },\n relationTo: 'media',\n },\n {\n name: 'favicon',\n type: 'upload',\n admin: {\n description: 'Square source icon (PNG or SVG) for the browser tab. Rendered by the frontend.',\n },\n relationTo: 'media',\n },\n]\n"],"names":["generalFields","name","type","admin","description","localized","required","defaultValue","options","label","value","relationTo"],"mappings":"AAEA;;;CAGC,GACD,OAAO,MAAMA,gBAAyB;IACpC;QACEC,MAAM;QACNC,MAAM;QACNC,OAAO;YACLC,aAAa;QACf;QACAC,WAAW;QACXC,UAAU;IACZ;IACA;QACEL,MAAM;QACNC,MAAM;QACNC,OAAO;YACLC,aAAa;QACf;QACAG,cAAc;QACdC,SAAS;YACP;gBAAEC,OAAO;gBAAkCC,OAAO;YAAa;YAC/D;gBAAED,OAAO;gBAAkCC,OAAO;YAAa;SAChE;IACH;IACA;QACET,MAAM;QACNC,MAAM;QACNC,OAAO;YACLC,aAAa;QACf;QACAG,cAAc;QACdC,SAAS;YACP;gBAAEC,OAAO;gBAAwBC,OAAO;YAAI;YAC5C;gBAAED,OAAO;gBAAwBC,OAAO;YAAI;YAC5C;gBAAED,OAAO;gBAA0BC,OAAO;YAAI;YAC9C;gBAAED,OAAO;gBAA0BC,OAAO;YAAI;YAC9C;gBAAED,OAAO;gBAAyBC,OAAO;YAAI;SAC9C;IACH;IACA;QACET,MAAM;QACNC,MAAM;QACNC,OAAO;YACLC,aAAa;QACf;QACAO,YAAY;IACd;IACA;QACEV,MAAM;QACNC,MAAM;QACNC,OAAO;YACLC,aAAa;QACf;QACAO,YAAY;IACd;IACA;QACEV,MAAM;QACNC,MAAM;QACNC,OAAO;YACLC,aAAa;QACf;QACAO,YAAY;IACd;CACD,CAAA"}
{"version":3,"sources":["../../../../src/globals/SiteSettings/fields/general.ts"],"sourcesContent":["import type { Field } from 'payload'\n\nimport { validateFaviconField } from '../../../modules/seo/index.js'\n\n/**\n * General site identity fields.\n * Consumed by SEO/OG (siteName, defaultShareImage) and frontend (logo, favicon).\n */\nexport const generalFields: Field[] = [\n {\n name: 'siteName',\n type: 'text',\n admin: {\n description: 'Used in page titles and Open Graph metadata.',\n },\n localized: true,\n required: true,\n },\n {\n name: 'titleOrder',\n type: 'select',\n admin: {\n description: 'Which comes first in browser tabs.',\n },\n defaultValue: 'page-first',\n options: [\n { label: 'Page first — About Us | Acme', value: 'page-first' },\n { label: 'Site first — Acme | About Us', value: 'site-first' },\n ],\n },\n {\n name: 'titleSeparator',\n type: 'select',\n admin: {\n description: 'Separates the page title from the site name in browser tabs.',\n },\n defaultValue: '|',\n options: [\n { label: 'Pipe — Page | Site', value: '|' },\n { label: 'Dash — Page – Site', value: '–' },\n { label: 'Hyphen — Page - Site', value: '-' },\n { label: 'Bullet — Page · Site', value: '·' },\n { label: 'Slash — Page / Site', value: '/' },\n ],\n },\n {\n name: 'logo',\n type: 'upload',\n admin: {\n description:\n 'Primary site logo. Also used for Organization structured data (buildOrganizationJsonLd).',\n },\n relationTo: 'media',\n },\n {\n name: 'defaultShareImage',\n type: 'upload',\n admin: {\n description: 'Fallback Open Graph image when a page has none.',\n },\n relationTo: 'media',\n },\n {\n name: 'favicon',\n type: 'upload',\n admin: {\n description:\n 'Square icon, PNG or SVG, min. 48×48px (Google requires this to show it in search). Rendered via buildIconsMetadata.',\n },\n hooks: {\n // Warns the editor at save time if the favicon is too small (<48×48) or\n // not square — Google won't display such favicons in search results.\n beforeValidate: [validateFaviconField],\n },\n relationTo: 'media',\n },\n]\n"],"names":["validateFaviconField","generalFields","name","type","admin","description","localized","required","defaultValue","options","label","value","relationTo","hooks","beforeValidate"],"mappings":"AAEA,SAASA,oBAAoB,QAAQ,gCAA+B;AAEpE;;;CAGC,GACD,OAAO,MAAMC,gBAAyB;IACpC;QACEC,MAAM;QACNC,MAAM;QACNC,OAAO;YACLC,aAAa;QACf;QACAC,WAAW;QACXC,UAAU;IACZ;IACA;QACEL,MAAM;QACNC,MAAM;QACNC,OAAO;YACLC,aAAa;QACf;QACAG,cAAc;QACdC,SAAS;YACP;gBAAEC,OAAO;gBAAkCC,OAAO;YAAa;YAC/D;gBAAED,OAAO;gBAAkCC,OAAO;YAAa;SAChE;IACH;IACA;QACET,MAAM;QACNC,MAAM;QACNC,OAAO;YACLC,aAAa;QACf;QACAG,cAAc;QACdC,SAAS;YACP;gBAAEC,OAAO;gBAAwBC,OAAO;YAAI;YAC5C;gBAAED,OAAO;gBAAwBC,OAAO;YAAI;YAC5C;gBAAED,OAAO;gBAA0BC,OAAO;YAAI;YAC9C;gBAAED,OAAO;gBAA0BC,OAAO;YAAI;YAC9C;gBAAED,OAAO;gBAAyBC,OAAO;YAAI;SAC9C;IACH;IACA;QACET,MAAM;QACNC,MAAM;QACNC,OAAO;YACLC,aACE;QACJ;QACAO,YAAY;IACd;IACA;QACEV,MAAM;QACNC,MAAM;QACNC,OAAO;YACLC,aAAa;QACf;QACAO,YAAY;IACd;IACA;QACEV,MAAM;QACNC,MAAM;QACNC,OAAO;YACLC,aACE;QACJ;QACAQ,OAAO;YACL,wEAAwE;YACxE,qEAAqE;YACrEC,gBAAgB;gBAACd;aAAqB;QACxC;QACAY,YAAY;IACd;CACD,CAAA"}
+1
View File
@@ -29,6 +29,7 @@ export type { GlobalQueryOptions } from './modules/payload/index.js';
export { getGlobal, getSiteIntegrations, getSiteSettings, SITE_INTEGRATIONS_SLUG, SITE_SETTINGS_SLUG, } from './modules/payload/index.js';
export { buildSecurityHeaders } from './modules/security/index.js';
export type { BuildSecurityHeadersArgs, SecurityHeader } from './modules/security/index.js';
export { buildIconsMetadata, buildOrganizationJsonLd, validateFaviconField, } from './modules/seo/index.js';
export type { PageMetadata, SeoMeta, SeoOption } from './modules/seo/index.js';
export { buildHreflangAlternates, buildMetadata, composeTitle } from './modules/seo/index.js';
export type { AutoFillMapping, RobotsRules, SitemapEntry } from './modules/seo/index.js';
+1
View File
@@ -18,6 +18,7 @@ export { getNotificationTexts, NOTIFICATION_FALLBACK, resolveFormMessage } from
export { ALL_SYSTEM_PAGE_ROLES, getSystemPagePath } from './modules/pages/index.js';
export { getGlobal, getSiteIntegrations, getSiteSettings, SITE_INTEGRATIONS_SLUG, SITE_SETTINGS_SLUG } from './modules/payload/index.js';
export { buildSecurityHeaders } from './modules/security/index.js';
export { buildIconsMetadata, buildOrganizationJsonLd, validateFaviconField } from './modules/seo/index.js';
export { buildHreflangAlternates, buildMetadata, composeTitle } from './modules/seo/index.js';
export { buildAutoFillMetaHook, buildRobots, buildSitemapEntries, createMetadataGenerator, createPageMetadata, injectAutoFillMeta } from './modules/seo/index.js';
export { buildSlugField, toSlug } from './modules/slug/index.js';
+1 -1
View File
File diff suppressed because one or more lines are too long
+33
View File
@@ -0,0 +1,33 @@
import type { Metadata } from 'next';
type MediaLike = {
height?: null | number;
mimeType?: null | string;
url?: null | string;
width?: null | number;
} | null | undefined;
/**
* Builds Next.js `icons` metadata (favicon / apple-touch-icon) from the panel's
* favicon upload, so the browser tab AND Google get a proper <link rel="icon">.
*
* Why the plugin must do this (not the project): favicon-in-Google has strict
* rules — a real <link rel="icon"> in <head>, square, ≥48×48, at a stable URL.
* Leaving it to each project meant inconsistent hand-rolled tags and no favicon
* in search results. This generates the tags correctly, every time, from the
* panel field.
*
* Favicon is GLOBAL (same across pages), so call this once in the ROOT layout's
* generateMetadata — not per page:
*
* import { buildIconsMetadata } from '@intecion/ipal-kit'
* export async function generateMetadata(): Promise<Metadata> {
* const settings = await getSettings(locale)
* return buildIconsMetadata(settings.favicon)
* }
*
* Google notes: it caches favicons separately and slowly (days/weeks), and only
* shows them for icons it deems valid. Warn on too-small icons at upload time
* (see the media validation hook) so editors don't ship a <48px favicon Google
* will reject.
*/
export declare function buildIconsMetadata(favicon: MediaLike): Metadata;
export {};
+54
View File
@@ -0,0 +1,54 @@
/**
* Builds Next.js `icons` metadata (favicon / apple-touch-icon) from the panel's
* favicon upload, so the browser tab AND Google get a proper <link rel="icon">.
*
* Why the plugin must do this (not the project): favicon-in-Google has strict
* rules — a real <link rel="icon"> in <head>, square, ≥48×48, at a stable URL.
* Leaving it to each project meant inconsistent hand-rolled tags and no favicon
* in search results. This generates the tags correctly, every time, from the
* panel field.
*
* Favicon is GLOBAL (same across pages), so call this once in the ROOT layout's
* generateMetadata — not per page:
*
* import { buildIconsMetadata } from '@intecion/ipal-kit'
* export async function generateMetadata(): Promise<Metadata> {
* const settings = await getSettings(locale)
* return buildIconsMetadata(settings.favicon)
* }
*
* Google notes: it caches favicons separately and slowly (days/weeks), and only
* shows them for icons it deems valid. Warn on too-small icons at upload time
* (see the media validation hook) so editors don't ship a <48px favicon Google
* will reject.
*/ export function buildIconsMetadata(favicon) {
const url = favicon?.url;
if (!url) {
return {};
}
const isSvg = favicon?.mimeType === 'image/svg+xml' || url.endsWith('.svg');
return {
icons: {
// Main favicon. SVG scales; PNG should be ≥48×48 (ideally 96 or 192).
icon: isSvg ? [
{
type: 'image/svg+xml',
url
}
] : [
{
sizes: 'any',
url
}
],
// Apple touch icon (home-screen bookmark on iOS). Reuses the same asset.
apple: [
{
url
}
]
}
};
}
//# sourceMappingURL=buildIconsMetadata.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/modules/seo/buildIconsMetadata.ts"],"sourcesContent":["import type { Metadata } from 'next'\n\ntype MediaLike =\n | { height?: null | number; mimeType?: null | string; url?: null | string; width?: null | number }\n | null\n | undefined\n\n/**\n * Builds Next.js `icons` metadata (favicon / apple-touch-icon) from the panel's\n * favicon upload, so the browser tab AND Google get a proper <link rel=\"icon\">.\n *\n * Why the plugin must do this (not the project): favicon-in-Google has strict\n * rules — a real <link rel=\"icon\"> in <head>, square, ≥48×48, at a stable URL.\n * Leaving it to each project meant inconsistent hand-rolled tags and no favicon\n * in search results. This generates the tags correctly, every time, from the\n * panel field.\n *\n * Favicon is GLOBAL (same across pages), so call this once in the ROOT layout's\n * generateMetadata — not per page:\n *\n * import { buildIconsMetadata } from '@intecion/ipal-kit'\n * export async function generateMetadata(): Promise<Metadata> {\n * const settings = await getSettings(locale)\n * return buildIconsMetadata(settings.favicon)\n * }\n *\n * Google notes: it caches favicons separately and slowly (days/weeks), and only\n * shows them for icons it deems valid. Warn on too-small icons at upload time\n * (see the media validation hook) so editors don't ship a <48px favicon Google\n * will reject.\n */\nexport function buildIconsMetadata(favicon: MediaLike): Metadata {\n const url = favicon?.url\n if (!url) {return {}}\n\n const isSvg = favicon?.mimeType === 'image/svg+xml' || url.endsWith('.svg')\n\n return {\n icons: {\n // Main favicon. SVG scales; PNG should be ≥48×48 (ideally 96 or 192).\n icon: isSvg ? [{ type: 'image/svg+xml', url }] : [{ sizes: 'any', url }],\n // Apple touch icon (home-screen bookmark on iOS). Reuses the same asset.\n apple: [{ url }],\n },\n }\n}\n"],"names":["buildIconsMetadata","favicon","url","isSvg","mimeType","endsWith","icons","icon","type","sizes","apple"],"mappings":"AAOA;;;;;;;;;;;;;;;;;;;;;;;CAuBC,GACD,OAAO,SAASA,mBAAmBC,OAAkB;IACnD,MAAMC,MAAMD,SAASC;IACrB,IAAI,CAACA,KAAK;QAAC,OAAO,CAAC;IAAC;IAEpB,MAAMC,QAAQF,SAASG,aAAa,mBAAmBF,IAAIG,QAAQ,CAAC;IAEpE,OAAO;QACLC,OAAO;YACL,sEAAsE;YACtEC,MAAMJ,QAAQ;gBAAC;oBAAEK,MAAM;oBAAiBN;gBAAI;aAAE,GAAG;gBAAC;oBAAEO,OAAO;oBAAOP;gBAAI;aAAE;YACxE,yEAAyE;YACzEQ,OAAO;gBAAC;oBAAER;gBAAI;aAAE;QAClB;IACF;AACF"}
+41
View File
@@ -0,0 +1,41 @@
type MediaLike = {
url?: null | string;
} | null | undefined;
type OrganizationJsonLdArgs = {
/** Logo media (from panel). Google uses this for brand knowledge panels. */
logo?: MediaLike;
/** Organization / site name. */
name: string;
/** Optional social / official profile URLs (sameAs). */
sameAs?: string[];
/** Absolute site URL (https://…). */
url: string;
};
/**
* Builds Organization JSON-LD (schema.org) — helps Google associate the site
* with a brand: name, logo, official links. Improves how the site appears in
* search (brand recognition, logo in knowledge panels) and is a signal used
* alongside favicon for identity.
*
* Returns a plain object; the project renders it as a <script type="application/
* ld+json"> in the root layout:
*
* import { buildOrganizationJsonLd } from '@intecion/ipal-kit'
* const jsonLd = buildOrganizationJsonLd({
* name: settings.siteName, url: baseUrl, logo: settings.logo,
* })
* <script type="application/ld+json"
* dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }} />
*
* Data comes from the panel (siteName, logo) — nothing hardcoded. Emit once in
* the root layout (Organization is site-wide, not per page).
*/
export declare function buildOrganizationJsonLd({ name, logo, sameAs, url }: OrganizationJsonLdArgs): {
sameAs?: string[] | undefined;
logo?: string | undefined;
name: string;
'@context': string;
'@type': string;
url: string;
};
export {};
+35
View File
@@ -0,0 +1,35 @@
/**
* Builds Organization JSON-LD (schema.org) — helps Google associate the site
* with a brand: name, logo, official links. Improves how the site appears in
* search (brand recognition, logo in knowledge panels) and is a signal used
* alongside favicon for identity.
*
* Returns a plain object; the project renders it as a <script type="application/
* ld+json"> in the root layout:
*
* import { buildOrganizationJsonLd } from '@intecion/ipal-kit'
* const jsonLd = buildOrganizationJsonLd({
* name: settings.siteName, url: baseUrl, logo: settings.logo,
* })
* <script type="application/ld+json"
* dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }} />
*
* Data comes from the panel (siteName, logo) — nothing hardcoded. Emit once in
* the root layout (Organization is site-wide, not per page).
*/ export function buildOrganizationJsonLd({ name, logo, sameAs, url }) {
const logoUrl = logo?.url;
return {
name,
'@context': 'https://schema.org',
'@type': 'Organization',
url,
...logoUrl ? {
logo: logoUrl.startsWith('http') ? logoUrl : `${url}${logoUrl}`
} : {},
...sameAs && sameAs.length > 0 ? {
sameAs
} : {}
};
}
//# sourceMappingURL=buildOrganizationJsonLd.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/modules/seo/buildOrganizationJsonLd.ts"],"sourcesContent":["type MediaLike = { url?: null | string } | null | undefined\n\ntype OrganizationJsonLdArgs = {\n /** Logo media (from panel). Google uses this for brand knowledge panels. */\n logo?: MediaLike\n /** Organization / site name. */\n name: string\n /** Optional social / official profile URLs (sameAs). */\n sameAs?: string[]\n /** Absolute site URL (https://…). */\n url: string\n}\n\n/**\n * Builds Organization JSON-LD (schema.org) — helps Google associate the site\n * with a brand: name, logo, official links. Improves how the site appears in\n * search (brand recognition, logo in knowledge panels) and is a signal used\n * alongside favicon for identity.\n *\n * Returns a plain object; the project renders it as a <script type=\"application/\n * ld+json\"> in the root layout:\n *\n * import { buildOrganizationJsonLd } from '@intecion/ipal-kit'\n * const jsonLd = buildOrganizationJsonLd({\n * name: settings.siteName, url: baseUrl, logo: settings.logo,\n * })\n * <script type=\"application/ld+json\"\n * dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }} />\n *\n * Data comes from the panel (siteName, logo) — nothing hardcoded. Emit once in\n * the root layout (Organization is site-wide, not per page).\n */\nexport function buildOrganizationJsonLd({ name, logo, sameAs, url }: OrganizationJsonLdArgs) {\n const logoUrl = logo?.url\n\n return {\n name,\n '@context': 'https://schema.org',\n '@type': 'Organization',\n url,\n ...(logoUrl ? { logo: logoUrl.startsWith('http') ? logoUrl : `${url}${logoUrl}` } : {}),\n ...(sameAs && sameAs.length > 0 ? { sameAs } : {}),\n }\n}\n"],"names":["buildOrganizationJsonLd","name","logo","sameAs","url","logoUrl","startsWith","length"],"mappings":"AAaA;;;;;;;;;;;;;;;;;;CAkBC,GACD,OAAO,SAASA,wBAAwB,EAAEC,IAAI,EAAEC,IAAI,EAAEC,MAAM,EAAEC,GAAG,EAA0B;IACzF,MAAMC,UAAUH,MAAME;IAEtB,OAAO;QACLH;QACA,YAAY;QACZ,SAAS;QACTG;QACA,GAAIC,UAAU;YAAEH,MAAMG,QAAQC,UAAU,CAAC,UAAUD,UAAU,GAAGD,MAAMC,SAAS;QAAC,IAAI,CAAC,CAAC;QACtF,GAAIF,UAAUA,OAAOI,MAAM,GAAG,IAAI;YAAEJ;QAAO,IAAI,CAAC,CAAC;IACnD;AACF"}
+3
View File
@@ -1,7 +1,9 @@
export { buildAutoFillMetaHook } from './autoFillMeta.js';
export type { AutoFillMapping } from './autoFillMeta.js';
export { buildIconsMetadata } from './buildIconsMetadata.js';
export { buildMetadata } from './buildMetadata.js';
export type { PageMetadata } from './buildMetadata.js';
export { buildOrganizationJsonLd } from './buildOrganizationJsonLd.js';
export { buildRobots } from './buildRobots.js';
export type { RobotsRules } from './buildRobots.js';
export { buildSitemapEntries } from './buildSitemapEntries.js';
@@ -18,3 +20,4 @@ export type { SiteMetaConfig } from './readSiteMetaConfig.js';
export { buildSeoPlugin } from './seoPluginConfig.js';
export { slugsAcrossLocales } from './slugsAcrossLocales.js';
export type { SeoMeta, SeoOption } from './types.js';
export { validateFaviconField } from './validateFavicon.js';
+3
View File
@@ -1,5 +1,7 @@
export { buildAutoFillMetaHook } from './autoFillMeta.js';
export { buildIconsMetadata } from './buildIconsMetadata.js';
export { buildMetadata } from './buildMetadata.js';
export { buildOrganizationJsonLd } from './buildOrganizationJsonLd.js';
export { buildRobots } from './buildRobots.js';
export { buildSitemapEntries } from './buildSitemapEntries.js';
export { composeTitle } from './composeTitle.js';
@@ -11,5 +13,6 @@ export { injectSeoTabs } from './injectSeoTabs.js';
export { readSiteMetaConfig } from './readSiteMetaConfig.js';
export { buildSeoPlugin } from './seoPluginConfig.js';
export { slugsAcrossLocales } from './slugsAcrossLocales.js';
export { validateFaviconField } from './validateFavicon.js';
//# sourceMappingURL=index.js.map
+1 -1
View File
@@ -1 +1 @@
{"version":3,"sources":["../../../src/modules/seo/index.ts"],"sourcesContent":["export { buildAutoFillMetaHook } from './autoFillMeta.js'\nexport type { AutoFillMapping } from './autoFillMeta.js'\nexport { buildMetadata } from './buildMetadata.js'\nexport type { PageMetadata } from './buildMetadata.js'\nexport { buildRobots } from './buildRobots.js'\nexport type { RobotsRules } from './buildRobots.js'\nexport { buildSitemapEntries } from './buildSitemapEntries.js'\nexport type { SitemapEntry } from './buildSitemapEntries.js'\nexport { composeTitle } from './composeTitle.js'\nexport type { TitleOrder } from './composeTitle.js'\nexport { createMetadataGenerator } from './createMetadataGenerator.js'\nexport { createPageMetadata } from './createPageMetadata.js'\nexport { buildHreflangAlternates } from './hreflang.js'\nexport { injectAutoFillMeta } from './injectAutoFillMeta.js'\nexport { injectSeoTabs } from './injectSeoTabs.js'\nexport { readSiteMetaConfig } from './readSiteMetaConfig.js'\nexport type { SiteMetaConfig } from './readSiteMetaConfig.js'\nexport { buildSeoPlugin } from './seoPluginConfig.js'\nexport { slugsAcrossLocales } from './slugsAcrossLocales.js'\nexport type { SeoMeta, SeoOption } from './types.js'\n"],"names":["buildAutoFillMetaHook","buildMetadata","buildRobots","buildSitemapEntries","composeTitle","createMetadataGenerator","createPageMetadata","buildHreflangAlternates","injectAutoFillMeta","injectSeoTabs","readSiteMetaConfig","buildSeoPlugin","slugsAcrossLocales"],"mappings":"AAAA,SAASA,qBAAqB,QAAQ,oBAAmB;AAEzD,SAASC,aAAa,QAAQ,qBAAoB;AAElD,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,SAASC,mBAAmB,QAAQ,2BAA0B;AAE9D,SAASC,YAAY,QAAQ,oBAAmB;AAEhD,SAASC,uBAAuB,QAAQ,+BAA8B;AACtE,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,uBAAuB,QAAQ,gBAAe;AACvD,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,kBAAkB,QAAQ,0BAAyB;AAE5D,SAASC,cAAc,QAAQ,uBAAsB;AACrD,SAASC,kBAAkB,QAAQ,0BAAyB"}
{"version":3,"sources":["../../../src/modules/seo/index.ts"],"sourcesContent":["export { buildAutoFillMetaHook } from './autoFillMeta.js'\nexport type { AutoFillMapping } from './autoFillMeta.js'\nexport { buildIconsMetadata } from './buildIconsMetadata.js'\nexport { buildMetadata } from './buildMetadata.js'\nexport type { PageMetadata } from './buildMetadata.js'\nexport { buildOrganizationJsonLd } from './buildOrganizationJsonLd.js'\nexport { buildRobots } from './buildRobots.js'\nexport type { RobotsRules } from './buildRobots.js'\nexport { buildSitemapEntries } from './buildSitemapEntries.js'\nexport type { SitemapEntry } from './buildSitemapEntries.js'\nexport { composeTitle } from './composeTitle.js'\nexport type { TitleOrder } from './composeTitle.js'\nexport { createMetadataGenerator } from './createMetadataGenerator.js'\nexport { createPageMetadata } from './createPageMetadata.js'\nexport { buildHreflangAlternates } from './hreflang.js'\nexport { injectAutoFillMeta } from './injectAutoFillMeta.js'\nexport { injectSeoTabs } from './injectSeoTabs.js'\nexport { readSiteMetaConfig } from './readSiteMetaConfig.js'\nexport type { SiteMetaConfig } from './readSiteMetaConfig.js'\nexport { buildSeoPlugin } from './seoPluginConfig.js'\nexport { slugsAcrossLocales } from './slugsAcrossLocales.js'\nexport type { SeoMeta, SeoOption } from './types.js'\nexport { validateFaviconField } from './validateFavicon.js'\n"],"names":["buildAutoFillMetaHook","buildIconsMetadata","buildMetadata","buildOrganizationJsonLd","buildRobots","buildSitemapEntries","composeTitle","createMetadataGenerator","createPageMetadata","buildHreflangAlternates","injectAutoFillMeta","injectSeoTabs","readSiteMetaConfig","buildSeoPlugin","slugsAcrossLocales","validateFaviconField"],"mappings":"AAAA,SAASA,qBAAqB,QAAQ,oBAAmB;AAEzD,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,aAAa,QAAQ,qBAAoB;AAElD,SAASC,uBAAuB,QAAQ,+BAA8B;AACtE,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,SAASC,mBAAmB,QAAQ,2BAA0B;AAE9D,SAASC,YAAY,QAAQ,oBAAmB;AAEhD,SAASC,uBAAuB,QAAQ,+BAA8B;AACtE,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,uBAAuB,QAAQ,gBAAe;AACvD,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,kBAAkB,QAAQ,0BAAyB;AAE5D,SAASC,cAAc,QAAQ,uBAAsB;AACrD,SAASC,kBAAkB,QAAQ,0BAAyB;AAE5D,SAASC,oBAAoB,QAAQ,uBAAsB"}
+15
View File
@@ -0,0 +1,15 @@
import type { FieldHook } from 'payload';
/**
* Field validation for the favicon upload: Google rejects favicons under 48×48,
* so warn the editor at save time if the uploaded icon is too small or not
* square. This ENFORCES the requirement instead of silently shipping a favicon
* Google won't display.
*
* Attach to the favicon field's validate (or as a beforeValidate hook on the
* Media relationship). Non-blocking by default — returns a warning string that
* Payload surfaces; make it throw if you want a hard block.
*
* Note: dimensions come from the related Media doc (Payload stores width/height
* for image uploads), so this checks the resolved upload, not the raw file.
*/
export declare const validateFaviconField: FieldHook;
+44
View File
@@ -0,0 +1,44 @@
/**
* Field validation for the favicon upload: Google rejects favicons under 48×48,
* so warn the editor at save time if the uploaded icon is too small or not
* square. This ENFORCES the requirement instead of silently shipping a favicon
* Google won't display.
*
* Attach to the favicon field's validate (or as a beforeValidate hook on the
* Media relationship). Non-blocking by default — returns a warning string that
* Payload surfaces; make it throw if you want a hard block.
*
* Note: dimensions come from the related Media doc (Payload stores width/height
* for image uploads), so this checks the resolved upload, not the raw file.
*/ export const validateFaviconField = async ({ req, value })=>{
if (!value) {
return value;
} // no favicon set → nothing to validate (optional field)
try {
const media = await req.payload.findByID({
id: typeof value === 'object' ? value.id : value,
collection: 'media',
depth: 0
});
const width = media.width;
const height = media.height;
const mimeType = media.mimeType;
// SVG scales infinitely — skip size checks.
if (mimeType === 'image/svg+xml') {
return value;
}
if (typeof width === 'number' && typeof height === 'number') {
if (width < 48 || height < 48) {
req.payload.logger.warn(`[ipal] Favicon is ${width}×${height}px. Google requires ≥48×48 to ` + `display it in search results. Upload a larger square icon (96 or 192px).`);
}
if (width !== height) {
req.payload.logger.warn(`[ipal] Favicon is not square (${width}×${height}). Use a square icon ` + `so it isn't cropped in the browser tab or search results.`);
}
}
} catch {
// Media lookup failed — don't block the save over a validation warning.
}
return value;
};
//# sourceMappingURL=validateFavicon.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/modules/seo/validateFavicon.ts"],"sourcesContent":["import type { FieldHook } from 'payload'\n\n/**\n * Field validation for the favicon upload: Google rejects favicons under 48×48,\n * so warn the editor at save time if the uploaded icon is too small or not\n * square. This ENFORCES the requirement instead of silently shipping a favicon\n * Google won't display.\n *\n * Attach to the favicon field's validate (or as a beforeValidate hook on the\n * Media relationship). Non-blocking by default — returns a warning string that\n * Payload surfaces; make it throw if you want a hard block.\n *\n * Note: dimensions come from the related Media doc (Payload stores width/height\n * for image uploads), so this checks the resolved upload, not the raw file.\n */\nexport const validateFaviconField: FieldHook = async ({ req, value }) => {\n if (!value) {return value} // no favicon set → nothing to validate (optional field)\n\n try {\n const media = await req.payload.findByID({\n id: typeof value === 'object' ? (value as { id: string }).id : value,\n collection: 'media',\n depth: 0,\n })\n\n const width = (media as { width?: number }).width\n const height = (media as { height?: number }).height\n const mimeType = (media as { mimeType?: string }).mimeType\n\n // SVG scales infinitely — skip size checks.\n if (mimeType === 'image/svg+xml') {return value}\n\n if (typeof width === 'number' && typeof height === 'number') {\n if (width < 48 || height < 48) {\n req.payload.logger.warn(\n `[ipal] Favicon is ${width}×${height}px. Google requires ≥48×48 to ` +\n `display it in search results. Upload a larger square icon (96 or 192px).`,\n )\n }\n if (width !== height) {\n req.payload.logger.warn(\n `[ipal] Favicon is not square (${width}×${height}). Use a square icon ` +\n `so it isn't cropped in the browser tab or search results.`,\n )\n }\n }\n } catch {\n // Media lookup failed — don't block the save over a validation warning.\n }\n\n return value\n}\n"],"names":["validateFaviconField","req","value","media","payload","findByID","id","collection","depth","width","height","mimeType","logger","warn"],"mappings":"AAEA;;;;;;;;;;;;CAYC,GACD,OAAO,MAAMA,uBAAkC,OAAO,EAAEC,GAAG,EAAEC,KAAK,EAAE;IAClE,IAAI,CAACA,OAAO;QAAC,OAAOA;IAAK,EAAE,wDAAwD;IAEnF,IAAI;QACF,MAAMC,QAAQ,MAAMF,IAAIG,OAAO,CAACC,QAAQ,CAAC;YACvCC,IAAI,OAAOJ,UAAU,WAAW,AAACA,MAAyBI,EAAE,GAAGJ;YAC/DK,YAAY;YACZC,OAAO;QACT;QAEA,MAAMC,QAAQ,AAACN,MAA6BM,KAAK;QACjD,MAAMC,SAAS,AAACP,MAA8BO,MAAM;QACpD,MAAMC,WAAW,AAACR,MAAgCQ,QAAQ;QAE1D,4CAA4C;QAC5C,IAAIA,aAAa,iBAAiB;YAAC,OAAOT;QAAK;QAE/C,IAAI,OAAOO,UAAU,YAAY,OAAOC,WAAW,UAAU;YAC3D,IAAID,QAAQ,MAAMC,SAAS,IAAI;gBAC7BT,IAAIG,OAAO,CAACQ,MAAM,CAACC,IAAI,CACrB,CAAC,kBAAkB,EAAEJ,MAAM,CAAC,EAAEC,OAAO,8BAA8B,CAAC,GAClE,CAAC,wEAAwE,CAAC;YAEhF;YACA,IAAID,UAAUC,QAAQ;gBACpBT,IAAIG,OAAO,CAACQ,MAAM,CAACC,IAAI,CACrB,CAAC,8BAA8B,EAAEJ,MAAM,CAAC,EAAEC,OAAO,qBAAqB,CAAC,GACrE,CAAC,yDAAyD,CAAC;YAEjE;QACF;IACF,EAAE,OAAM;IACN,wEAAwE;IAC1E;IAEA,OAAOR;AACT,EAAC"}
+79
View File
@@ -248,3 +248,82 @@ const entries = await buildSitemapEntries({
Przy dziesiątkach tysięcy URL-i Next ma `generateSitemaps` do dzielenia na
części — dodasz, gdyby realnie było ich tyle. Jedna sitemapa wystarcza do ~50k.
## Favicon w Google + Organization (branding w wyszukiwarce)
Favicon i structured data wpływają na to, jak strona wygląda w wynikach Google.
Plugin generuje jedno i drugie z panelu — projekt tylko wpina w root layout.
### Favicon — dlaczego się nie pokazywał
Google ma twarde wymogi: `<link rel="icon">` w `<head>`, kwadratowy, **≥48×48px**,
stały URL. Gdy projekt renderował favicon „po swojemu", często był za mały, źle
otagowany albo nieobecny w head → Google go nie pokazywał. Plugin robi to teraz
poprawnie.
### Wpięcie favicon (root layout)
Favicon jest GLOBALNY (ten sam wszędzie) — wpina się RAZ w root layout, nie per strona:
```tsx
// app/(frontend)/[locale]/layout.tsx
import type { Metadata } from 'next'
import { buildIconsMetadata } from '@intecion/ipal-kit'
import { getSettings } from '@/lib/payload'
export async function generateMetadata({ params }): Promise<Metadata> {
const { locale } = await params
const settings = await getSettings(locale)
return buildIconsMetadata(settings.favicon) // z pola favicon (panel)
}
```
`buildIconsMetadata` generuje poprawne `icons` (favicon + apple-touch) z pola
favicon. SVG → skaluje się; PNG → powinien być ≥48×48 (walidacja ostrzega, patrz niżej).
### Wymuszenie rozmiaru (walidacja)
Pole favicon w SiteSettings ma walidację `validateFaviconField` — ostrzega
redaktora przy zapisie, jeśli favicon jest <48×48 albo nie kwadratowy. Redaktor
widzi ostrzeżenie, zamiast po cichu wgrać favicon, którego Google nie pokaże.
### Organization JSON-LD (branding)
Pomaga Google powiązać stronę z marką (nazwa, logo) — lepsze wyświetlanie w
wynikach, logo w knowledge panel.
```tsx
// root layout — RAZ (Organization jest globalny)
import { buildOrganizationJsonLd } from '@intecion/ipal-kit'
const jsonLd = buildOrganizationJsonLd({
name: settings.siteName,
url: process.env.NEXT_PUBLIC_SERVER_URL!,
logo: settings.logo,
sameAs: settings.socialLinks, // opcjonalne: profile społecznościowe
})
// w JSX layoutu:
<script
type="application/ld+json"
dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }}
/>
```
Dane z panelu (siteName, logo) — nic na sztywno.
### Po wdrożeniu — cierpliwość z Google
Google **cache'uje favicon osobno i wolno** (dni, czasem tygodnie). Po poprawnym
wpięciu favicon nie pojawi się natychmiast — Googlebot musi ponownie odwiedzić
stronę główną. Przyspieszenie: Search Console → prośba o ponowne indeksowanie
strony głównej. Sprawdź też, czy `/` nie blokuje Googlebota (robots) i czy
favicon URL jest publiczny (nie za auth).
### Weryfikacja
1. Otwórz stronę → DevTools → Elements → `<head>` → sprawdź `<link rel="icon">`
z poprawnym URL.
2. Otwórz sam URL favicon w przeglądarce — obraz się pokazuje, ≥48×48.
3. Rich Results Test (Google) — wklej URL strony, sprawdź Organization.
4. Search Console → poproś o ponowne indeksowanie strony głównej.
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@intecion/ipal-kit",
"version": "1.1.0",
"version": "1.1.1",
"description": "Intecion Payload Advanced Library — a Payload CMS 3 plugin: i18n, SEO, forms, consent, analytics, blog/archives.",
"license": "MIT",
"repository": {
+12 -3
View File
@@ -1,8 +1,10 @@
import type { Field } from 'payload'
import { validateFaviconField } from '../../../modules/seo/index.js'
/**
* General site identity fields.
* Consumed by SEO/OG (siteName, defaultShareImage) and frontend (logo).
* Consumed by SEO/OG (siteName, defaultShareImage) and frontend (logo, favicon).
*/
export const generalFields: Field[] = [
{
@@ -45,7 +47,8 @@ export const generalFields: Field[] = [
name: 'logo',
type: 'upload',
admin: {
description: 'Primary site logo.',
description:
'Primary site logo. Also used for Organization structured data (buildOrganizationJsonLd).',
},
relationTo: 'media',
},
@@ -61,7 +64,13 @@ export const generalFields: Field[] = [
name: 'favicon',
type: 'upload',
admin: {
description: 'Square source icon (PNG or SVG) for the browser tab. Rendered by the frontend.',
description:
'Square icon, PNG or SVG, min. 48×48px (Google requires this to show it in search). Rendered via buildIconsMetadata.',
},
hooks: {
// Warns the editor at save time if the favicon is too small (<48×48) or
// not square — Google won't display such favicons in search results.
beforeValidate: [validateFaviconField],
},
relationTo: 'media',
},
+5
View File
@@ -99,6 +99,11 @@ export {
} from './modules/payload/index.js'
export { buildSecurityHeaders } from './modules/security/index.js'
export type { BuildSecurityHeadersArgs, SecurityHeader } from './modules/security/index.js'
export {
buildIconsMetadata,
buildOrganizationJsonLd,
validateFaviconField,
} from './modules/seo/index.js'
export type { PageMetadata, SeoMeta, SeoOption } from './modules/seo/index.js'
export { buildHreflangAlternates, buildMetadata, composeTitle } from './modules/seo/index.js'
export type { AutoFillMapping, RobotsRules, SitemapEntry } from './modules/seo/index.js'
+46
View File
@@ -0,0 +1,46 @@
import type { Metadata } from 'next'
type MediaLike =
| { height?: null | number; mimeType?: null | string; url?: null | string; width?: null | number }
| null
| undefined
/**
* Builds Next.js `icons` metadata (favicon / apple-touch-icon) from the panel's
* favicon upload, so the browser tab AND Google get a proper <link rel="icon">.
*
* Why the plugin must do this (not the project): favicon-in-Google has strict
* rules — a real <link rel="icon"> in <head>, square, ≥48×48, at a stable URL.
* Leaving it to each project meant inconsistent hand-rolled tags and no favicon
* in search results. This generates the tags correctly, every time, from the
* panel field.
*
* Favicon is GLOBAL (same across pages), so call this once in the ROOT layout's
* generateMetadata — not per page:
*
* import { buildIconsMetadata } from '@intecion/ipal-kit'
* export async function generateMetadata(): Promise<Metadata> {
* const settings = await getSettings(locale)
* return buildIconsMetadata(settings.favicon)
* }
*
* Google notes: it caches favicons separately and slowly (days/weeks), and only
* shows them for icons it deems valid. Warn on too-small icons at upload time
* (see the media validation hook) so editors don't ship a <48px favicon Google
* will reject.
*/
export function buildIconsMetadata(favicon: MediaLike): Metadata {
const url = favicon?.url
if (!url) {return {}}
const isSvg = favicon?.mimeType === 'image/svg+xml' || url.endsWith('.svg')
return {
icons: {
// Main favicon. SVG scales; PNG should be ≥48×48 (ideally 96 or 192).
icon: isSvg ? [{ type: 'image/svg+xml', url }] : [{ sizes: 'any', url }],
// Apple touch icon (home-screen bookmark on iOS). Reuses the same asset.
apple: [{ url }],
},
}
}
@@ -0,0 +1,44 @@
type MediaLike = { url?: null | string } | null | undefined
type OrganizationJsonLdArgs = {
/** Logo media (from panel). Google uses this for brand knowledge panels. */
logo?: MediaLike
/** Organization / site name. */
name: string
/** Optional social / official profile URLs (sameAs). */
sameAs?: string[]
/** Absolute site URL (https://…). */
url: string
}
/**
* Builds Organization JSON-LD (schema.org) — helps Google associate the site
* with a brand: name, logo, official links. Improves how the site appears in
* search (brand recognition, logo in knowledge panels) and is a signal used
* alongside favicon for identity.
*
* Returns a plain object; the project renders it as a <script type="application/
* ld+json"> in the root layout:
*
* import { buildOrganizationJsonLd } from '@intecion/ipal-kit'
* const jsonLd = buildOrganizationJsonLd({
* name: settings.siteName, url: baseUrl, logo: settings.logo,
* })
* <script type="application/ld+json"
* dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }} />
*
* Data comes from the panel (siteName, logo) — nothing hardcoded. Emit once in
* the root layout (Organization is site-wide, not per page).
*/
export function buildOrganizationJsonLd({ name, logo, sameAs, url }: OrganizationJsonLdArgs) {
const logoUrl = logo?.url
return {
name,
'@context': 'https://schema.org',
'@type': 'Organization',
url,
...(logoUrl ? { logo: logoUrl.startsWith('http') ? logoUrl : `${url}${logoUrl}` } : {}),
...(sameAs && sameAs.length > 0 ? { sameAs } : {}),
}
}
+3
View File
@@ -1,7 +1,9 @@
export { buildAutoFillMetaHook } from './autoFillMeta.js'
export type { AutoFillMapping } from './autoFillMeta.js'
export { buildIconsMetadata } from './buildIconsMetadata.js'
export { buildMetadata } from './buildMetadata.js'
export type { PageMetadata } from './buildMetadata.js'
export { buildOrganizationJsonLd } from './buildOrganizationJsonLd.js'
export { buildRobots } from './buildRobots.js'
export type { RobotsRules } from './buildRobots.js'
export { buildSitemapEntries } from './buildSitemapEntries.js'
@@ -18,3 +20,4 @@ export type { SiteMetaConfig } from './readSiteMetaConfig.js'
export { buildSeoPlugin } from './seoPluginConfig.js'
export { slugsAcrossLocales } from './slugsAcrossLocales.js'
export type { SeoMeta, SeoOption } from './types.js'
export { validateFaviconField } from './validateFavicon.js'
+52
View File
@@ -0,0 +1,52 @@
import type { FieldHook } from 'payload'
/**
* Field validation for the favicon upload: Google rejects favicons under 48×48,
* so warn the editor at save time if the uploaded icon is too small or not
* square. This ENFORCES the requirement instead of silently shipping a favicon
* Google won't display.
*
* Attach to the favicon field's validate (or as a beforeValidate hook on the
* Media relationship). Non-blocking by default — returns a warning string that
* Payload surfaces; make it throw if you want a hard block.
*
* Note: dimensions come from the related Media doc (Payload stores width/height
* for image uploads), so this checks the resolved upload, not the raw file.
*/
export const validateFaviconField: FieldHook = async ({ req, value }) => {
if (!value) {return value} // no favicon set → nothing to validate (optional field)
try {
const media = await req.payload.findByID({
id: typeof value === 'object' ? (value as { id: string }).id : value,
collection: 'media',
depth: 0,
})
const width = (media as { width?: number }).width
const height = (media as { height?: number }).height
const mimeType = (media as { mimeType?: string }).mimeType
// SVG scales infinitely — skip size checks.
if (mimeType === 'image/svg+xml') {return value}
if (typeof width === 'number' && typeof height === 'number') {
if (width < 48 || height < 48) {
req.payload.logger.warn(
`[ipal] Favicon is ${width}×${height}px. Google requires ≥48×48 to ` +
`display it in search results. Upload a larger square icon (96 or 192px).`,
)
}
if (width !== height) {
req.payload.logger.warn(
`[ipal] Favicon is not square (${width}×${height}). Use a square icon ` +
`so it isn't cropped in the browser tab or search results.`,
)
}
}
} catch {
// Media lookup failed — don't block the save over a validation warning.
}
return value
}