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:
@@ -0,0 +1,37 @@
|
||||
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs'
|
||||
import path from 'node:path'
|
||||
import { describe, expect, test } from 'vitest'
|
||||
|
||||
const root = path.resolve(import.meta.dirname, '..')
|
||||
const pkg = JSON.parse(readFileSync(path.join(root, 'package.json'), 'utf8')) as { exports: Record<string, unknown> }
|
||||
|
||||
function files(dir: string): string[] {
|
||||
return readdirSync(dir).flatMap((name) => {
|
||||
const p = path.join(dir, name)
|
||||
return statSync(p).isDirectory() ? files(p) : /\.(?:md|ts|tsx|mjs)$/.test(name) ? [p] : []
|
||||
})
|
||||
}
|
||||
|
||||
describe('package exports', () => {
|
||||
test('every @intecion/ipal-kit/<subpath> used in docs and src is exported', () => {
|
||||
const used = new Map<string, string>()
|
||||
for (const file of [...files(path.join(root, 'docs')), ...files(path.join(root, 'src'))]) {
|
||||
for (const m of readFileSync(file, 'utf8').matchAll(/@intecion\/ipal-kit(?<sub>\/[a-z0-9./-]+)?(?=['"#\s`)])/g)) {
|
||||
const sub = m.groups?.sub ? `.${m.groups.sub}` : '.'
|
||||
// node_modules/@intecion/ipal-kit/dist|docs|package.json — filesystem paths in prose, not imports
|
||||
if (/^\.\/(?:dist|docs|package\.json)(?:\/|$)/.test(sub)) {continue}
|
||||
if (!used.has(sub)) {used.set(sub, path.relative(root, file))}
|
||||
}
|
||||
}
|
||||
const missing = [...used].filter(([sub]) => !(sub in pkg.exports)).map(([sub, file]) => `${sub} (e.g. ${file})`)
|
||||
expect(missing).toEqual([])
|
||||
})
|
||||
|
||||
test('every export points at a file the build produces from src', () => {
|
||||
for (const [sub, target] of Object.entries(pkg.exports)) {
|
||||
const out = typeof target === 'string' ? target : (target as { import: string }).import
|
||||
const src = out.replace('./dist/', 'src/').replace(/\.js$/, '.ts')
|
||||
expect(existsSync(path.join(root, src)) || existsSync(path.join(root, src.replace(/\.ts$/, '.tsx'))), `${sub} → ${src}`).toBe(true)
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,95 @@
|
||||
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
|
||||
|
||||
import type { I18nConfig } from '../src/modules/i18n/types.js'
|
||||
|
||||
import { buildIndexNowHook, createIndexNowKeyRoute, indexNowFields } from '../src/modules/seo/indexNow.js'
|
||||
|
||||
const config: I18nConfig = {
|
||||
defaultLocale: 'pl',
|
||||
locales: [
|
||||
{ code: 'pl', label: 'Polski' },
|
||||
{ code: 'en', label: 'English' },
|
||||
],
|
||||
}
|
||||
|
||||
function fakeReq(doc: Record<string, unknown>, settings: Record<string, unknown>) {
|
||||
return {
|
||||
payload: {
|
||||
findByID: vi.fn(async () => doc),
|
||||
findGlobal: vi.fn(async ({ slug }: { slug: string }) => (slug === 'site-integrations' ? { indexNowKey: 'k123' } : settings)),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
const flush = () => new Promise((r) => setTimeout(r, 0))
|
||||
|
||||
describe('IndexNow hook', () => {
|
||||
let fetchSpy: ReturnType<typeof vi.spyOn>
|
||||
beforeEach(() => {
|
||||
fetchSpy = vi.spyOn(globalThis, 'fetch').mockResolvedValue(new Response(null, { status: 202 }))
|
||||
vi.stubEnv('NODE_ENV', 'production')
|
||||
vi.stubEnv('NEXT_PUBLIC_SERVER_URL', 'https://acme.pl')
|
||||
})
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks()
|
||||
vi.unstubAllEnvs()
|
||||
})
|
||||
|
||||
const run = async (row: Record<string, unknown>, opts = {}, settings: Record<string, unknown> = {}) => {
|
||||
const req = fakeReq({ slug: { en: 'about', pl: 'o-nas' } }, settings)
|
||||
const hook = buildIndexNowHook({ config, ...opts })
|
||||
await hook({ collection: { slug: 'pages' }, context: {}, doc: { id: 1, ...row }, req } as never)
|
||||
await flush()
|
||||
await flush()
|
||||
}
|
||||
|
||||
test('published page → every language submitted with key and keyLocation', async () => {
|
||||
await run({ _status: 'published' })
|
||||
expect(fetchSpy).toHaveBeenCalledOnce()
|
||||
const body = JSON.parse((fetchSpy.mock.calls[0][1] as RequestInit).body as string)
|
||||
expect(body).toEqual({
|
||||
host: 'acme.pl',
|
||||
key: 'k123',
|
||||
keyLocation: 'https://acme.pl/indexnow-key.txt',
|
||||
urlList: ['https://acme.pl/pl/o-nas', 'https://acme.pl/en/about'],
|
||||
})
|
||||
})
|
||||
|
||||
test('archive entry gets the archive prefix; no archive page → nothing sent', async () => {
|
||||
await run({}, { contentCollection: 'posts' }, { postsArchive: { slug: { en: 'blog', pl: 'blog-pl' } } })
|
||||
const body = JSON.parse((fetchSpy.mock.calls[0][1] as RequestInit).body as string)
|
||||
expect(body.urlList).toEqual(['https://acme.pl/pl/blog-pl/o-nas', 'https://acme.pl/en/blog/about'])
|
||||
fetchSpy.mockClear()
|
||||
await run({}, { contentCollection: 'posts' }, {})
|
||||
expect(fetchSpy).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
test('drafts, noindex, dev and localhost send nothing', async () => {
|
||||
await run({ _status: 'draft' })
|
||||
await run({ noindex: true })
|
||||
vi.stubEnv('NODE_ENV', 'development')
|
||||
await run({})
|
||||
vi.stubEnv('NODE_ENV', 'production')
|
||||
vi.stubEnv('NEXT_PUBLIC_SERVER_URL', 'http://localhost:3000')
|
||||
await run({})
|
||||
expect(fetchSpy).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
describe('IndexNow key', () => {
|
||||
afterEach(() => vi.unstubAllEnvs())
|
||||
|
||||
test('field generates a 32-char key when empty and keeps an existing one', () => {
|
||||
const hook = (indexNowFields[0] as { hooks: { beforeChange: ((a: { value: unknown }) => string)[] } }).hooks.beforeChange[0]
|
||||
expect(hook({ value: '' })).toMatch(/^[0-9a-f]{32}$/)
|
||||
expect(hook({ value: ' mine ' })).toBe('mine')
|
||||
})
|
||||
|
||||
test('key route: env wins, 404 without a key', async () => {
|
||||
const payload = { findGlobal: async () => ({}) } as never
|
||||
expect((await createIndexNowKeyRoute({ getCachedPayload: async () => payload })()).status).toBe(404)
|
||||
vi.stubEnv('INDEXNOW_KEY', 'fromenv')
|
||||
const res = await createIndexNowKeyRoute({ getCachedPayload: async () => payload })()
|
||||
expect(await res.text()).toBe('fromenv')
|
||||
})
|
||||
})
|
||||
@@ -156,3 +156,21 @@ describe('generatePageMetadata — markdownAlternate', () => {
|
||||
expect((await off.generatePageMetadata('pl', ['o-nas'])).alternates?.types).toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
||||
describe('getPageJsonLd', () => {
|
||||
const i18n = { defaultLocale: 'pl', locales: [{ code: 'pl', label: 'Polski' }] } as const
|
||||
|
||||
test('WebPage + breadcrumbs from the real route, FAQ when mapped, no @context per node', async () => {
|
||||
await payload.create({ collection: 'pages' as never, data: { slug: 'kontakt', title: 'Kontakt' } as never })
|
||||
const h = createContentHelpers({ baseUrl: 'https://acme.pl', config: configPromise, i18n })
|
||||
const nodes = await h.getPageJsonLd('pl', ['kontakt'], {
|
||||
faq: () => [{ answer: 'Tak.', question: 'Czy dojeżdżacie?' }, { answer: '', question: 'puste' }],
|
||||
pageType: () => 'ContactPage',
|
||||
})
|
||||
expect(nodes.map((n) => n['@type'])).toEqual(['ContactPage', 'BreadcrumbList', 'FAQPage'])
|
||||
expect(nodes[0]).toMatchObject({ name: 'Kontakt', '@id': 'https://acme.pl/kontakt', inLanguage: 'pl' })
|
||||
expect(nodes.every((n) => !('@context' in n))).toBe(true)
|
||||
expect((nodes[2] as { mainEntity: unknown[] }).mainEntity).toHaveLength(1)
|
||||
expect(await h.getPageJsonLd('pl', ['nie-ma'])).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import { describe, expect, test } from 'vitest'
|
||||
|
||||
import { formatOpeningHours } from '../src/modules/seo/formatOpeningHours.js'
|
||||
|
||||
describe('formatOpeningHours', () => {
|
||||
test.each([
|
||||
['Pn-Pt: 08:00 - 17:00, Sob: 08:00 - 14:00', ['Mo-Fr 08:00-17:00', 'Sa 08:00-14:00']],
|
||||
['Pn–Pt 8–17, Sob: 8-14, Nd: nieczynne', ['Mo-Fr 08:00-17:00', 'Sa 08:00-14:00']],
|
||||
['Poniedziałek - Piątek: 9.30 - 17.30\nSobota: 10-14\nNiedziela: zamknięte', ['Mo-Fr 09:30-17:30', 'Sa 10:00-14:00']],
|
||||
['Pn do Pt 8:00 do 16:00', ['Mo-Fr 08:00-16:00']],
|
||||
['Sob: nieczynne, Nd 10-14', ['Su 10:00-14:00']],
|
||||
['Pn, Śr, Pt 9-17', ['Mo,We,Fr 09:00-17:00']],
|
||||
['Mon–Fri 9am... no: 9:00-18:00; Sat 10:00 to 15:00', ['Mo-Fr 09:00-18:00', 'Sa 10:00-15:00']],
|
||||
['Mo–Fr 8–16 Uhr; Sa 9–12; So geschlossen', ['Mo-Fr 08:00-16:00', 'Sa 09:00-12:00']],
|
||||
['Do 10-18', ['Th 10:00-18:00']],
|
||||
['całodobowo', ['Mo-Su 00:00-23:59']],
|
||||
['24/7', ['Mo-Su 00:00-23:59']],
|
||||
['Pn-Pt 8-24', ['Mo-Fr 08:00-23:59']],
|
||||
])('%s', (input, expected) => {
|
||||
expect(formatOpeningHours(input)).toEqual(expected)
|
||||
})
|
||||
|
||||
test('schema.org strings and arrays pass through; junk is dropped', () => {
|
||||
expect(formatOpeningHours(['Mo-Fr 08:00-17:00', 'Sa 09:00-13:00'])).toEqual(['Mo-Fr 08:00-17:00', 'Sa 09:00-13:00'])
|
||||
expect(formatOpeningHours(['Pn-Pt 8-16', 'Sa 09:00-13:00'])).toEqual(['Mo-Fr 08:00-16:00', 'Sa 09:00-13:00'])
|
||||
expect(formatOpeningHours('zadzwoń, umówimy się')).toEqual([])
|
||||
expect(formatOpeningHours('Pn-Pt 25-30')).toEqual([])
|
||||
expect(formatOpeningHours(undefined)).toEqual([])
|
||||
})
|
||||
})
|
||||
@@ -54,3 +54,26 @@ describe('ipalKit — config transform', () => {
|
||||
expect(() => ipalKit({ i18n: { defaultLocale: 'de', locales: i18n.locales }, twoFactor: false })).toThrow()
|
||||
})
|
||||
})
|
||||
|
||||
describe('ipalKit — auth collection', () => {
|
||||
test('injects a users auth collection when the project has none, with roles', async () => {
|
||||
const config = await ipalKit({ access: { authCollection: 'users' }, i18n, twoFactor: false })({
|
||||
collections: [],
|
||||
secret: 'x',
|
||||
} as unknown as Config)
|
||||
const users = config.collections?.find((c) => c.slug === 'users')
|
||||
expect(users?.auth).toBe(true)
|
||||
expect(users?.fields.some((f) => 'name' in f && f.name === 'roles')).toBe(true)
|
||||
})
|
||||
|
||||
test("keeps the project's own users collection", async () => {
|
||||
const own = { slug: 'users', auth: true, fields: [{ name: 'fullName', type: 'text' }] }
|
||||
const config = await ipalKit({ access: { authCollection: 'users' }, i18n, twoFactor: false })({
|
||||
collections: [own],
|
||||
secret: 'x',
|
||||
} as unknown as Config)
|
||||
const users = config.collections?.filter((c) => c.slug === 'users')
|
||||
expect(users).toHaveLength(1)
|
||||
expect(users?.[0].fields.some((f) => 'name' in f && f.name === 'fullName')).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -159,3 +159,46 @@ describe('consent cookie', () => {
|
||||
expect(parseConsent(undefined)).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('buildNavigationJsonLd', () => {
|
||||
test('resolves page links per locale, keeps own-site links only, dedupes, walks submenus', async () => {
|
||||
const { buildNavigationJsonLd } = await import('../src/modules/seo/buildSiteNavigationJsonLd.js')
|
||||
const page = (slug: string) => ({ type: 'internal' as const, page: { slug } })
|
||||
const nav = buildNavigationJsonLd({
|
||||
baseUrl: 'https://acme.pl/',
|
||||
config,
|
||||
homeSlug: { en: 'home', pl: 'start' },
|
||||
items: [
|
||||
{ link: { ...page('start'), label: 'Start' } },
|
||||
{ link: { ...page('uslugi'), label: 'Usługi' }, subItems: [{ link: { ...page('audyt'), label: 'Audyt' } }] },
|
||||
{ link: { type: 'external', label: 'Blog firmy X', url: 'https://medium.com/x' } },
|
||||
{ link: { ...page('uslugi'), label: 'Usługi (dup)' } },
|
||||
{ link: { ...page('bez-etykiety') } },
|
||||
],
|
||||
locale: 'pl',
|
||||
})
|
||||
expect(nav?.itemListElement.map((i: { name: string; url: string }) => [i.name, i.url])).toEqual([
|
||||
['Start', 'https://acme.pl/pl'],
|
||||
['Usługi', 'https://acme.pl/pl/uslugi'],
|
||||
['Audyt', 'https://acme.pl/pl/audyt'],
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe('buildCsp — googleMaps', () => {
|
||||
test('covers Maps JS API domains in every needed directive, no duplicates', () => {
|
||||
const { value } = buildCsp({ googleMaps: true })
|
||||
const dir = (name: string) => value.split('; ').find((d) => d.startsWith(`${name} `)) ?? ''
|
||||
for (const d of ['script-src', 'img-src', 'connect-src']) {
|
||||
expect(dir(d)).toContain('https://*.googleapis.com')
|
||||
expect(dir(d)).toContain('https://*.gstatic.com')
|
||||
}
|
||||
expect(dir('frame-src')).toContain('https://*.google.com')
|
||||
expect(dir('worker-src')).toContain('blob:')
|
||||
for (const d of value.split('; ')) {
|
||||
const parts = d.split(' ').slice(1)
|
||||
expect(new Set(parts).size).toBe(parts.length)
|
||||
}
|
||||
expect(buildCsp().value).toContain('https://fonts.gstatic.com')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import { afterEach, describe, expect, test, vi } from 'vitest'
|
||||
|
||||
import { createSubmitAction } from '../src/modules/forms/createSubmitAction.js'
|
||||
import { fakePayload } from './helpers.js'
|
||||
|
||||
vi.mock('server-only', () => ({}))
|
||||
|
||||
const forms = { contact: { fields: [{ name: 'name', blockType: 'text', required: true }] } }
|
||||
|
||||
describe('createSubmitAction', () => {
|
||||
afterEach(() => vi.restoreAllMocks())
|
||||
|
||||
const make = (ip: string) => {
|
||||
const { create, payload } = fakePayload({ forms })
|
||||
;(payload as unknown as { findGlobal: unknown }).findGlobal = vi.fn(async ({ slug }: { slug: string }) =>
|
||||
slug === 'notifications' ? { form: { success: 'Dzięki!', validation: 'Uzupełnij pola' } } : {},
|
||||
)
|
||||
const sendForm = createSubmitAction({ getCachedPayload: async () => payload, headers: () => new Headers({ 'x-real-ip': ip }) })
|
||||
return { create, sendForm }
|
||||
}
|
||||
|
||||
test('valid submission → stored, message from Notifications', async () => {
|
||||
const { create, sendForm } = make('10.8.0.1')
|
||||
expect(await sendForm('contact', 'pl', { name: 'Ala' })).toEqual({ message: 'Dzięki!', success: true })
|
||||
expect(create).toHaveBeenCalledOnce()
|
||||
})
|
||||
|
||||
test('honeypot → fake success, nothing stored; field is stripped otherwise', async () => {
|
||||
const { create, sendForm } = make('10.8.0.2')
|
||||
expect((await sendForm('contact', 'pl', { name: 'x', company_url: 'http://spam' })).success).toBe(true)
|
||||
expect(create).not.toHaveBeenCalled()
|
||||
expect((await sendForm('contact', 'pl', { name: 'Ala', company_url: '' })).success).toBe(true)
|
||||
expect(create).toHaveBeenCalledOnce()
|
||||
})
|
||||
|
||||
test('failure carries reason and field for the renderer', async () => {
|
||||
const { sendForm } = make('10.8.0.3')
|
||||
expect(await sendForm('contact', 'pl', {})).toMatchObject({ field: 'name', reason: 'validation', success: false })
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user