Compare commits
6
Commits
f1f808d079
..
v1.1.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e39e2a361a | ||
|
|
9d3e749c38 | ||
|
|
b7c6cb4d81 | ||
|
|
c41b75e364 | ||
|
|
41630bb8c5 | ||
|
|
b9430e7ab6 |
+1
-1
@@ -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
@@ -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
@@ -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"}
|
||||
Vendored
+2
@@ -29,6 +29,8 @@ 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 { buildBreadcrumbJsonLd, buildSiteNavigationJsonLd, buildWebSiteJsonLd, } 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';
|
||||
|
||||
Vendored
+4
@@ -18,6 +18,10 @@ 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';
|
||||
// Structured data (schema.org JSON-LD) — brand/sitelink signals for Google.
|
||||
// WebSite (+ optional SearchAction), BreadcrumbList (per page), SiteNavigation.
|
||||
export { buildBreadcrumbJsonLd, buildSiteNavigationJsonLd, buildWebSiteJsonLd } 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';
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+40
@@ -0,0 +1,40 @@
|
||||
type Crumb = {
|
||||
/** Visible name of the breadcrumb (e.g. 'Usługi'). */
|
||||
name: string;
|
||||
/** Absolute URL of this crumb (e.g. 'https://example.com/pl/uslugi'). */
|
||||
url: string;
|
||||
};
|
||||
/**
|
||||
* Builds BreadcrumbList JSON-LD (schema.org) for a page's position in the site
|
||||
* hierarchy. Google can show breadcrumbs in the result (Dom › Usługi › Detailing)
|
||||
* and uses them to understand structure — a signal that helps navigational
|
||||
* results and sitelinks.
|
||||
*
|
||||
* Unlike Organization/WebSite (site-wide, root layout), breadcrumbs are
|
||||
* PER-PAGE — build them from the page's ancestry and emit on that page:
|
||||
*
|
||||
* import { buildBreadcrumbJsonLd } from '@intecion/ipal-kit'
|
||||
* const jsonLd = buildBreadcrumbJsonLd([
|
||||
* { name: 'Strona główna', url: `${base}/pl` },
|
||||
* { name: 'Usługi', url: `${base}/pl/uslugi` },
|
||||
* { name: 'Detailing', url: `${base}/pl/uslugi/detailing` },
|
||||
* ])
|
||||
* <script type="application/ld+json" ... />
|
||||
*
|
||||
* The crumb data comes from the page's real position (parent pages / URL path),
|
||||
* NOT hardcoded. Derive it from the resolved route, not a static list.
|
||||
*
|
||||
* Returns null for an empty/single crumb list — a one-item breadcrumb isn't
|
||||
* meaningful and shouldn't be emitted.
|
||||
*/
|
||||
export declare function buildBreadcrumbJsonLd(crumbs: Crumb[]): {
|
||||
'@context': string;
|
||||
'@type': string;
|
||||
itemListElement: {
|
||||
name: string;
|
||||
'@type': string;
|
||||
item: string;
|
||||
position: number;
|
||||
}[];
|
||||
} | null;
|
||||
export {};
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Builds BreadcrumbList JSON-LD (schema.org) for a page's position in the site
|
||||
* hierarchy. Google can show breadcrumbs in the result (Dom › Usługi › Detailing)
|
||||
* and uses them to understand structure — a signal that helps navigational
|
||||
* results and sitelinks.
|
||||
*
|
||||
* Unlike Organization/WebSite (site-wide, root layout), breadcrumbs are
|
||||
* PER-PAGE — build them from the page's ancestry and emit on that page:
|
||||
*
|
||||
* import { buildBreadcrumbJsonLd } from '@intecion/ipal-kit'
|
||||
* const jsonLd = buildBreadcrumbJsonLd([
|
||||
* { name: 'Strona główna', url: `${base}/pl` },
|
||||
* { name: 'Usługi', url: `${base}/pl/uslugi` },
|
||||
* { name: 'Detailing', url: `${base}/pl/uslugi/detailing` },
|
||||
* ])
|
||||
* <script type="application/ld+json" ... />
|
||||
*
|
||||
* The crumb data comes from the page's real position (parent pages / URL path),
|
||||
* NOT hardcoded. Derive it from the resolved route, not a static list.
|
||||
*
|
||||
* Returns null for an empty/single crumb list — a one-item breadcrumb isn't
|
||||
* meaningful and shouldn't be emitted.
|
||||
*/ export function buildBreadcrumbJsonLd(crumbs) {
|
||||
if (!crumbs || crumbs.length < 2) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
'@context': 'https://schema.org',
|
||||
'@type': 'BreadcrumbList',
|
||||
itemListElement: crumbs.map((crumb, index)=>({
|
||||
name: crumb.name,
|
||||
'@type': 'ListItem',
|
||||
item: crumb.url,
|
||||
position: index + 1
|
||||
}))
|
||||
};
|
||||
}
|
||||
|
||||
//# sourceMappingURL=buildBreadcrumbJsonLd.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../src/modules/seo/buildBreadcrumbJsonLd.ts"],"sourcesContent":["type Crumb = {\n /** Visible name of the breadcrumb (e.g. 'Usługi'). */\n name: string\n /** Absolute URL of this crumb (e.g. 'https://example.com/pl/uslugi'). */\n url: string\n}\n\n/**\n * Builds BreadcrumbList JSON-LD (schema.org) for a page's position in the site\n * hierarchy. Google can show breadcrumbs in the result (Dom › Usługi › Detailing)\n * and uses them to understand structure — a signal that helps navigational\n * results and sitelinks.\n *\n * Unlike Organization/WebSite (site-wide, root layout), breadcrumbs are\n * PER-PAGE — build them from the page's ancestry and emit on that page:\n *\n * import { buildBreadcrumbJsonLd } from '@intecion/ipal-kit'\n * const jsonLd = buildBreadcrumbJsonLd([\n * { name: 'Strona główna', url: `${base}/pl` },\n * { name: 'Usługi', url: `${base}/pl/uslugi` },\n * { name: 'Detailing', url: `${base}/pl/uslugi/detailing` },\n * ])\n * <script type=\"application/ld+json\" ... />\n *\n * The crumb data comes from the page's real position (parent pages / URL path),\n * NOT hardcoded. Derive it from the resolved route, not a static list.\n *\n * Returns null for an empty/single crumb list — a one-item breadcrumb isn't\n * meaningful and shouldn't be emitted.\n */\nexport function buildBreadcrumbJsonLd(crumbs: Crumb[]) {\n if (!crumbs || crumbs.length < 2) {return null}\n\n return {\n '@context': 'https://schema.org',\n '@type': 'BreadcrumbList',\n itemListElement: crumbs.map((crumb, index) => ({\n name: crumb.name,\n '@type': 'ListItem',\n item: crumb.url,\n position: index + 1,\n })),\n }\n}\n"],"names":["buildBreadcrumbJsonLd","crumbs","length","itemListElement","map","crumb","index","name","item","url","position"],"mappings":"AAOA;;;;;;;;;;;;;;;;;;;;;;CAsBC,GACD,OAAO,SAASA,sBAAsBC,MAAe;IACnD,IAAI,CAACA,UAAUA,OAAOC,MAAM,GAAG,GAAG;QAAC,OAAO;IAAI;IAE9C,OAAO;QACL,YAAY;QACZ,SAAS;QACTC,iBAAiBF,OAAOG,GAAG,CAAC,CAACC,OAAOC,QAAW,CAAA;gBAC7CC,MAAMF,MAAME,IAAI;gBAChB,SAAS;gBACTC,MAAMH,MAAMI,GAAG;gBACfC,UAAUJ,QAAQ;YACpB,CAAA;IACF;AACF"}
|
||||
+33
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
|
||||
@@ -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"}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
type NavItem = {
|
||||
/** Visible label (e.g. 'Usługi'). */
|
||||
name: string;
|
||||
/** Absolute URL (e.g. 'https://example.com/pl/uslugi'). */
|
||||
url: string;
|
||||
};
|
||||
/**
|
||||
* Builds SiteNavigationElement JSON-LD (schema.org) from the main navigation —
|
||||
* declares the site's primary nav as structured data. A weaker sitelinks signal
|
||||
* than WebSite/breadcrumbs, but cheap: it tells Google which pages are the main
|
||||
* navigation targets.
|
||||
*
|
||||
* Feed it the SAME nav items the header renders (from the panel/nav global), so
|
||||
* the structured data matches the visible menu — not a separate hardcoded list.
|
||||
*
|
||||
* import { buildSiteNavigationJsonLd } from '@intecion/ipal-kit'
|
||||
* const jsonLd = buildSiteNavigationJsonLd(
|
||||
* navItems.map(i => ({ name: i.label, url: `${base}${i.href}` }))
|
||||
* )
|
||||
* <script type="application/ld+json" ... />
|
||||
*
|
||||
* Emit once (site-wide, root layout). Data from the nav source, never hardcoded.
|
||||
* Returns null for empty nav.
|
||||
*/
|
||||
export declare function buildSiteNavigationJsonLd(items: NavItem[]): {
|
||||
'@context': string;
|
||||
'@type': string;
|
||||
itemListElement: {
|
||||
name: string;
|
||||
'@type': string;
|
||||
position: number;
|
||||
url: string;
|
||||
}[];
|
||||
} | null;
|
||||
export {};
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* Builds SiteNavigationElement JSON-LD (schema.org) from the main navigation —
|
||||
* declares the site's primary nav as structured data. A weaker sitelinks signal
|
||||
* than WebSite/breadcrumbs, but cheap: it tells Google which pages are the main
|
||||
* navigation targets.
|
||||
*
|
||||
* Feed it the SAME nav items the header renders (from the panel/nav global), so
|
||||
* the structured data matches the visible menu — not a separate hardcoded list.
|
||||
*
|
||||
* import { buildSiteNavigationJsonLd } from '@intecion/ipal-kit'
|
||||
* const jsonLd = buildSiteNavigationJsonLd(
|
||||
* navItems.map(i => ({ name: i.label, url: `${base}${i.href}` }))
|
||||
* )
|
||||
* <script type="application/ld+json" ... />
|
||||
*
|
||||
* Emit once (site-wide, root layout). Data from the nav source, never hardcoded.
|
||||
* Returns null for empty nav.
|
||||
*/ export function buildSiteNavigationJsonLd(items) {
|
||||
if (!items || items.length === 0) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
'@context': 'https://schema.org',
|
||||
'@type': 'ItemList',
|
||||
itemListElement: items.map((item, index)=>({
|
||||
name: item.name,
|
||||
'@type': 'SiteNavigationElement',
|
||||
position: index + 1,
|
||||
url: item.url
|
||||
}))
|
||||
};
|
||||
}
|
||||
|
||||
//# sourceMappingURL=buildSiteNavigationJsonLd.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../src/modules/seo/buildSiteNavigationJsonLd.ts"],"sourcesContent":["type NavItem = {\n /** Visible label (e.g. 'Usługi'). */\n name: string\n /** Absolute URL (e.g. 'https://example.com/pl/uslugi'). */\n url: string\n}\n\n/**\n * Builds SiteNavigationElement JSON-LD (schema.org) from the main navigation —\n * declares the site's primary nav as structured data. A weaker sitelinks signal\n * than WebSite/breadcrumbs, but cheap: it tells Google which pages are the main\n * navigation targets.\n *\n * Feed it the SAME nav items the header renders (from the panel/nav global), so\n * the structured data matches the visible menu — not a separate hardcoded list.\n *\n * import { buildSiteNavigationJsonLd } from '@intecion/ipal-kit'\n * const jsonLd = buildSiteNavigationJsonLd(\n * navItems.map(i => ({ name: i.label, url: `${base}${i.href}` }))\n * )\n * <script type=\"application/ld+json\" ... />\n *\n * Emit once (site-wide, root layout). Data from the nav source, never hardcoded.\n * Returns null for empty nav.\n */\nexport function buildSiteNavigationJsonLd(items: NavItem[]) {\n if (!items || items.length === 0) {return null}\n\n return {\n '@context': 'https://schema.org',\n '@type': 'ItemList',\n itemListElement: items.map((item, index) => ({\n name: item.name,\n '@type': 'SiteNavigationElement',\n position: index + 1,\n url: item.url,\n })),\n }\n}\n"],"names":["buildSiteNavigationJsonLd","items","length","itemListElement","map","item","index","name","position","url"],"mappings":"AAOA;;;;;;;;;;;;;;;;;CAiBC,GACD,OAAO,SAASA,0BAA0BC,KAAgB;IACxD,IAAI,CAACA,SAASA,MAAMC,MAAM,KAAK,GAAG;QAAC,OAAO;IAAI;IAE9C,OAAO;QACL,YAAY;QACZ,SAAS;QACTC,iBAAiBF,MAAMG,GAAG,CAAC,CAACC,MAAMC,QAAW,CAAA;gBAC3CC,MAAMF,KAAKE,IAAI;gBACf,SAAS;gBACTC,UAAUF,QAAQ;gBAClBG,KAAKJ,KAAKI,GAAG;YACf,CAAA;IACF;AACF"}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
type SearchActionConfig = {
|
||||
/**
|
||||
* URL template for site search, with {search_term_string} placeholder.
|
||||
* e.g. 'https://example.com/szukaj?q={search_term_string}'. Only include if
|
||||
* the site actually HAS a working search page — a SearchAction pointing at a
|
||||
* non-existent search does more harm than good.
|
||||
*/
|
||||
target: string;
|
||||
};
|
||||
type WebSiteJsonLdArgs = {
|
||||
/** Site name (from panel — siteName). */
|
||||
name: string;
|
||||
/**
|
||||
* Optional site search. Enables the "sitelinks searchbox" — a search field
|
||||
* Google may show under the brand result. Only pass when a real search page
|
||||
* exists. Omit entirely otherwise.
|
||||
*/
|
||||
search?: SearchActionConfig;
|
||||
/** Absolute site URL (https://…). */
|
||||
url: string;
|
||||
};
|
||||
/**
|
||||
* Builds WebSite JSON-LD (schema.org). Two jobs:
|
||||
* - Declares the site + name (helps Google associate brand queries with the site).
|
||||
* - Optionally declares a SearchAction, which is what can produce the "sitelinks
|
||||
* searchbox" (a search field under the brand result in Google).
|
||||
*
|
||||
* IMPORTANT — sitelinks (the sub-links under a result) CANNOT be forced. No
|
||||
* schema guarantees them; Google generates them algorithmically from site
|
||||
* structure, internal links, clear titles, and ranking. This schema is a SIGNAL
|
||||
* that improves the odds and can enable the searchbox — not a switch. Manage
|
||||
* expectations accordingly (see docs/seo.md).
|
||||
*
|
||||
* Emit once in the ROOT layout (site-wide), from panel data:
|
||||
*
|
||||
* import { buildWebSiteJsonLd } from '@intecion/ipal-kit'
|
||||
* const jsonLd = buildWebSiteJsonLd({ name: settings.siteName, url: baseUrl })
|
||||
* <script type="application/ld+json"
|
||||
* dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }} />
|
||||
*/
|
||||
export declare function buildWebSiteJsonLd({ name, search, url }: WebSiteJsonLdArgs): {
|
||||
potentialAction?: {
|
||||
'@type': string;
|
||||
'query-input': string;
|
||||
target: {
|
||||
'@type': string;
|
||||
urlTemplate: string;
|
||||
};
|
||||
} | undefined;
|
||||
name: string;
|
||||
'@context': string;
|
||||
'@type': string;
|
||||
url: string;
|
||||
};
|
||||
export {};
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* Builds WebSite JSON-LD (schema.org). Two jobs:
|
||||
* - Declares the site + name (helps Google associate brand queries with the site).
|
||||
* - Optionally declares a SearchAction, which is what can produce the "sitelinks
|
||||
* searchbox" (a search field under the brand result in Google).
|
||||
*
|
||||
* IMPORTANT — sitelinks (the sub-links under a result) CANNOT be forced. No
|
||||
* schema guarantees them; Google generates them algorithmically from site
|
||||
* structure, internal links, clear titles, and ranking. This schema is a SIGNAL
|
||||
* that improves the odds and can enable the searchbox — not a switch. Manage
|
||||
* expectations accordingly (see docs/seo.md).
|
||||
*
|
||||
* Emit once in the ROOT layout (site-wide), from panel data:
|
||||
*
|
||||
* import { buildWebSiteJsonLd } from '@intecion/ipal-kit'
|
||||
* const jsonLd = buildWebSiteJsonLd({ name: settings.siteName, url: baseUrl })
|
||||
* <script type="application/ld+json"
|
||||
* dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }} />
|
||||
*/ export function buildWebSiteJsonLd({ name, search, url }) {
|
||||
return {
|
||||
name,
|
||||
'@context': 'https://schema.org',
|
||||
'@type': 'WebSite',
|
||||
url,
|
||||
...search ? {
|
||||
potentialAction: {
|
||||
'@type': 'SearchAction',
|
||||
'query-input': 'required name=search_term_string',
|
||||
target: {
|
||||
'@type': 'EntryPoint',
|
||||
urlTemplate: search.target
|
||||
}
|
||||
}
|
||||
} : {}
|
||||
};
|
||||
}
|
||||
|
||||
//# sourceMappingURL=buildWebSiteJsonLd.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../src/modules/seo/buildWebSiteJsonLd.ts"],"sourcesContent":["type SearchActionConfig = {\n /**\n * URL template for site search, with {search_term_string} placeholder.\n * e.g. 'https://example.com/szukaj?q={search_term_string}'. Only include if\n * the site actually HAS a working search page — a SearchAction pointing at a\n * non-existent search does more harm than good.\n */\n target: string\n}\n\ntype WebSiteJsonLdArgs = {\n /** Site name (from panel — siteName). */\n name: string\n /**\n * Optional site search. Enables the \"sitelinks searchbox\" — a search field\n * Google may show under the brand result. Only pass when a real search page\n * exists. Omit entirely otherwise.\n */\n search?: SearchActionConfig\n /** Absolute site URL (https://…). */\n url: string\n}\n\n/**\n * Builds WebSite JSON-LD (schema.org). Two jobs:\n * - Declares the site + name (helps Google associate brand queries with the site).\n * - Optionally declares a SearchAction, which is what can produce the \"sitelinks\n * searchbox\" (a search field under the brand result in Google).\n *\n * IMPORTANT — sitelinks (the sub-links under a result) CANNOT be forced. No\n * schema guarantees them; Google generates them algorithmically from site\n * structure, internal links, clear titles, and ranking. This schema is a SIGNAL\n * that improves the odds and can enable the searchbox — not a switch. Manage\n * expectations accordingly (see docs/seo.md).\n *\n * Emit once in the ROOT layout (site-wide), from panel data:\n *\n * import { buildWebSiteJsonLd } from '@intecion/ipal-kit'\n * const jsonLd = buildWebSiteJsonLd({ name: settings.siteName, url: baseUrl })\n * <script type=\"application/ld+json\"\n * dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }} />\n */\nexport function buildWebSiteJsonLd({ name, search, url }: WebSiteJsonLdArgs) {\n return {\n name,\n '@context': 'https://schema.org',\n '@type': 'WebSite',\n url,\n ...(search\n ? {\n potentialAction: {\n '@type': 'SearchAction',\n 'query-input': 'required name=search_term_string',\n target: {\n '@type': 'EntryPoint',\n urlTemplate: search.target,\n },\n },\n }\n : {}),\n }\n}\n"],"names":["buildWebSiteJsonLd","name","search","url","potentialAction","target","urlTemplate"],"mappings":"AAuBA;;;;;;;;;;;;;;;;;;CAkBC,GACD,OAAO,SAASA,mBAAmB,EAAEC,IAAI,EAAEC,MAAM,EAAEC,GAAG,EAAqB;IACzE,OAAO;QACLF;QACA,YAAY;QACZ,SAAS;QACTE;QACA,GAAID,SACA;YACEE,iBAAiB;gBACf,SAAS;gBACT,eAAe;gBACfC,QAAQ;oBACN,SAAS;oBACTC,aAAaJ,OAAOG,MAAM;gBAC5B;YACF;QACF,IACA,CAAC,CAAC;IACR;AACF"}
|
||||
Vendored
+10
-2
@@ -15,20 +15,28 @@ type BuildHreflangArgs = {
|
||||
slugs: LocalizedSlugs;
|
||||
};
|
||||
/**
|
||||
* Builds a map of locale → URL for hreflang alternate links, suitable for
|
||||
* Next.js Metadata `alternates.languages`.
|
||||
*
|
||||
* Bridges SEO and i18n: for each configured locale that the document has a
|
||||
* slug in, it produces the locale-aware path (via buildLocalizedPath),
|
||||
* optionally prefixed with an absolute origin.
|
||||
*
|
||||
* Also emits `x-default` pointing at the default locale — the version Google
|
||||
* serves when the user's language/region matches no hreflang, and the fallback
|
||||
* when the root ('/') redirect is ambiguous (Googlebot with no/foreign
|
||||
* Accept-Language).
|
||||
*
|
||||
* @example
|
||||
* buildHreflangAlternates({
|
||||
* slugs: { pl: 'o-nas', en: 'about' },
|
||||
* config,
|
||||
* baseUrl: 'https://example.com',
|
||||
* })
|
||||
* // → { pl: 'https://example.com/pl/o-nas', en: 'https://example.com/en/about' }
|
||||
* // → {
|
||||
* // pl: 'https://example.com/pl/o-nas',
|
||||
* // en: 'https://example.com/en/about',
|
||||
* // 'x-default': 'https://example.com/pl/o-nas',
|
||||
* // }
|
||||
*/
|
||||
export declare function buildHreflangAlternates({ baseUrl, config, homeSlug, prefix, slugs, }: BuildHreflangArgs): Record<string, string>;
|
||||
export {};
|
||||
|
||||
Vendored
+20
-3
@@ -1,19 +1,27 @@
|
||||
import { buildLocalizedPath, getLocaleCodes } from '../i18n/index.js';
|
||||
import { buildLocalizedPath, getDefaultLocale, getLocaleCodes } from '../i18n/index.js';
|
||||
/**
|
||||
* Builds a map of locale → URL for hreflang alternate links, suitable for
|
||||
* Next.js Metadata `alternates.languages`.
|
||||
*
|
||||
* Bridges SEO and i18n: for each configured locale that the document has a
|
||||
* slug in, it produces the locale-aware path (via buildLocalizedPath),
|
||||
* optionally prefixed with an absolute origin.
|
||||
*
|
||||
* Also emits `x-default` pointing at the default locale — the version Google
|
||||
* serves when the user's language/region matches no hreflang, and the fallback
|
||||
* when the root ('/') redirect is ambiguous (Googlebot with no/foreign
|
||||
* Accept-Language).
|
||||
*
|
||||
* @example
|
||||
* buildHreflangAlternates({
|
||||
* slugs: { pl: 'o-nas', en: 'about' },
|
||||
* config,
|
||||
* baseUrl: 'https://example.com',
|
||||
* })
|
||||
* // → { pl: 'https://example.com/pl/o-nas', en: 'https://example.com/en/about' }
|
||||
* // → {
|
||||
* // pl: 'https://example.com/pl/o-nas',
|
||||
* // en: 'https://example.com/en/about',
|
||||
* // 'x-default': 'https://example.com/pl/o-nas',
|
||||
* // }
|
||||
*/ export function buildHreflangAlternates({ baseUrl, config, homeSlug = 'home', prefix, slugs }) {
|
||||
const origin = baseUrl?.replace(/\/$/, '') ?? '';
|
||||
const alternates = {};
|
||||
@@ -29,6 +37,15 @@ import { buildLocalizedPath, getLocaleCodes } from '../i18n/index.js';
|
||||
alternates[locale] = `${origin}${path}`;
|
||||
}
|
||||
}
|
||||
// x-default: the version Google serves when the user's language/region doesn't
|
||||
// match any hreflang — and, crucially here, the fallback when the root ('/')
|
||||
// redirect is ambiguous (Googlebot with no/foreign Accept-Language). Point it
|
||||
// at the default locale (the primary market) so search shows that version by
|
||||
// default instead of guessing. Only set when the default locale has a URL.
|
||||
const defaultLocalePath = alternates[getDefaultLocale(config)];
|
||||
if (defaultLocalePath) {
|
||||
alternates['x-default'] = defaultLocalePath;
|
||||
}
|
||||
return alternates;
|
||||
}
|
||||
|
||||
|
||||
Vendored
+1
-1
@@ -1 +1 @@
|
||||
{"version":3,"sources":["../../../src/modules/seo/hreflang.ts"],"sourcesContent":["import type { I18nConfig, LocalizedSlugs } from '../i18n/index.js'\n\nimport { buildLocalizedPath, getLocaleCodes } from '../i18n/index.js'\n\ntype BuildHreflangArgs = {\n /** Absolute site origin, e.g. 'https://example.com'. Omit for relative paths. */\n baseUrl?: string\n config: I18nConfig\n /** Home slug that collapses to the locale root. Defaults to 'home'. */\n homeSlug?: string\n /**\n * Localized segment the document lives under (an archive page's slugs),\n * e.g. { pl: 'artykuly', en: 'articles' }. Locales missing from the prefix\n * are omitted — an entry with no archive in that language has no URL there.\n */\n prefix?: LocalizedSlugs\n /** slug per locale for the current document, e.g. { pl: 'o-nas', en: 'about' } */\n slugs: LocalizedSlugs\n}\n\n/**\n * Builds a map of locale → URL for hreflang alternate links, suitable for\n * Next.js Metadata `alternates.languages`.\n *\n * Bridges SEO and i18n: for each configured locale that the document has a\n * slug in, it produces the locale-aware path (via buildLocalizedPath),\n * optionally prefixed with an absolute origin.\n *\n * @example\n * buildHreflangAlternates({\n * slugs: { pl: 'o-nas', en: 'about' },\n * config,\n * baseUrl: 'https://example.com',\n * })\n * // → { pl: 'https://example.com/pl/o-nas', en: 'https://example.com/en/about' }\n */\nexport function buildHreflangAlternates({\n baseUrl,\n config,\n homeSlug = 'home',\n prefix,\n slugs,\n}: BuildHreflangArgs): Record<string, string> {\n const origin = baseUrl?.replace(/\\/$/, '') ?? ''\n const alternates: Record<string, string> = {}\n\n for (const locale of getLocaleCodes(config)) {\n const path = buildLocalizedPath({ config, homeSlug, locale, prefix, slugs })\n if (path) {\n alternates[locale] = `${origin}${path}`\n }\n }\n\n return alternates\n}\n"],"names":["buildLocalizedPath","getLocaleCodes","buildHreflangAlternates","baseUrl","config","homeSlug","prefix","slugs","origin","replace","alternates","locale","path"],"mappings":"AAEA,SAASA,kBAAkB,EAAEC,cAAc,QAAQ,mBAAkB;AAkBrE;;;;;;;;;;;;;;;CAeC,GACD,OAAO,SAASC,wBAAwB,EACtCC,OAAO,EACPC,MAAM,EACNC,WAAW,MAAM,EACjBC,MAAM,EACNC,KAAK,EACa;IAClB,MAAMC,SAASL,SAASM,QAAQ,OAAO,OAAO;IAC9C,MAAMC,aAAqC,CAAC;IAE5C,KAAK,MAAMC,UAAUV,eAAeG,QAAS;QAC3C,MAAMQ,OAAOZ,mBAAmB;YAAEI;YAAQC;YAAUM;YAAQL;YAAQC;QAAM;QAC1E,IAAIK,MAAM;YACRF,UAAU,CAACC,OAAO,GAAG,GAAGH,SAASI,MAAM;QACzC;IACF;IAEA,OAAOF;AACT"}
|
||||
{"version":3,"sources":["../../../src/modules/seo/hreflang.ts"],"sourcesContent":["import type { I18nConfig, LocalizedSlugs } from '../i18n/index.js'\n\nimport { buildLocalizedPath, getDefaultLocale, getLocaleCodes } from '../i18n/index.js'\n\ntype BuildHreflangArgs = {\n /** Absolute site origin, e.g. 'https://example.com'. Omit for relative paths. */\n baseUrl?: string\n config: I18nConfig\n /** Home slug that collapses to the locale root. Defaults to 'home'. */\n homeSlug?: string\n /**\n * Localized segment the document lives under (an archive page's slugs),\n * e.g. { pl: 'artykuly', en: 'articles' }. Locales missing from the prefix\n * are omitted — an entry with no archive in that language has no URL there.\n */\n prefix?: LocalizedSlugs\n /** slug per locale for the current document, e.g. { pl: 'o-nas', en: 'about' } */\n slugs: LocalizedSlugs\n}\n\n/**\n * Next.js Metadata `alternates.languages`.\n *\n * Bridges SEO and i18n: for each configured locale that the document has a\n * slug in, it produces the locale-aware path (via buildLocalizedPath),\n * optionally prefixed with an absolute origin.\n *\n * Also emits `x-default` pointing at the default locale — the version Google\n * serves when the user's language/region matches no hreflang, and the fallback\n * when the root ('/') redirect is ambiguous (Googlebot with no/foreign\n * Accept-Language).\n *\n * @example\n * buildHreflangAlternates({\n * slugs: { pl: 'o-nas', en: 'about' },\n * config,\n * baseUrl: 'https://example.com',\n * })\n * // → {\n * // pl: 'https://example.com/pl/o-nas',\n * // en: 'https://example.com/en/about',\n * // 'x-default': 'https://example.com/pl/o-nas',\n * // }\n */\nexport function buildHreflangAlternates({\n baseUrl,\n config,\n homeSlug = 'home',\n prefix,\n slugs,\n}: BuildHreflangArgs): Record<string, string> {\n const origin = baseUrl?.replace(/\\/$/, '') ?? ''\n const alternates: Record<string, string> = {}\n\n for (const locale of getLocaleCodes(config)) {\n const path = buildLocalizedPath({ config, homeSlug, locale, prefix, slugs })\n if (path) {\n alternates[locale] = `${origin}${path}`\n }\n }\n\n // x-default: the version Google serves when the user's language/region doesn't\n // match any hreflang — and, crucially here, the fallback when the root ('/')\n // redirect is ambiguous (Googlebot with no/foreign Accept-Language). Point it\n // at the default locale (the primary market) so search shows that version by\n // default instead of guessing. Only set when the default locale has a URL.\n const defaultLocalePath = alternates[getDefaultLocale(config)]\n if (defaultLocalePath) {\n alternates['x-default'] = defaultLocalePath\n }\n\n return alternates\n}\n"],"names":["buildLocalizedPath","getDefaultLocale","getLocaleCodes","buildHreflangAlternates","baseUrl","config","homeSlug","prefix","slugs","origin","replace","alternates","locale","path","defaultLocalePath"],"mappings":"AAEA,SAASA,kBAAkB,EAAEC,gBAAgB,EAAEC,cAAc,QAAQ,mBAAkB;AAkBvF;;;;;;;;;;;;;;;;;;;;;;;CAuBC,GACD,OAAO,SAASC,wBAAwB,EACtCC,OAAO,EACPC,MAAM,EACNC,WAAW,MAAM,EACjBC,MAAM,EACNC,KAAK,EACa;IAClB,MAAMC,SAASL,SAASM,QAAQ,OAAO,OAAO;IAC9C,MAAMC,aAAqC,CAAC;IAE5C,KAAK,MAAMC,UAAUV,eAAeG,QAAS;QAC3C,MAAMQ,OAAOb,mBAAmB;YAAEK;YAAQC;YAAUM;YAAQL;YAAQC;QAAM;QAC1E,IAAIK,MAAM;YACRF,UAAU,CAACC,OAAO,GAAG,GAAGH,SAASI,MAAM;QACzC;IACF;IAEA,+EAA+E;IAC/E,6EAA6E;IAC7E,8EAA8E;IAC9E,6EAA6E;IAC7E,2EAA2E;IAC3E,MAAMC,oBAAoBH,UAAU,CAACV,iBAAiBI,QAAQ;IAC9D,IAAIS,mBAAmB;QACrBH,UAAU,CAAC,YAAY,GAAGG;IAC5B;IAEA,OAAOH;AACT"}
|
||||
Vendored
+6
@@ -1,11 +1,16 @@
|
||||
export { buildAutoFillMetaHook } from './autoFillMeta.js';
|
||||
export type { AutoFillMapping } from './autoFillMeta.js';
|
||||
export { buildBreadcrumbJsonLd } from './buildBreadcrumbJsonLd.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';
|
||||
export type { SitemapEntry } from './buildSitemapEntries.js';
|
||||
export { buildSiteNavigationJsonLd } from './buildSiteNavigationJsonLd.js';
|
||||
export { buildWebSiteJsonLd } from './buildWebSiteJsonLd.js';
|
||||
export { composeTitle } from './composeTitle.js';
|
||||
export type { TitleOrder } from './composeTitle.js';
|
||||
export { createMetadataGenerator } from './createMetadataGenerator.js';
|
||||
@@ -18,3 +23,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';
|
||||
|
||||
Vendored
+6
@@ -1,7 +1,12 @@
|
||||
export { buildAutoFillMetaHook } from './autoFillMeta.js';
|
||||
export { buildBreadcrumbJsonLd } from './buildBreadcrumbJsonLd.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 { buildSiteNavigationJsonLd } from './buildSiteNavigationJsonLd.js';
|
||||
export { buildWebSiteJsonLd } from './buildWebSiteJsonLd.js';
|
||||
export { composeTitle } from './composeTitle.js';
|
||||
export { createMetadataGenerator } from './createMetadataGenerator.js';
|
||||
export { createPageMetadata } from './createPageMetadata.js';
|
||||
@@ -11,5 +16,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
|
||||
Vendored
+1
-1
@@ -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 { buildBreadcrumbJsonLd } from './buildBreadcrumbJsonLd.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 { buildSiteNavigationJsonLd } from './buildSiteNavigationJsonLd.js'\nexport { buildWebSiteJsonLd } from './buildWebSiteJsonLd.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","buildBreadcrumbJsonLd","buildIconsMetadata","buildMetadata","buildOrganizationJsonLd","buildRobots","buildSitemapEntries","buildSiteNavigationJsonLd","buildWebSiteJsonLd","composeTitle","createMetadataGenerator","createPageMetadata","buildHreflangAlternates","injectAutoFillMeta","injectSeoTabs","readSiteMetaConfig","buildSeoPlugin","slugsAcrossLocales","validateFaviconField"],"mappings":"AAAA,SAASA,qBAAqB,QAAQ,oBAAmB;AAEzD,SAASC,qBAAqB,QAAQ,6BAA4B;AAClE,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,yBAAyB,QAAQ,iCAAgC;AAC1E,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,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
@@ -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;
|
||||
Vendored
+44
@@ -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
@@ -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"}
|
||||
+289
@@ -248,3 +248,292 @@ 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 — format: PNG, nie SVG (ważne)
|
||||
|
||||
**Dla Google użyj PNG (≥48×48), nie SVG.** Zweryfikowane: Google niezawodnie
|
||||
wspiera PNG i ICO, ale **SVG w wynikach Google jest zawodny** — często pokazuje
|
||||
glob mimo że w karcie przeglądarki favicon renderuje się dobrze. Oficjalna
|
||||
dokumentacja Google nie wymienia SVG. Jeśli zależy Ci na faviconie w wyszukiwarce
|
||||
— wgraj PNG.
|
||||
|
||||
- **PNG ≥48×48** (idealnie 96 lub 192), kwadratowy → działa w Google ✓
|
||||
- **SVG** → działa w przeglądarce, ale w Google glob (zawodne) ✗
|
||||
- Walidacja pola favicon OSTRZEGA, gdy wgrasz SVG (żebyś wiedział, że dla search
|
||||
potrzebny PNG).
|
||||
|
||||
### 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.
|
||||
|
||||
## Ręczne rozszerzenia SEO/PWA (manifest itp.) — z panelu, NIE hardkod
|
||||
|
||||
Niektóre rzeczy SEO/PWA są na tyle projekt-specyficzne i jednorazowe, że plugin
|
||||
ich nie dostarcza (byłoby przeinżynierowaniem). Robisz je w projekcie — ALE
|
||||
poprawnie: czytając z panelu/env, nie zaszywając wartości klienta.
|
||||
|
||||
> **Zasada:** nawet gdy coś robisz ręcznie w projekcie, dane (nazwa, kolory,
|
||||
> opis, logo) czytaj z panelu (SiteSettings) albo env. Zaszyta nazwa/kolor
|
||||
> klienta = antywzorzec (patrz standardy-kodu.md). Manifest „R Custom Cars" z
|
||||
> hardkodem zadziała tylko dla jednego klienta.
|
||||
|
||||
### Web App Manifest (PWA) — jak zrobić DOBRZE
|
||||
|
||||
```ts
|
||||
// app/manifest.ts
|
||||
import type { MetadataRoute } from 'next'
|
||||
import { getCachedPayload } from '@/lib/content'
|
||||
import { getSiteSettings } from '@intecion/ipal-kit'
|
||||
import type { SiteSetting } from '@/payload-types'
|
||||
|
||||
export default async function manifest(): Promise<MetadataRoute.Manifest> {
|
||||
const payload = await getCachedPayload()
|
||||
const settings = await getSiteSettings<SiteSetting>(payload, { locale: 'pl' as never })
|
||||
|
||||
// Wszystko z panelu — zero hardkodu. Ikona z pola logo/favicon (upload),
|
||||
// nie ze statycznej ścieżki.
|
||||
const iconUrl =
|
||||
typeof settings.logo === 'object' && settings.logo?.url ? settings.logo.url : undefined
|
||||
|
||||
return {
|
||||
name: settings.siteName ?? '',
|
||||
short_name: settings.siteName ?? '', // albo osobne pole, jeśli dodasz
|
||||
start_url: '/',
|
||||
display: 'standalone',
|
||||
...(iconUrl
|
||||
? { icons: [{ src: iconUrl, sizes: 'any', type: 'image/svg+xml' }] }
|
||||
: {}),
|
||||
// description / theme_color / background_color:
|
||||
// jeśli klient ich potrzebuje, DODAJ POLA w SiteSettings i czytaj stąd —
|
||||
// NIE wpisuj '#d4af37' na sztywno. Bez pól — pomiń (manifest działa bez nich).
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Kontrast — czego NIE robić** (realny błąd z sesji):
|
||||
|
||||
```ts
|
||||
// ŹLE — wszystko zaszyte, zadziała tylko dla jednego klienta
|
||||
let name = 'R Custom Cars' // hardkod nazwy
|
||||
short_name: 'RCC', // hardkod
|
||||
description: 'Custom car styling...', // hardkod
|
||||
background_color: '#08080a', theme_color: '#d4af37', // hardkod kolorów
|
||||
icons: [{ src: '/logo/rcc-logo.svg' }] // statyczna ścieżka, nie panel
|
||||
```
|
||||
|
||||
Jeśli klient potrzebuje kolorów motywu / opisu w manifeście — **dodaj pola**
|
||||
`themeColor`, `manifestDescription` w SiteSettings (SiteSettingsFields przez
|
||||
opcje pluginu) i czytaj z panelu. Wtedy redaktor je zmienia, i nie są zaszyte.
|
||||
|
||||
### Inne ręczne rozszerzenia — ta sama zasada
|
||||
|
||||
Cokolwiek dodajesz ręcznie (dodatkowe meta tagi, structured data konkretnego
|
||||
typu, itp.):
|
||||
- dane z panelu (SiteSettings / pola strony) albo env
|
||||
- nic zaszytego per klient (nazwa, kolor, adres, domena)
|
||||
- jeśli to uniwersalne i powtarzalne → rozważ zgłoszenie do pluginu zamiast
|
||||
ręcznie (patrz ANTIGRAVITY-ZASADY-AGENT.md A0)
|
||||
|
||||
## SEO wielojęzyczne — hreflang, x-default, redirect roota
|
||||
|
||||
Przekierowanie `/` → `/pl` (negocjacja locale) może wpływać na SEO. Kluczowe:
|
||||
plugin generuje hreflang, więc Google rozumie, że `/pl` i `/en` to wersje
|
||||
językowe (nie duplikaty). Ale są niuanse.
|
||||
|
||||
### hreflang + x-default (generowane przez plugin)
|
||||
|
||||
`buildHreflangAlternates` generuje `alternates.languages` z wpisami per locale
|
||||
ORAZ **`x-default`** wskazujący na defaultLocale. x-default mówi Google: „gdy
|
||||
język/region użytkownika nie pasuje do żadnej wersji, użyj TEJ" — co pokrywa
|
||||
sytuację roota (Googlebot bez preferencji językowej). Bez x-default Google
|
||||
zgadywałby; z nim dostaje jasną wskazówkę (domyślnie pl).
|
||||
|
||||
Działa automatycznie przez createPageMetadata (canonical + hreflang + x-default).
|
||||
|
||||
### Redirect roota — na co uważać
|
||||
|
||||
- **307 (temporary)** na `/` → `/pl` — plugin tak robi. Dla warunkowego redirectu
|
||||
(zależnego od negocjacji) to obronne. Google i tak podąża.
|
||||
- **Negocjacja Accept-Language** — Googlebot bywa z `Accept-Language: en` albo
|
||||
bez. Może trafić na `/en`. x-default (→ pl) łagodzi to: Google wie, że
|
||||
domyślna wersja to polska.
|
||||
- **Root nie ma własnej treści** — cała moc idzie przez redirect na locale. To
|
||||
normalne dla i18n stron, hreflang to obsługuje.
|
||||
|
||||
### Weryfikacja SEO wielojęzycznego
|
||||
|
||||
1. Search Console → Inspekcja URL dla `/` — zobacz, na co Google przekierowuje
|
||||
i co indeksuje.
|
||||
2. Sprawdź, czy `/pl` i `/en` są indeksowane osobno (nie jako duplikaty).
|
||||
3. Rich Results / źródło strony → potwierdź `<link rel="alternate" hreflang="...">`
|
||||
z wpisami per locale + `hreflang="x-default"`.
|
||||
4. Search Console → raport Międzynarodowe targetowanie (jeśli dostępny) — błędy
|
||||
hreflang.
|
||||
|
||||
### Częste błędy (nie rób tak)
|
||||
|
||||
- Brak hreflang → Google traktuje wersje jako duplikaty (plugin to ma, nie usuwaj).
|
||||
- Zaszyta mapa ścieżek zamiast getLocalizedSlugs → hreflang się rozjedzie z bazą.
|
||||
- `noindex` na `/pl` przez pomyłkę → wypada z indeksu. Sprawdź robots meta.
|
||||
- Redirect roota na twardo 301 do jednego języka → tracisz negocjację i drugą
|
||||
wersję. Zostaw negocjację + hreflang.
|
||||
|
||||
## Sitelinks i structured data (branding w wynikach Google)
|
||||
|
||||
Cel: żeby wyszukanie marki („rcustomcars") pokazało stronę główną + podlinki
|
||||
(sitelinks) z opisami. Ważne — **sitelinków NIE DA SIĘ wymusić.** Google
|
||||
generuje je algorytmicznie ze struktury strony, linkowania wewnętrznego, jasnych
|
||||
tytułów i rankingu. Żaden kod ich nie włączy. Plugin dostarcza SYGNAŁY, które
|
||||
zwiększają szansę — nie gwarancję.
|
||||
|
||||
### Co realnie wpływa na sitelinki (kolejność wg wagi)
|
||||
|
||||
1. **Ranking na 1. stronie Google** — bez tego sitelinków nie ma. To robota SEO
|
||||
(treść, linki), nie kodu.
|
||||
2. **Czysta struktura + jasne tytuły** — logiczna hierarchia stron, opisowe title
|
||||
(nie „Strona 1"). Patrz fundamenty-projektu.md.
|
||||
3. **Linkowanie wewnętrzne** — ważne strony podlinkowane z głównej.
|
||||
4. **Structured data** (poniżej) — sygnał pomocniczy, nie przełącznik.
|
||||
5. **Sitemap + robots** — żeby Google w ogóle widział wszystkie strony (patrz
|
||||
niżej — to fundament, sprawdź czy działa!).
|
||||
|
||||
### Structured data z pluginu — 3 helpery
|
||||
|
||||
Wszystkie emitowane jako `<script type="application/ld+json">`, dane z panelu.
|
||||
|
||||
**1. WebSite + SearchAction (największy realny efekt)** — może dać sitelinks
|
||||
searchbox (pole wyszukiwania pod wynikiem marki). RAZ w root layout:
|
||||
```tsx
|
||||
import { buildWebSiteJsonLd } from '@intecion/ipal-kit'
|
||||
const jsonLd = buildWebSiteJsonLd({
|
||||
name: settings.siteName,
|
||||
url: baseUrl,
|
||||
// TYLKO jeśli masz działającą stronę wyszukiwania:
|
||||
search: { target: `${baseUrl}/szukaj?q={search_term_string}` },
|
||||
})
|
||||
```
|
||||
Pomiń `search`, jeśli nie ma realnej wyszukiwarki — SearchAction wskazujący na
|
||||
nieistniejącą stronę szkodzi.
|
||||
|
||||
**2. BreadcrumbList (realny efekt)** — okruszki w wynikach (Dom › Usługi ›
|
||||
Detailing) + Google rozumie hierarchię. PER STRONA, z pozycji strony:
|
||||
```tsx
|
||||
import { buildBreadcrumbJsonLd } from '@intecion/ipal-kit'
|
||||
const jsonLd = buildBreadcrumbJsonLd([
|
||||
{ name: 'Strona główna', url: `${base}/pl` },
|
||||
{ name: 'Usługi', url: `${base}/pl/uslugi` },
|
||||
{ name: 'Detailing', url: `${base}/pl/uslugi/detailing` },
|
||||
])
|
||||
```
|
||||
Okruszki buduj z RZECZYWISTEJ pozycji strony (resolveRoute / ścieżka URL), NIE z
|
||||
zaszytej listy.
|
||||
|
||||
**3. SiteNavigationElement (słabszy, tani)** — nawigacja jako dane. RAZ, z tych
|
||||
samych pozycji co menu w headerze:
|
||||
```tsx
|
||||
import { buildSiteNavigationJsonLd } from '@intecion/ipal-kit'
|
||||
const jsonLd = buildSiteNavigationJsonLd(
|
||||
navItems.map(i => ({ name: i.label, url: `${base}${i.href}` }))
|
||||
)
|
||||
```
|
||||
Dane z tego samego źródła co widoczne menu — nie osobna zaszyta lista.
|
||||
|
||||
### Realne oczekiwania (ważne)
|
||||
|
||||
- Structured data **nie gwarantuje** sitelinków — to sygnał wśród wielu.
|
||||
- Efekt (jeśli będzie) pojawia się **po tygodniach**, gdy Google przecrawluje i
|
||||
strona rankuje.
|
||||
- Największy wpływ ma **ranking + struktura + linkowanie**, nie schema. Schema
|
||||
pomaga Google zrozumieć, ale nie zastąpi bycia na 1. stronie.
|
||||
- Weryfikuj: Google Rich Results Test (czy schema poprawna) + Search Console
|
||||
(co Google pokazuje dla marki).
|
||||
|
||||
### To, co ZALEŻY OD PROJEKTU (obowiązki wpięcia)
|
||||
|
||||
Plugin dostarcza helpery — projekt MUSI je wpiąć i podać dane z panelu:
|
||||
|
||||
- [ ] `buildWebSiteJsonLd` w root layout (search tylko jeśli jest wyszukiwarka)
|
||||
- [ ] `buildOrganizationJsonLd` w root layout (logo, nazwa)
|
||||
- [ ] `buildBreadcrumbJsonLd` na podstronach (z realnej ścieżki)
|
||||
- [ ] `buildSiteNavigationJsonLd` z pozycji menu (jeśli jest header nav)
|
||||
- [ ] `app/robots.ts` i `app/sitemap.ts` wystawione (patrz niżej — bez tego
|
||||
Google nie widzi stron!)
|
||||
- [ ] Jasne, opisowe tytuły stron (nie generyczne)
|
||||
- [ ] Logiczna hierarchia + linkowanie wewnętrzne z głównej
|
||||
|
||||
Dane WSZĘDZIE z panelu (siteName, nav, logo), nigdy zaszyte.
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@intecion/ipal-kit",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.2",
|
||||
"description": "Intecion Payload Advanced Library — a Payload CMS 3 plugin: i18n, SEO, forms, consent, analytics, blog/archives.",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
|
||||
@@ -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',
|
||||
},
|
||||
|
||||
@@ -99,6 +99,18 @@ 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'
|
||||
// Structured data (schema.org JSON-LD) — brand/sitelink signals for Google.
|
||||
// WebSite (+ optional SearchAction), BreadcrumbList (per page), SiteNavigation.
|
||||
export {
|
||||
buildBreadcrumbJsonLd,
|
||||
buildSiteNavigationJsonLd,
|
||||
buildWebSiteJsonLd,
|
||||
} 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'
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
type Crumb = {
|
||||
/** Visible name of the breadcrumb (e.g. 'Usługi'). */
|
||||
name: string
|
||||
/** Absolute URL of this crumb (e.g. 'https://example.com/pl/uslugi'). */
|
||||
url: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds BreadcrumbList JSON-LD (schema.org) for a page's position in the site
|
||||
* hierarchy. Google can show breadcrumbs in the result (Dom › Usługi › Detailing)
|
||||
* and uses them to understand structure — a signal that helps navigational
|
||||
* results and sitelinks.
|
||||
*
|
||||
* Unlike Organization/WebSite (site-wide, root layout), breadcrumbs are
|
||||
* PER-PAGE — build them from the page's ancestry and emit on that page:
|
||||
*
|
||||
* import { buildBreadcrumbJsonLd } from '@intecion/ipal-kit'
|
||||
* const jsonLd = buildBreadcrumbJsonLd([
|
||||
* { name: 'Strona główna', url: `${base}/pl` },
|
||||
* { name: 'Usługi', url: `${base}/pl/uslugi` },
|
||||
* { name: 'Detailing', url: `${base}/pl/uslugi/detailing` },
|
||||
* ])
|
||||
* <script type="application/ld+json" ... />
|
||||
*
|
||||
* The crumb data comes from the page's real position (parent pages / URL path),
|
||||
* NOT hardcoded. Derive it from the resolved route, not a static list.
|
||||
*
|
||||
* Returns null for an empty/single crumb list — a one-item breadcrumb isn't
|
||||
* meaningful and shouldn't be emitted.
|
||||
*/
|
||||
export function buildBreadcrumbJsonLd(crumbs: Crumb[]) {
|
||||
if (!crumbs || crumbs.length < 2) {return null}
|
||||
|
||||
return {
|
||||
'@context': 'https://schema.org',
|
||||
'@type': 'BreadcrumbList',
|
||||
itemListElement: crumbs.map((crumb, index) => ({
|
||||
name: crumb.name,
|
||||
'@type': 'ListItem',
|
||||
item: crumb.url,
|
||||
position: index + 1,
|
||||
})),
|
||||
}
|
||||
}
|
||||
@@ -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 } : {}),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
type NavItem = {
|
||||
/** Visible label (e.g. 'Usługi'). */
|
||||
name: string
|
||||
/** Absolute URL (e.g. 'https://example.com/pl/uslugi'). */
|
||||
url: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds SiteNavigationElement JSON-LD (schema.org) from the main navigation —
|
||||
* declares the site's primary nav as structured data. A weaker sitelinks signal
|
||||
* than WebSite/breadcrumbs, but cheap: it tells Google which pages are the main
|
||||
* navigation targets.
|
||||
*
|
||||
* Feed it the SAME nav items the header renders (from the panel/nav global), so
|
||||
* the structured data matches the visible menu — not a separate hardcoded list.
|
||||
*
|
||||
* import { buildSiteNavigationJsonLd } from '@intecion/ipal-kit'
|
||||
* const jsonLd = buildSiteNavigationJsonLd(
|
||||
* navItems.map(i => ({ name: i.label, url: `${base}${i.href}` }))
|
||||
* )
|
||||
* <script type="application/ld+json" ... />
|
||||
*
|
||||
* Emit once (site-wide, root layout). Data from the nav source, never hardcoded.
|
||||
* Returns null for empty nav.
|
||||
*/
|
||||
export function buildSiteNavigationJsonLd(items: NavItem[]) {
|
||||
if (!items || items.length === 0) {return null}
|
||||
|
||||
return {
|
||||
'@context': 'https://schema.org',
|
||||
'@type': 'ItemList',
|
||||
itemListElement: items.map((item, index) => ({
|
||||
name: item.name,
|
||||
'@type': 'SiteNavigationElement',
|
||||
position: index + 1,
|
||||
url: item.url,
|
||||
})),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
type SearchActionConfig = {
|
||||
/**
|
||||
* URL template for site search, with {search_term_string} placeholder.
|
||||
* e.g. 'https://example.com/szukaj?q={search_term_string}'. Only include if
|
||||
* the site actually HAS a working search page — a SearchAction pointing at a
|
||||
* non-existent search does more harm than good.
|
||||
*/
|
||||
target: string
|
||||
}
|
||||
|
||||
type WebSiteJsonLdArgs = {
|
||||
/** Site name (from panel — siteName). */
|
||||
name: string
|
||||
/**
|
||||
* Optional site search. Enables the "sitelinks searchbox" — a search field
|
||||
* Google may show under the brand result. Only pass when a real search page
|
||||
* exists. Omit entirely otherwise.
|
||||
*/
|
||||
search?: SearchActionConfig
|
||||
/** Absolute site URL (https://…). */
|
||||
url: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds WebSite JSON-LD (schema.org). Two jobs:
|
||||
* - Declares the site + name (helps Google associate brand queries with the site).
|
||||
* - Optionally declares a SearchAction, which is what can produce the "sitelinks
|
||||
* searchbox" (a search field under the brand result in Google).
|
||||
*
|
||||
* IMPORTANT — sitelinks (the sub-links under a result) CANNOT be forced. No
|
||||
* schema guarantees them; Google generates them algorithmically from site
|
||||
* structure, internal links, clear titles, and ranking. This schema is a SIGNAL
|
||||
* that improves the odds and can enable the searchbox — not a switch. Manage
|
||||
* expectations accordingly (see docs/seo.md).
|
||||
*
|
||||
* Emit once in the ROOT layout (site-wide), from panel data:
|
||||
*
|
||||
* import { buildWebSiteJsonLd } from '@intecion/ipal-kit'
|
||||
* const jsonLd = buildWebSiteJsonLd({ name: settings.siteName, url: baseUrl })
|
||||
* <script type="application/ld+json"
|
||||
* dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }} />
|
||||
*/
|
||||
export function buildWebSiteJsonLd({ name, search, url }: WebSiteJsonLdArgs) {
|
||||
return {
|
||||
name,
|
||||
'@context': 'https://schema.org',
|
||||
'@type': 'WebSite',
|
||||
url,
|
||||
...(search
|
||||
? {
|
||||
potentialAction: {
|
||||
'@type': 'SearchAction',
|
||||
'query-input': 'required name=search_term_string',
|
||||
target: {
|
||||
'@type': 'EntryPoint',
|
||||
urlTemplate: search.target,
|
||||
},
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { I18nConfig, LocalizedSlugs } from '../i18n/index.js'
|
||||
|
||||
import { buildLocalizedPath, getLocaleCodes } from '../i18n/index.js'
|
||||
import { buildLocalizedPath, getDefaultLocale, getLocaleCodes } from '../i18n/index.js'
|
||||
|
||||
type BuildHreflangArgs = {
|
||||
/** Absolute site origin, e.g. 'https://example.com'. Omit for relative paths. */
|
||||
@@ -19,20 +19,28 @@ type BuildHreflangArgs = {
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a map of locale → URL for hreflang alternate links, suitable for
|
||||
* Next.js Metadata `alternates.languages`.
|
||||
*
|
||||
* Bridges SEO and i18n: for each configured locale that the document has a
|
||||
* slug in, it produces the locale-aware path (via buildLocalizedPath),
|
||||
* optionally prefixed with an absolute origin.
|
||||
*
|
||||
* Also emits `x-default` pointing at the default locale — the version Google
|
||||
* serves when the user's language/region matches no hreflang, and the fallback
|
||||
* when the root ('/') redirect is ambiguous (Googlebot with no/foreign
|
||||
* Accept-Language).
|
||||
*
|
||||
* @example
|
||||
* buildHreflangAlternates({
|
||||
* slugs: { pl: 'o-nas', en: 'about' },
|
||||
* config,
|
||||
* baseUrl: 'https://example.com',
|
||||
* })
|
||||
* // → { pl: 'https://example.com/pl/o-nas', en: 'https://example.com/en/about' }
|
||||
* // → {
|
||||
* // pl: 'https://example.com/pl/o-nas',
|
||||
* // en: 'https://example.com/en/about',
|
||||
* // 'x-default': 'https://example.com/pl/o-nas',
|
||||
* // }
|
||||
*/
|
||||
export function buildHreflangAlternates({
|
||||
baseUrl,
|
||||
@@ -51,5 +59,15 @@ export function buildHreflangAlternates({
|
||||
}
|
||||
}
|
||||
|
||||
// x-default: the version Google serves when the user's language/region doesn't
|
||||
// match any hreflang — and, crucially here, the fallback when the root ('/')
|
||||
// redirect is ambiguous (Googlebot with no/foreign Accept-Language). Point it
|
||||
// at the default locale (the primary market) so search shows that version by
|
||||
// default instead of guessing. Only set when the default locale has a URL.
|
||||
const defaultLocalePath = alternates[getDefaultLocale(config)]
|
||||
if (defaultLocalePath) {
|
||||
alternates['x-default'] = defaultLocalePath
|
||||
}
|
||||
|
||||
return alternates
|
||||
}
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
export { buildAutoFillMetaHook } from './autoFillMeta.js'
|
||||
export type { AutoFillMapping } from './autoFillMeta.js'
|
||||
export { buildBreadcrumbJsonLd } from './buildBreadcrumbJsonLd.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'
|
||||
export type { SitemapEntry } from './buildSitemapEntries.js'
|
||||
export { buildSiteNavigationJsonLd } from './buildSiteNavigationJsonLd.js'
|
||||
export { buildWebSiteJsonLd } from './buildWebSiteJsonLd.js'
|
||||
export { composeTitle } from './composeTitle.js'
|
||||
export type { TitleOrder } from './composeTitle.js'
|
||||
export { createMetadataGenerator } from './createMetadataGenerator.js'
|
||||
@@ -18,3 +23,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'
|
||||
|
||||
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user