SEO/GEO tools and project requests: site index, IndexNow, page JSON-LD, fixes

GEO / SEO
- collectSiteIndex: one list of public docs per locale (pages + archive
  entries) on sitemap rules; llms.txt/llms-full and MCP list_pages now include
  blog/content entries and every language. Fixes hard-coded "## Strony" heading
  and homepage not collapsing to the locale root in llms.txt.
- Markdown frontmatter: canonical url + updated date.
- Metadata: X/Twitter card, OG image width/height/alt, og:type article with
  published/modified times for entries.
- Fix: Site Settings "defaultShareImage" was never used — now the OG fallback.
- getPageJsonLd (createContentHelpers): WebPage/CollectionPage/BlogPosting,
  BreadcrumbList from the real route, FAQPage via a project mapper.
- IndexNow (opt-in ipalKit({ indexNow: true })): submit published URLs in all
  languages, key generated in Site Integrations or INDEXNOW_KEY, key route.
- sameAs profiles in Site Settings + sameAsUrls(); sitemap <image:image>.

From project reports
- Fix: package exports were missing ./env and ./fluid.css although the docs
  import them (TS2307); regression test checks every documented subpath.
- Fix: plugins run before Payload adds its default users collection, so roles
  and 2FA had nothing to attach to — ipalKit injects an auth collection when
  the project has none (project's own one wins). Audit no longer errors on it.
- createMarkdownRoute, createSubmitAction (/server, headers injected).
- formatOpeningHours (PL/EN/DE text → schema.org), used by
  buildLocalBusinessJsonLd, which also takes a schema.org `type`.
- buildNavigationJsonLd straight from the header global.
- buildCsp googleMaps: full Maps JS API domain set; values de-duplicated.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-16 02:19:08 +02:00
co-authored by Claude Opus 5.5
parent 9e40d74bb3
commit c9a50abc33
39 changed files with 1449 additions and 168 deletions
+167
View File
@@ -0,0 +1,167 @@
import type { BasePayload } from 'payload'
import type { ContentOption } from '../content/index.js'
import type { I18nConfig } from '../i18n/index.js'
import { archiveFieldName } from '../content/index.js'
import { buildLocalizedPath, getLocaleCodes, isValidLocale } from '../i18n/index.js'
import { resolveLocalized } from '../i18n/resolveLocalized.js'
/** One public, indexable document in one language. */
export type SiteIndexEntry = {
/** Collection slug, e.g. 'pages', 'posts'. */
collection: string
/** Plural label of the collection in this locale (from the project's config), e.g. 'Pages'. */
collectionLabel: string
createdAt?: string
/** Summary field (when configured and filled) or meta.description. */
description?: string
/** The raw document in this locale — for callers that render content (llms-full). */
doc: Record<string, unknown>
id: number | string
locale: string
/** Locale-aware path, e.g. /pl/blog/moj-wpis. */
path: string
/** publishedAt when the collection has it (setPublishedAt hook). */
publishedAt?: string
title: string
updatedAt?: string
/** Absolute URL (path prefixed with baseUrl). */
url: string
}
export type CollectSiteIndexArgs = {
/** Absolute origin; omit for relative URLs. */
baseUrl?: string
config: I18nConfig
/** Archive-backed collections, same value as the plugin option — their entries are included. */
content?: ContentOption
/** Population depth of `doc`. Default 0 (1 when you render blocks with images). */
depth?: number
/** Max documents per collection and locale. Default 1000. */
limit?: number
/** Only these locales. Default: every configured locale. */
locales?: string[]
/** Pages collection. Default 'pages'. */
pagesSlug?: string
payload: BasePayload
/** SiteSettings global. Default 'site-settings'. */
settingsSlug?: string
/** Field holding a richer AI summary (buildSummaryField) to prefer as description. */
summaryField?: string
}
type Row = {
[key: string]: unknown
_status?: string
createdAt?: string
id: number | string
meta?: { description?: unknown; noindex?: boolean } | null
noindex?: boolean | null
publishedAt?: unknown
slug?: unknown
title?: unknown
updatedAt?: string
}
/** Same exclusions as the sitemap: error/system pages that exist as documents. */
const EXCLUDED_SLUGS = new Set(['404', '500', 'error', 'not-found'])
function slugMap(rel: unknown, locales: string[]): Record<string, string> | undefined {
if (!rel || typeof rel !== 'object') {return undefined}
const slug = (rel as { slug?: unknown }).slug
if (typeof slug === 'string') {return Object.fromEntries(locales.map((l) => [l, slug]))}
if (!slug || typeof slug !== 'object') {return undefined}
const map: Record<string, string> = {}
for (const l of locales) {
const v = (slug as Record<string, unknown>)[l]
if (typeof v === 'string') {map[l] = v}
}
return Object.keys(map).length ? map : undefined
}
/**
* Every public page and archive entry, per language, with its URL, title,
* description and dates — ONE source for everything that lists the site to
* machines: llms.txt / llms-full.txt, the MCP server's list_pages, IndexNow.
* Uses the same rules as the sitemap (published only, no noindex, no 404/500
* pages, archive prefixes and homepage from System Pages), so all of them
* agree with what the site actually serves.
*
* Never throws for a missing field: a collection that can't be read is skipped.
*/
export async function collectSiteIndex({
baseUrl,
config,
content,
depth = 0,
limit = 1000,
locales,
pagesSlug = 'pages',
payload,
settingsSlug = 'site-settings',
summaryField,
}: CollectSiteIndexArgs): Promise<SiteIndexEntry[]> {
const all = getLocaleCodes(config)
const wanted = (locales ?? all).filter((l) => isValidLocale(l, config))
const origin = baseUrl?.replace(/\/$/, '') ?? ''
let settings: Record<string, unknown> = {}
try {
settings = (await payload.findGlobal({ slug: settingsSlug as never, depth: 1, locale: 'all' as never })) as Record<string, unknown>
} catch {
// no settings yet (fresh DB) — no homepage/archives, plain paths
}
const homeSlug = slugMap(settings.homepage, all) ?? 'home'
const collections: { prefix?: Record<string, string>; slug: string }[] = [{ slug: pagesSlug }]
for (const c of content?.collections ?? []) {
const prefix = slugMap(settings[archiveFieldName(c.slug)], all)
collections.push({ slug: c.slug, prefix })
}
const entries: SiteIndexEntry[] = []
for (const locale of wanted) {
for (const { slug: collection, prefix } of collections) {
// An archive collection without an archive page in this locale has no URLs there.
if (collection !== pagesSlug && !prefix?.[locale]) {continue}
let docs: Row[] = []
try {
const res = await payload.find({ collection: collection as never, depth, limit, locale: locale as never })
docs = (res?.docs ?? []) as Row[]
} catch {
continue
}
const labels = payload.collections?.[collection as never]?.config?.labels as { plural?: unknown } | undefined
const collectionLabel = resolveLocalized(labels?.plural, locale, collection)
for (const doc of docs) {
if (doc._status && doc._status !== 'published') {continue}
if (doc.noindex || doc.meta?.noindex) {continue}
const title = typeof doc.title === 'string' ? doc.title.trim() : ''
const slug = typeof doc.slug === 'string' ? doc.slug : ''
if (!title || !slug || EXCLUDED_SLUGS.has(slug)) {continue}
const path = buildLocalizedPath({ config, homeSlug, locale, prefix, slugs: { [locale]: slug } })
if (!path) {continue}
const summary = summaryField && typeof doc[summaryField] === 'string' ? (doc[summaryField]).trim() : ''
const metaDescription = typeof doc.meta?.description === 'string' ? doc.meta.description.trim() : ''
const description = summary || metaDescription
entries.push({
id: doc.id,
collection,
collectionLabel,
doc,
locale,
path,
title,
url: `${origin}${path}`,
...(description ? { description } : {}),
...(typeof doc.createdAt === 'string' ? { createdAt: doc.createdAt } : {}),
...(typeof doc.updatedAt === 'string' ? { updatedAt: doc.updatedAt } : {}),
...(typeof doc.publishedAt === 'string' ? { publishedAt: doc.publishedAt } : {}),
})
}
}
}
return entries
}