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]>
272 lines
16 KiB
Bash
272 lines
16 KiB
Bash
#!/usr/bin/env bash
|
|
# ipal-audit — deterministic checks of an ipal-kit project against AGENT.md.
|
|
# Run from the project root:
|
|
# bash .agents/skills/ipal-audit/scripts/audit.sh # all checks + tsc + build
|
|
# bash .agents/skills/ipal-audit/scripts/audit.sh --quick # static checks only
|
|
# bash .agents/skills/ipal-audit/scripts/audit.sh --help
|
|
# Exit code: 0 = no errors (warnings allowed), 1 = at least one error.
|
|
|
|
set -u
|
|
|
|
QUICK=0
|
|
for arg in "$@"; do
|
|
case "$arg" in
|
|
--quick) QUICK=1 ;;
|
|
--help|-h)
|
|
sed -n '2,7p' "$0" | sed 's/^# \{0,1\}//'
|
|
exit 0
|
|
;;
|
|
esac
|
|
done
|
|
|
|
if [ ! -d src ]; then
|
|
echo "ipal-audit: run from the project root (no ./src found)." >&2
|
|
exit 2
|
|
fi
|
|
|
|
ERRORS=0
|
|
WARNINGS=0
|
|
|
|
# report LEVEL "title" "rule" <<< "$matches"
|
|
report() {
|
|
local level="$1" title="$2" rule="$3" matches="$4"
|
|
[ -z "$matches" ] && return 0
|
|
local count
|
|
count=$(printf '%s\n' "$matches" | grep -c .)
|
|
if [ "$level" = ERROR ]; then ERRORS=$((ERRORS + count)); else WARNINGS=$((WARNINGS + count)); fi
|
|
printf '\n[%s] %s (%s) — %s\n' "$level" "$title" "$count" "$rule"
|
|
printf '%s\n' "$matches" | head -20 | sed 's/^/ /'
|
|
[ "$count" -gt 20 ] && printf ' … and %s more\n' "$((count - 20))"
|
|
}
|
|
|
|
g() { grep -rnE "$@" 2>/dev/null || true; }
|
|
# drop matches that sit inside a // or /* comment (keeps http:// URLs)
|
|
nc() { grep -vE "(^|[^:])//.*$1|/\*.*$1" || true; }
|
|
dirs() { for d in "$@"; do [ -d "$d" ] && printf '%s ' "$d"; done; }
|
|
|
|
BLOCKS=$(dirs src/blocks)
|
|
UI=$(dirs src/blocks src/components)
|
|
|
|
echo "ipal-audit — $(pwd)"
|
|
|
|
# --- Skill templates must not be compiled as project code ---
|
|
if [ -d .agents ] && [ -f tsconfig.json ]; then
|
|
report ERROR "tsconfig.json does not exclude .agents" "skill templates (.ts/.tsx) break tsc / next build — \"exclude\": [\"node_modules\", \".agents\"]" \
|
|
"$(grep -qE '"exclude"[^]]*\.agents' tsconfig.json || echo tsconfig.json)"
|
|
fi
|
|
|
|
# --- Sitemap: one route, look from the plugin (seo.md) ---
|
|
SM_TS=$(ls src/app/sitemap.ts 2>/dev/null)
|
|
SM_ROUTE=$(ls src/app/sitemap.xml/route.ts 2>/dev/null)
|
|
if [ -n "$SM_TS" ] && [ -n "$SM_ROUTE" ]; then
|
|
report ERROR "two sitemaps" "seo.md — keep src/app/sitemap.xml/route.ts (sitemapRoute), delete src/app/sitemap.ts" "$(printf '%s\n%s' "$SM_TS" "$SM_ROUTE")"
|
|
fi
|
|
report WARNING "project copy of the sitemap stylesheet" "seo.md — sitemapRoute serves the look from the plugin; delete it (and cssUrl)" \
|
|
"$(ls public/sitemap.css 2>/dev/null)"
|
|
|
|
# --- Architecture (AGENT.md §4) ---
|
|
report ERROR "middleware.ts exists" "§4.1 Next 16 uses proxy.ts only" \
|
|
"$(ls src/middleware.ts middleware.ts 2>/dev/null)"
|
|
|
|
report ERROR "<head> in app" "§4.2 no explicit <head> — metadata ends up in <body>" \
|
|
"$(g '<head[ >]' src/app --include=*.tsx | nc '<head')"
|
|
|
|
PAGES=$(find src/app -path '*\[\[...slug\]\]*' -name 'page.tsx' 2>/dev/null)
|
|
for p in $PAGES; do
|
|
grep -q 'revalidate' "$p" || report ERROR "no ISR" "§4.3 export const revalidate" "$p"
|
|
grep -q 'generateStaticParams' "$p" || report ERROR "no generateStaticParams" "§4.4 without it the route is dynamic and metadata lands in <body>" "$p"
|
|
report WARNING "searchParams in catch-all page" "§4.6 deoptimizes SSG/ISR — only for paginated archives" \
|
|
"$(grep -n 'searchParams' "$p" | nc 'searchParams' | sed "s|^|$p:|")"
|
|
done
|
|
|
|
for r in src/app/sitemap.ts src/app/manifest.ts src/app/llms.txt/route.ts src/app/sitemap.xml/route.ts src/app/api/health/route.ts; do
|
|
[ -f "$r" ] && ! grep -q "dynamic = 'force-dynamic'" "$r" && \
|
|
report ERROR "DB route without force-dynamic" "§4.7 build without DB will crash" "$r"
|
|
done
|
|
|
|
report ERROR "headers()/cookies() in blocks/components" "§4.6 forces dynamic rendering — pass locale via enhanceProps" \
|
|
"$( [ -n "$UI" ] && g "from 'next/headers'" $UI)"
|
|
|
|
report ERROR "headers()/cookies() in static page tree" "§4.6 SSG/ISR → 'Page changed from static to dynamic' — not-found: LocaleView (pages.md)" \
|
|
"$(g "from 'next/headers'" src/app --include=page.tsx --include=layout.tsx --include=not-found.tsx --include=template.tsx | grep -v '/api/\|(payload)')"
|
|
|
|
# --- Hardcoding & types (§2, §8) ---
|
|
report ERROR "hardcoded locale map / any / ts-ignore" "§2, §8" \
|
|
"$(g 'localizedRoutes|as any\b|@ts-ignore|: any\b' src --include=*.ts --include=*.tsx | grep -v '/payload-types.ts:')"
|
|
|
|
report ERROR "hardcoded locale list" "§2 languages come from i18n.config.ts" \
|
|
"$(g "\[ *'(pl|en|de|fr|es|it)' *, *'(pl|en|de|fr|es|it)'" src --include=*.ts --include=*.tsx | grep -v 'i18n.config.ts')"
|
|
|
|
# --- Sections (§6) ---
|
|
if [ -n "$BLOCKS" ]; then
|
|
report ERROR "forbidden field names" "§6.5 use links/link/media (linksField, linkField, upload)" \
|
|
"$(g "name: *'[a-zA-Z]*([cC]ta|[bB]utton|Url|Href|[pP]df|[iI]mage)[a-zA-Z]*'" $BLOCKS --include=config.ts)"
|
|
|
|
report ERROR "hardcoded href/src/file paths in blocks" "§2, §6 use CMSLink / Media" \
|
|
"$(g 'href=\{?["`]/|<img |/files/|/images/|\.pdf' $BLOCKS --include=*.tsx | nc '(href|<img|/files/|/images/|\.pdf)')"
|
|
|
|
report ERROR "raw <a>/<Link> in blocks" "§6.3 links from the panel render via CMSLink" \
|
|
"$(g '<(a|Link)[ >]' $BLOCKS --include=*.tsx)"
|
|
|
|
report ERROR "hardcoded text in blocks" "§2 every visible text comes from the panel (localized field)" \
|
|
"$(node "$(dirname "$0")/jsx-text.mjs" $BLOCKS 2>/dev/null)"
|
|
|
|
report WARNING "inline <svg> in blocks" "§6.10 icons via media upload or Icon map" \
|
|
"$(g '<svg[ >]' $BLOCKS --include=*.tsx)"
|
|
|
|
report WARNING "large section component (>120 lines)" "§6.4 split into subcomponents" \
|
|
"$(find $BLOCKS -name '*.tsx' -exec wc -l {} + 2>/dev/null | awk '$2 != "total" && $1 > 120 {print $2": "$1" lines"}')"
|
|
|
|
report ERROR "Component imported into block config" "§6.12 payload.config must not pull React components" \
|
|
"$(g "from '\./Component'|/Component'" $BLOCKS --include=config.ts)"
|
|
fi
|
|
|
|
if [ -d src/components ]; then
|
|
report WARNING "hardcoded text in components/layout" "§2 texts and a11y labels from the panel — keep only symbols/numbers in code" \
|
|
"$(node "$(dirname "$0")/jsx-text.mjs" src/components 2>/dev/null)"
|
|
fi
|
|
|
|
if [ -n "$UI" ]; then
|
|
report ERROR "hex colors in classes" "§6.11 use design tokens (bg-primary…)" \
|
|
"$(g '(bg|text|border|from|to|via|fill|stroke)-\[#' $UI --include=*.tsx)"
|
|
|
|
report ERROR "barrel index.ts" "§6.12 import files directly" \
|
|
"$(find $UI -name 'index.ts' 2>/dev/null)"
|
|
|
|
CLIENT=$(grep -rlE "^['\"]use client['\"]" $UI 2>/dev/null)
|
|
for c in $CLIENT; do
|
|
report ERROR "server import in client component" "§6.9 no payload / lib/content / server-only in 'use client'" \
|
|
"$(grep -nE "from '(payload|server-only|@/lib/content|@/payload\.config)'" "$c" | grep -v 'import type' | sed "s|^|$c:|")"
|
|
done
|
|
fi
|
|
|
|
# --- Collections (§5.3) ---
|
|
if [ -d src/collections ]; then
|
|
report ERROR "forbidden collection" "§5.3 settings/nav/footer are globals; FAQ/hero are blocks" \
|
|
"$(ls src/collections | grep -iE '^(settings|navigation|nav|footer|header|faq|hero|company|danefirmy)\.ts$')"
|
|
report WARNING "own users collection" "§5.3 ipalKit injects the auth collection — keep your own only to add fields (roles + 2FA still attach)" \
|
|
"$(ls src/collections | grep -iE '^(users|user)\.ts$')"
|
|
report WARNING "collections present — confirm each passed the §5.3 test" "minimum: Pages, Media" \
|
|
"$(ls src/collections | grep -viE '^(pages|media|users|user|settings|navigation|nav|footer|header|faq|hero|company|danefirmy)\.ts$')"
|
|
fi
|
|
|
|
# --- Editor panel clarity (§6.5a) ---
|
|
SCHEMA=$(dirs src/blocks src/collections src/globals src/fields)
|
|
if [ -n "$SCHEMA" ]; then
|
|
PANEL=$(node "$(dirname "$0")/panel-check.mjs" $SCHEMA)
|
|
while IFS= read -r rule; do
|
|
[ -z "$rule" ] && continue
|
|
level=${rule%%|*}; rest=${rule#*|}
|
|
report "$level" "panel: ${rest%%|*}" "§6.5a editor panel" "$(printf '%s\n' "$PANEL" | grep -F "$level|${rest%%|*}|" | cut -d'|' -f3-)"
|
|
done <<< "$(printf '%s\n' "$PANEL" | cut -d'|' -f1-2 | sort -u)"
|
|
fi
|
|
|
|
# --- Plugin duplicates (§1, §7) ---
|
|
report ERROR "own block renderer switch" "§7 use RenderBlocks + registry" \
|
|
"$(g 'switch *\(.*blockType' src --include=*.tsx --include=*.ts)"
|
|
report WARNING "files that usually duplicate the plugin" "§3 plugin has resolveRoute / getConfiguredLocales" \
|
|
"$(ls src/lib/pages.ts src/lib/locales.ts 2>/dev/null)"
|
|
report ERROR "project copy of link fields" "links.md — use buildLinkField / buildLinksField / resolveLinkHref from the plugin" \
|
|
"$(ls src/fields/link.ts src/lib/links.ts 2>/dev/null; g "from '@/fields/link'|from '@/lib/links'" src --include=*.ts --include=*.tsx)"
|
|
report ERROR "manual Lexical rendering" "§7 use RenderRichText" \
|
|
"$(g 'node\.type *===' src --include=*.tsx | nc 'node')"
|
|
HTML=$(node "$(dirname "$0")/html-check.mjs" src)
|
|
while IFS= read -r rule; do
|
|
[ -z "$rule" ] && continue
|
|
level=${rule%%|*}; title=${rule#*|}
|
|
report "$level" "$title" "§7 / seo.md" "$(printf '%s\n' "$HTML" | grep -F "$rule|" | cut -d'|' -f3-)"
|
|
done <<< "$(printf '%s\n' "$HTML" | cut -d'|' -f1-2 | sort -u)"
|
|
|
|
# --- Mandatory feature set (AGENT.md §0b) ---
|
|
# Every site wires all of these through the plugin. A missing one is an ERROR
|
|
# unless AGENTS.md records the client's decision: `ipal-audit-skip: mcp, llms-full — reason`.
|
|
SKIP=$(grep -hiE '^[-* ]*ipal-audit-skip:' AGENTS.md 2>/dev/null | sed 's/^[^:]*://; s/—.*//; s/ - .*//' | tr ',' ' ')
|
|
skipped() { for k in $SKIP; do [ "$k" = "$1" ] && return 0; done; return 1; }
|
|
# has <regex> <paths…> — true when any file under the paths matches
|
|
has() { local re="$1"; shift; grep -rqE "$re" "$@" 2>/dev/null; }
|
|
# need LEVEL key "what" "how" <regex> <paths…>
|
|
need() {
|
|
local level="$1" key="$2" what="$3" how="$4" re="$5"; shift 5
|
|
[ -n "$key" ] && skipped "$key" && return 0
|
|
has "$re" "$@" || report "$level" "missing: $what" "§0b — $how" "$what"
|
|
}
|
|
CFG=$(ls src/payload.config.ts payload.config.ts 2>/dev/null | head -1)
|
|
APP=$(dirs src/app)
|
|
|
|
if [ -n "$APP" ]; then
|
|
# SEO
|
|
need ERROR '' "page metadata" "generatePageMetadata (lib/content) in generateMetadata of the page routes" 'generatePageMetadata|createPageMetadata|createMetadataGenerator' src/app
|
|
need ERROR '' "sitemap.xml route" "src/app/sitemap.xml/route.ts → sitemapRoute" 'sitemapRoute|createSitemapRouteHandler|buildSitemapEntries|sitemap' src/app/sitemap.xml src/app/sitemap.ts
|
|
need ERROR '' "robots" "src/app/robots.ts → robots from lib/content" 'robots|buildRobots' src/app/robots.ts
|
|
need ERROR '' "manifest" "src/app/manifest.ts → createManifestHandler" 'createManifestHandler|buildManifest' src/app/manifest.ts
|
|
need ERROR '' "htmlLimitedBots" "next.config.ts — metadata must reach crawlers in <head>" 'htmlLimitedBots' next.config.ts next.config.mjs next.config.js
|
|
need ERROR jsonld "structured data" "<JsonLdGraph> with WebSite + Organization/LocalBusiness in [locale]/layout.tsx" 'JsonLdGraph' src
|
|
# GEO
|
|
need ERROR llms "llms.txt" "src/app/llms.txt/route.ts → createLlmsTxtRoute" 'createLlmsTxtRoute|buildLlmsTxt' src/app
|
|
need ERROR llms-full "llms-full.txt" "src/app/llms-full.txt/route.ts → createLlmsTxtRoute({ full: true })" 'full: *true' src/app/llms-full.txt
|
|
need ERROR markdown "Markdown route" "src/app/md/[locale]/[[...slug]]/route.ts → createMarkdownRenderer + markdownResponse" 'createMarkdownRenderer' src/app
|
|
need ERROR markdown "Markdown in proxy" "proxy.ts → createProxy(i18nConfig, { NextResponse, markdown: true }) — without it /md/… is redirected to /<locale>/md/…" 'markdown: *(true|['"'"'"])|prefersMarkdown' src/proxy.ts proxy.ts
|
|
need WARNING markdown "Markdown alternate link" "createContentHelpers({ markdownAlternate: true }) or markdownHref in metadata" 'markdownAlternate|markdownHref' src
|
|
need ERROR mcp "MCP server" "src/app/api/mcp/route.ts → createMcpRoute (public: AI browses the site)" 'createMcpRoute' src/app
|
|
need WARNING '' "AI summary field" "buildSummaryField() in Pages + summaryField: 'aiSummary' in llms/MCP routes" 'buildSummaryField' src
|
|
# Ops
|
|
need ERROR '' "health route" "src/app/api/health/route.ts → createHealthRoute" 'createHealthRoute' src/app
|
|
need ERROR '' "env validation" "src/instrumentation.ts → assertEnv(ipalEnvRules({...})) from @intecion/ipal-kit/env" 'assertEnv' src/instrumentation.ts instrumentation.ts
|
|
need ERROR '' "security headers" "next.config.ts → buildSecurityHeaders" 'buildSecurityHeaders' next.config.ts next.config.mjs next.config.js
|
|
# Consent, analytics, Turnstile (layout)
|
|
need ERROR '' "cookie consent" "ConsentProvider + CookieBanner + CookieButton in [locale]/layout.tsx" 'CookieBanner' src/app
|
|
need ERROR analytics "analytics" "<Analytics> inside ConsentProvider (IDs from the panel)" '<Analytics' src/app
|
|
need ERROR turnstile "Turnstile provider" "<TurnstileProvider siteKey> in [locale]/layout.tsx — always, it hides itself without keys" 'TurnstileProvider' src
|
|
need WARNING turnstile "getTurnstileConfig" "siteKey from getTurnstileConfig(payload) — off unless BOTH keys are set" 'getTurnstileConfig' src
|
|
need WARNING '' "MediaPreconnect" "<MediaPreconnect/> in the layout (R2 CDN preconnect from env)" 'MediaPreconnect' src/app
|
|
# Forms
|
|
need ERROR '' "form submission via the plugin" "server action sendForm → submitForm (ipal-form)" 'submitForm' src
|
|
fi
|
|
|
|
if [ -n "$CFG" ]; then
|
|
need ERROR '' "forms in ipalKit" "$CFG → ipalKit({ forms: {…} }) — forms are built in the panel" 'forms *:' "$CFG"
|
|
need ERROR '' "mailAdapter" "$CFG → email: mailAdapter() — form e-mails go through the panel transport" 'mailAdapter\(' "$CFG"
|
|
need ERROR r2 "R2 storage" "$CFG → buildR2Storage(['media'], { s3Storage }) — always wired, local disk only without R2_* env" 'buildR2Storage' "$CFG"
|
|
need ERROR r2 "@payloadcms/storage-s3" "pnpm add @payloadcms/storage-s3 (same version as payload)" '"@payloadcms/storage-s3"' package.json
|
|
need ERROR twofactor "2FA" "$CFG → twoFactor: { issuer, plugin: payloadTotp }" 'payloadTotp' "$CFG"
|
|
report WARNING "robots blocks AI bots" "§0b.8 — only with the client's decision in AGENTS.md" \
|
|
"$(skipped aibots || g "aiBots: *'(disallow|block-training)'" src --include=*.ts)"
|
|
fi
|
|
need WARNING r2 "R2 env in .env.example" ".env.example lists R2_BUCKET, R2_ENDPOINT, R2_ACCESS_KEY_ID, R2_SECRET_ACCESS_KEY, R2_PUBLIC_URL" 'R2_BUCKET' .env.example
|
|
need WARNING '' "IPAL_IP_HEADER in .env.example" "header the rate limit trusts, e.g. cf-connecting-ip (forms.md)" 'IPAL_IP_HEADER' .env.example
|
|
|
|
# Plugin replacements (§0b "Zakazane zamienniki")
|
|
report ERROR "own form / mail / captcha stack" "§0b — forms come from the panel builder, mail from mailAdapter, bot check from Turnstile" \
|
|
"$(g "from '(nodemailer|resend|@sendgrid/[a-z]+|react-hook-form|formik|react-google-recaptcha|@hcaptcha/react-hcaptcha|@aws-sdk/client-s3)'" src --include=*.ts --include=*.tsx)"
|
|
report ERROR "own form/mail API route" "§0b — use the sendForm server action → submitForm" \
|
|
"$(find src/app -type d \( -path '*api/contact*' -o -path '*api/send*' -o -path '*api/form*' -o -path '*api/mail*' -o -path '*api/newsletter*' \) 2>/dev/null)"
|
|
report ERROR "hand-written JSON-LD script" "§0b — <JsonLdGraph> escapes and wraps @graph" \
|
|
"$(g 'application/ld\+json' src --include=*.tsx | grep -v 'JsonLdGraph')"
|
|
report ERROR "static SEO files in public/" "§0b — sitemap, robots and llms are generated from the panel" \
|
|
"$(ls public/sitemap.xml public/robots.txt public/llms.txt public/llms-full.txt 2>/dev/null)"
|
|
report WARNING "<form> outside the form renderer" "§0b — forms render from the panel via FormRenderer (a search box is fine)" \
|
|
"$(g '<form[ >]' src --include=*.tsx | grep -v 'components/forms/')"
|
|
|
|
# --- Compile & build ---
|
|
if [ "$QUICK" -eq 0 ]; then
|
|
echo
|
|
echo "== pnpm generate:types && tsc --noEmit =="
|
|
if ! (pnpm -s generate:types >/dev/null && pnpm -s exec tsc --noEmit); then
|
|
ERRORS=$((ERRORS + 1)); echo "[ERROR] type check failed"
|
|
fi
|
|
echo
|
|
echo "== pnpm build =="
|
|
BUILD_LOG=$(mktemp)
|
|
if pnpm -s build >"$BUILD_LOG" 2>&1; then
|
|
DYN=$(grep -E '^[│├└ ]*ƒ .*\[locale\]' "$BUILD_LOG" || true)
|
|
report WARNING "page routes rendered dynamically (ƒ)" "§4 expected ● SSG — does the build see the DB?" "$DYN"
|
|
else
|
|
ERRORS=$((ERRORS + 1)); echo "[ERROR] build failed — last lines:"; tail -30 "$BUILD_LOG" | sed 's/^/ /'
|
|
fi
|
|
rm -f "$BUILD_LOG"
|
|
fi
|
|
|
|
echo
|
|
echo "ipal-audit: $ERRORS error(s), $WARNINGS warning(s)$( [ "$QUICK" -eq 1 ] && echo ' (quick: no tsc/build)')"
|
|
[ "$ERRORS" -eq 0 ]
|