Admin link previews: site name, description, preview image, noindex; technology support credit
- adminMeta (default on, with or without whiteLabel): robots noindex/nofollow, title suffix "— <site> | Panel", og:site_name and en/pl description from Site settings, preview image GET /api/ipal/admin-og (next/og, from the logo or name, no external service) and icon GET /api/ipal/admin-icon - the site name sits in a process-wide store read through getters, so link previews stay current after a Site settings save and across config loads - agency option (default Intecion.com) feeds the credit, description and image; credit reads "Technology support: Intecion.com" (pl: Wsparcie technologiczne) - the project's own admin.meta keys always win; adminMeta: false / agency: false - dev: whiteLabel on; docs: white-label.md, AGENT.md, ipal-reference/setup/upgrade Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
6998b44431
commit
3c828d963d
@@ -34,6 +34,9 @@ export { shouldLoadGoogle } from './modules/analytics/shouldLoadGoogle.js'
|
||||
// Shared section fields (header: eyebrow/heading/intro, settings: anchor/background).
|
||||
export { buildSectionHeaderField, buildSectionSettingsField } from './modules/blocks/sectionFields.js'
|
||||
export type { SectionHeaderFieldOptions, SectionSettingsFieldOptions } from './modules/blocks/sectionFields.js'
|
||||
export { buildAdminImageEndpoints } from './modules/branding/adminImages.js'
|
||||
export { ADMIN_META_TEXTS, adminMetaForSite, buildAdminMeta, DEFAULT_AGENCY, syncAdminMeta } from './modules/branding/adminMeta.js'
|
||||
export type { AdminMetaOptions, AgencyOption, ResolvedAdminMeta } from './modules/branding/adminMeta.js'
|
||||
export {
|
||||
ACCEPT_ALL_CONSENT,
|
||||
buildConsentLogCollection,
|
||||
|
||||
@@ -3,12 +3,12 @@ import { defineTexts } from '../define.js'
|
||||
/** Admin component texts — settings. Placeholders use Payload's {{name}} syntax. */
|
||||
export const settingsTexts = defineTexts({
|
||||
en: {
|
||||
brandingCredit: 'Technology supported by Intecion.com',
|
||||
brandingCredit: 'Technology support: {{agency}}',
|
||||
faviconNotSquare: 'The icon is not square ({{width}}×{{height}} px), so it may be cropped in tabs and search results.',
|
||||
faviconTooSmall: 'The icon is {{width}}×{{height}} px. Google shows icons of at least 48×48 px; upload a larger one.',
|
||||
},
|
||||
pl: {
|
||||
brandingCredit: 'Technologię wspiera Intecion.com',
|
||||
brandingCredit: 'Wsparcie technologiczne: {{agency}}',
|
||||
faviconNotSquare: 'Ikona nie jest kwadratowa ({{width}}×{{height}} px), więc może być przycięta na kartach i w wynikach wyszukiwania.',
|
||||
faviconTooSmall: 'Ikona ma {{width}}×{{height}} px. Google pokazuje ikony od 48×48 px; wgraj większą.',
|
||||
},
|
||||
|
||||
@@ -116,7 +116,7 @@ export async function AdminIcon(props: BrandingProps = {}) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Discreet vendor credit: "Technology supported by Intecion.com". This is the
|
||||
* Discreet vendor credit: "Technology support: Intecion.com". This is the
|
||||
* PLUGIN VENDOR's credit (Intecion ships ipal-kit, the framework), not client
|
||||
* data — a sensible default here is fine and A0-safe. The client's own brand
|
||||
* still owns the logo/name; this is a small line stating who supports the tech.
|
||||
@@ -130,11 +130,20 @@ export async function AdminIcon(props: BrandingProps = {}) {
|
||||
* - 'login' → centered line below the login form
|
||||
*/
|
||||
export function IntecionCredit(
|
||||
props: { i18n?: { t: (key: never, vars?: Record<string, unknown>) => string }; text?: string; url?: string; variant?: 'login' | 'nav' } = {},
|
||||
props: {
|
||||
/** Agency name in the default text (`agency` option). Default "Intecion.com". */
|
||||
agency?: string
|
||||
i18n?: { t: (key: never, vars?: Record<string, unknown>) => string }
|
||||
text?: string
|
||||
url?: string
|
||||
variant?: 'login' | 'nav'
|
||||
} = {},
|
||||
) {
|
||||
const { i18n, url = 'https://intecion.com', variant = 'nav' } = props
|
||||
const { agency = 'Intecion.com', i18n, url = 'https://intecion.com', variant = 'nav' } = props
|
||||
// A project's own text wins; otherwise the plugin's text in the admin language.
|
||||
const text = props.text ?? (i18n ? ipalT(i18n.t, 'brandingCredit') : settingsTexts.en.brandingCredit)
|
||||
const text =
|
||||
props.text ??
|
||||
(i18n ? ipalT(i18n.t, 'brandingCredit', { agency }) : settingsTexts.en.brandingCredit.replace('{{agency}}', agency))
|
||||
const style =
|
||||
variant === 'login'
|
||||
? {
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
import type { Endpoint, PayloadRequest } from 'payload'
|
||||
|
||||
import type { AgencyOption, ResolvedAdminMeta } from './adminMeta.js'
|
||||
|
||||
import { ADMIN_ICON_PATH, ADMIN_META_TEXTS, ADMIN_OG_PATH } from './adminMeta.js'
|
||||
|
||||
/**
|
||||
* The panel's link-preview image (1200×630) and icon, drawn from SiteSettings:
|
||||
* logo (or the site name), "Administration panel" and a small technology
|
||||
* support line. Rendered on the server with next/og — no external service.
|
||||
* Public (link previews fetch without a session); they show only what the site
|
||||
* already shows publicly. Never throw: a missing logo or setting falls back to
|
||||
* the site name, then to initials.
|
||||
*/
|
||||
|
||||
type Fields = { iconField?: string; logoField?: string; nameField?: string; settingsSlug?: string }
|
||||
|
||||
type Branding = { icon: null | string; logo: null | string; name: string }
|
||||
|
||||
const CACHE = 'public, max-age=3600, s-maxage=3600'
|
||||
|
||||
async function loadBranding(req: PayloadRequest, f: Required<Fields>): Promise<Branding> {
|
||||
try {
|
||||
const locale = req.payload.config.localization ? req.payload.config.localization.defaultLocale : undefined
|
||||
const s = (await req.payload.findGlobal({ slug: f.settingsSlug as never, depth: 1, ...(locale ? { locale: locale as never } : {}), req })) as Record<string, unknown>
|
||||
const url = (v: unknown) => (v && typeof v === 'object' && typeof (v as { url?: unknown }).url === 'string' ? (v as { url: string }).url : null)
|
||||
const name = typeof s[f.nameField] === 'string' ? (s[f.nameField] as string).trim() : ''
|
||||
return { name, icon: url(s[f.iconField]), logo: url(s[f.logoField]) }
|
||||
} catch {
|
||||
return { name: '', icon: null, logo: null }
|
||||
}
|
||||
}
|
||||
|
||||
/** Absolute URL of an upload, resolved against the request (uploads are often relative). */
|
||||
const absolute = (url: string, req: PayloadRequest) => new URL(url, req.url ?? `http://localhost`).toString()
|
||||
|
||||
/** The image as a data URI, so the renderer needs no network access of its own. */
|
||||
async function inline(url: null | string, req: PayloadRequest): Promise<null | string> {
|
||||
if (!url) {return null}
|
||||
try {
|
||||
const res = await fetch(absolute(url, req))
|
||||
if (!res.ok) {return null}
|
||||
const type = res.headers.get('content-type') ?? 'image/png'
|
||||
// The renderer can't draw WebP/AVIF; the site name is shown instead.
|
||||
if (!/png|jpe?g|gif|svg/.test(type)) {return null}
|
||||
return `data:${type};base64,${Buffer.from(await res.arrayBuffer()).toString('base64')}`
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
// Loaded on first use, so the Payload CLI (which reads this config outside Next) never loads it;
|
||||
// '.js' because next has no exports map (plain Node ESM can't resolve 'next/og').
|
||||
const imageResponse = async () => (await import('next/og.js')).ImageResponse
|
||||
|
||||
const initials = (name: string) =>
|
||||
name
|
||||
.split(/\s+/)
|
||||
.filter(Boolean)
|
||||
.slice(0, 2)
|
||||
.map((w) => w[0].toUpperCase())
|
||||
.join('') || 'A'
|
||||
|
||||
export function buildAdminImageEndpoints(resolved: ResolvedAdminMeta, fields: Fields = {}): Endpoint[] {
|
||||
const f: Required<Fields> = {
|
||||
iconField: fields.iconField ?? 'favicon',
|
||||
logoField: fields.logoField ?? 'logo',
|
||||
nameField: fields.nameField ?? 'siteName',
|
||||
settingsSlug: fields.settingsSlug ?? 'site-settings',
|
||||
}
|
||||
const texts = ADMIN_META_TEXTS[resolved.language]
|
||||
const agency: AgencyOption | false = resolved.agency
|
||||
|
||||
const og: Endpoint = {
|
||||
handler: async (req) => {
|
||||
const brand = await loadBranding(req, f)
|
||||
const logo = await inline(brand.logo, req)
|
||||
const ImageResponse = await imageResponse()
|
||||
const image = new ImageResponse(
|
||||
(
|
||||
<div style={{ alignItems: 'center', background: '#ffffff', color: '#111111', display: 'flex', flexDirection: 'column', height: '100%', justifyContent: 'center', padding: 80, width: '100%' }}>
|
||||
{logo ? (
|
||||
// Rendered by next/og, not the browser.
|
||||
<img alt="" src={logo} style={{ maxHeight: 220, maxWidth: 760, objectFit: 'contain' }} />
|
||||
) : (
|
||||
<div style={{ display: 'flex', fontSize: 84, fontWeight: 700, textAlign: 'center' }}>{brand.name || texts.imageTitle}</div>
|
||||
)}
|
||||
<div style={{ display: 'flex', fontSize: 40, marginTop: 48, opacity: 0.75 }}>{texts.imageTitle}</div>
|
||||
{agency ? (
|
||||
<div style={{ bottom: 40, display: 'flex', fontSize: 24, opacity: 0.5, position: 'absolute' }}>
|
||||
{texts.imageLine.replace('{agency}', agency.name)}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
),
|
||||
{ headers: { 'Cache-Control': CACHE }, height: 630, width: 1200 },
|
||||
)
|
||||
return image
|
||||
},
|
||||
method: 'get',
|
||||
path: ADMIN_OG_PATH,
|
||||
}
|
||||
|
||||
const icon: Endpoint = {
|
||||
handler: async (req) => {
|
||||
const brand = await loadBranding(req, f)
|
||||
if (brand.icon) {
|
||||
return new Response(null, { headers: { 'Cache-Control': CACHE, Location: absolute(brand.icon, req) }, status: 302 })
|
||||
}
|
||||
const ImageResponse = await imageResponse()
|
||||
return new ImageResponse(
|
||||
(
|
||||
<div style={{ alignItems: 'center', background: '#111111', borderRadius: 12, color: '#ffffff', display: 'flex', fontSize: 30, fontWeight: 700, height: '100%', justifyContent: 'center', width: '100%' }}>
|
||||
{initials(brand.name)}
|
||||
</div>
|
||||
),
|
||||
{ headers: { 'Cache-Control': CACHE }, height: 64, width: 64 },
|
||||
)
|
||||
},
|
||||
method: 'get',
|
||||
path: ADMIN_ICON_PATH,
|
||||
}
|
||||
|
||||
return [og, icon]
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
import type { Config, Payload } from 'payload'
|
||||
|
||||
import type { AdminText } from '../admin-i18n/index.js'
|
||||
|
||||
/**
|
||||
* Admin panel <head> for link previews and search engines: what Slack,
|
||||
* Messenger and similar show for a pasted /admin link, and noindex for robots.
|
||||
*
|
||||
* Payload builds every admin page's metadata from `config.admin.meta` on each
|
||||
* request, so the plugin
|
||||
* - sets static defaults at config time (robots, preview image and icon
|
||||
* pointing at the plugin's own endpoints), and
|
||||
* - fills the site-dependent parts (title suffix, description, siteName)
|
||||
* from SiteSettings on start and after every Site settings save.
|
||||
* Next may load the config more than once per process (dev recompiles, route
|
||||
* bundles), so the site name lives in a process-wide store and the meta reads
|
||||
* it through getters: `openGraph` keeps its object reference through Payload's
|
||||
* sanitize, so its getters run on every request; the top-level `titleSuffix`
|
||||
* and `description` are read when a config is loaded, and the live config is
|
||||
* updated in place as well.
|
||||
* A key the project set in its own `admin.meta` is never touched.
|
||||
*/
|
||||
|
||||
/** Who supports the technology: named in the credit, the description and the preview image. */
|
||||
export type AgencyOption = { name: string; url: string }
|
||||
|
||||
export const DEFAULT_AGENCY: AgencyOption = { name: 'Intecion.com', url: 'https://intecion.com' }
|
||||
|
||||
export type AdminMetaOptions = {
|
||||
/** Description for link previews; `{site}` and `{agency}` are replaced. `false` = Payload's own. */
|
||||
description?: AdminText | false | string
|
||||
/** Favicon of the panel from SiteSettings (`/api/ipal/admin-icon`). `false` = Payload's own. */
|
||||
icons?: boolean
|
||||
/** Preview image: generated from the site's logo (`/api/ipal/admin-og`), your own URL, or `false` = Payload's own. */
|
||||
image?: false | string
|
||||
/** Language of the description and suffix. Default: the site's default locale when it is `pl`, else `en`. */
|
||||
language?: 'en' | 'pl'
|
||||
/** Robots meta. Default noindex, nofollow. `false` = none. */
|
||||
robots?: { follow?: boolean; index?: boolean } | false
|
||||
/** Browser-tab suffix; `{site}` is replaced. Default "— {site} | Panel". `false` = none. */
|
||||
titleSuffix?: false | string
|
||||
}
|
||||
|
||||
export const ADMIN_META_TEXTS = {
|
||||
en: {
|
||||
description: 'Administration panel of {site}. Built on Payload CMS, technology support: {agency}.',
|
||||
descriptionNoAgency: 'Administration panel of {site}. Built on Payload CMS.',
|
||||
imageLine: 'Technology support: {agency}',
|
||||
imageTitle: 'Administration panel',
|
||||
titleSuffix: '— {site} | Panel',
|
||||
titleSuffixNoSite: '| Panel',
|
||||
},
|
||||
pl: {
|
||||
description: 'Panel administracyjny witryny {site}. Zbudowany na Payload CMS, wsparcie technologiczne: {agency}.',
|
||||
descriptionNoAgency: 'Panel administracyjny witryny {site}. Zbudowany na Payload CMS.',
|
||||
imageLine: 'Wsparcie technologiczne: {agency}',
|
||||
imageTitle: 'Panel administracyjny',
|
||||
titleSuffix: '— {site} | Panel',
|
||||
titleSuffixNoSite: '| Panel',
|
||||
},
|
||||
}
|
||||
|
||||
type Store = { site?: string }
|
||||
const STORE_KEY = Symbol.for('ipal.adminMeta')
|
||||
/** Process-wide: the site name the meta getters read. */
|
||||
export const adminMetaStore = (): Store => {
|
||||
const g = globalThis as unknown as Record<symbol, Store | undefined>
|
||||
return (g[STORE_KEY] ??= {})
|
||||
}
|
||||
|
||||
export const ADMIN_OG_PATH = '/ipal/admin-og'
|
||||
export const ADMIN_ICON_PATH = '/ipal/admin-icon'
|
||||
|
||||
type Meta = NonNullable<NonNullable<Config['admin']>['meta']>
|
||||
|
||||
const fill = (template: string, site: string, agency: AgencyOption | false) =>
|
||||
template.replaceAll('{site}', site).replaceAll('{agency}', agency ? agency.name : '').trim()
|
||||
|
||||
export type ResolvedAdminMeta = {
|
||||
agency: AgencyOption | false
|
||||
language: 'en' | 'pl'
|
||||
options: AdminMetaOptions
|
||||
/** Keys the project set itself in admin.meta — never overwritten. */
|
||||
own: { description: boolean; icons: boolean; images: boolean; robots: boolean; siteName: boolean; titleSuffix: boolean }
|
||||
}
|
||||
|
||||
/** Static defaults at config time. Returns the new meta and what the runtime sync may fill. */
|
||||
export function buildAdminMeta({
|
||||
agency,
|
||||
apiRoute = '/api',
|
||||
defaultLocale,
|
||||
meta = {},
|
||||
options = {},
|
||||
}: {
|
||||
agency: AgencyOption | false
|
||||
apiRoute?: string
|
||||
defaultLocale?: string
|
||||
meta?: Meta
|
||||
options?: AdminMetaOptions
|
||||
}): { meta: Meta; resolved: ResolvedAdminMeta } {
|
||||
const og = (meta.openGraph ?? {}) as Record<string, unknown>
|
||||
const own = {
|
||||
description: meta.description !== undefined || og.description !== undefined,
|
||||
icons: meta.icons !== undefined,
|
||||
images: og.images !== undefined,
|
||||
robots: meta.robots !== undefined,
|
||||
siteName: og.siteName !== undefined,
|
||||
titleSuffix: meta.titleSuffix !== undefined,
|
||||
}
|
||||
const language = options.language ?? (defaultLocale?.toLowerCase().startsWith('pl') ? 'pl' : 'en')
|
||||
const api = apiRoute.replace(/\/$/, '')
|
||||
const next: Meta = { ...meta }
|
||||
const openGraph: Record<string, unknown> = { ...og }
|
||||
const resolved: ResolvedAdminMeta = { agency, language, options, own }
|
||||
const current = () => {
|
||||
const site = adminMetaStore().site
|
||||
return site ? adminMetaForSite(site, resolved) : null
|
||||
}
|
||||
const getter = (target: object, key: string, read: () => unknown) =>
|
||||
Object.defineProperty(target, key, { configurable: true, enumerable: true, get: read })
|
||||
|
||||
if (!own.titleSuffix && options.titleSuffix !== false) {
|
||||
getter(next, 'titleSuffix', () => current()?.titleSuffix ?? ADMIN_META_TEXTS[language].titleSuffixNoSite)
|
||||
}
|
||||
if (!own.description && options.description !== false) {
|
||||
getter(next, 'description', () => current()?.description)
|
||||
getter(openGraph, 'description', () => current()?.description)
|
||||
}
|
||||
if (!own.siteName) {getter(openGraph, 'siteName', () => current()?.siteName)}
|
||||
|
||||
if (!own.robots && options.robots !== false) {
|
||||
next.robots = { follow: false, index: false, ...(options.robots ?? {}) } as Meta['robots']
|
||||
}
|
||||
if (!own.images && options.image !== false) {
|
||||
openGraph.images = [{ height: 630, url: options.image ?? `${api}${ADMIN_OG_PATH}`, width: 1200 }]
|
||||
}
|
||||
if (!own.icons && options.icons !== false) {
|
||||
next.icons = [{ rel: 'icon', url: `${api}${ADMIN_ICON_PATH}` }] as Meta['icons']
|
||||
}
|
||||
if (Object.keys(openGraph).length) {next.openGraph = openGraph as Meta['openGraph']}
|
||||
return { meta: next, resolved }
|
||||
}
|
||||
|
||||
/** Site-dependent parts of the meta for a given site name. */
|
||||
export function adminMetaForSite(site: string, { agency, language, options }: ResolvedAdminMeta) {
|
||||
const texts = ADMIN_META_TEXTS[language]
|
||||
const description =
|
||||
options.description === false
|
||||
? undefined
|
||||
: fill(
|
||||
typeof options.description === 'string'
|
||||
? options.description
|
||||
: options.description
|
||||
? options.description[language]
|
||||
: agency
|
||||
? texts.description
|
||||
: texts.descriptionNoAgency,
|
||||
site,
|
||||
agency,
|
||||
)
|
||||
const titleSuffix = options.titleSuffix === false ? undefined : fill(options.titleSuffix ?? texts.titleSuffix, site, agency)
|
||||
return { description, siteName: site, titleSuffix }
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the site-dependent parts into the live config Payload reads for every
|
||||
* admin page. Never throws; skips keys the project set itself.
|
||||
*/
|
||||
export async function syncAdminMeta(
|
||||
payload: Payload,
|
||||
resolved: ResolvedAdminMeta,
|
||||
{ nameField = 'siteName', settingsSlug = 'site-settings' }: { nameField?: string; settingsSlug?: string } = {},
|
||||
): Promise<void> {
|
||||
try {
|
||||
const locale = payload.config.localization ? payload.config.localization.defaultLocale : undefined
|
||||
const settings = (await payload.findGlobal({ slug: settingsSlug as never, depth: 0, ...(locale ? { locale: locale as never } : {}) })) as Record<string, unknown>
|
||||
const raw = settings[nameField]
|
||||
const site = typeof raw === 'string' ? raw.trim() : ''
|
||||
if (!site) {return}
|
||||
adminMetaStore().site = site
|
||||
// The live config was sanitized before this ran: its top-level values are plain copies.
|
||||
const { description, titleSuffix } = adminMetaForSite(site, resolved)
|
||||
const meta = payload.config.admin.meta as (Meta & Record<string, unknown>) | undefined
|
||||
if (!meta) {return}
|
||||
if (!resolved.own.description && resolved.options.description !== false && description) {meta.description = description}
|
||||
if (!resolved.own.titleSuffix && resolved.options.titleSuffix !== false && titleSuffix) {meta.titleSuffix = titleSuffix}
|
||||
} catch (error) {
|
||||
payload.logger.warn({ err: error, msg: '[ipal] admin meta: could not read Site settings; Payload defaults stay.' })
|
||||
}
|
||||
}
|
||||
+61
-4
@@ -1,5 +1,6 @@
|
||||
import type { Config, Plugin } from 'payload'
|
||||
|
||||
import type { ResolvedAdminMeta } from './modules/branding/adminMeta.js'
|
||||
import type { IpalOptions, TotpPluginFactory } from './types.js'
|
||||
|
||||
import { buildCookieSettings } from './globals/CookieSettings/index.js'
|
||||
@@ -10,6 +11,8 @@ import { buildSiteIntegrations } from './globals/SiteIntegrations/index.js'
|
||||
import { buildSiteSettings } from './globals/SiteSettings/index.js'
|
||||
import { adminOnly, adminOrSelf, injectRoles } from './modules/access/index.js'
|
||||
import { applyAdminI18n } from './modules/admin-i18n/apply.js'
|
||||
import { buildAdminImageEndpoints } from './modules/branding/adminImages.js'
|
||||
import { buildAdminMeta, DEFAULT_AGENCY, syncAdminMeta } from './modules/branding/adminMeta.js'
|
||||
import { buildConsentLogCollection, buildConsentLogEndpoint } from './modules/consent/consentLog.js'
|
||||
import { addCookieScannerTabs } from './modules/consent/scanner/adminTabs.js'
|
||||
import { buildCookieApprovalEndpoints, COOKIE_APPROVAL_VIEW_PATH } from './modules/consent/scanner/approval.js'
|
||||
@@ -222,6 +225,8 @@ export const ipalKit = (options: IpalOptions): Plugin => {
|
||||
}
|
||||
}
|
||||
|
||||
const agency = options.agency === undefined ? DEFAULT_AGENCY : options.agency
|
||||
|
||||
// --- white-label admin branding ---
|
||||
// Inject admin.components.graphics.Logo/Icon pointing at the plugin's
|
||||
// /admin export. The components read SiteSettings at render, so each client
|
||||
@@ -237,14 +242,16 @@ export const ipalKit = (options: IpalOptions): Plugin => {
|
||||
|
||||
// Vendor credit ("Technology by Intecion.com") under the nav — on by
|
||||
// default, hidden with credit:false, text/url overridable.
|
||||
const creditOn = wl.credit !== false
|
||||
const creditProps =
|
||||
wl.credit && typeof wl.credit === 'object'
|
||||
const creditOn = wl.credit !== false && agency !== false
|
||||
const creditProps = {
|
||||
...(agency ? { agency: agency.name, url: agency.url } : {}),
|
||||
...(wl.credit && typeof wl.credit === 'object'
|
||||
? {
|
||||
...(wl.credit.text ? { text: wl.credit.text } : {}),
|
||||
...(wl.credit.url ? { url: wl.credit.url } : {}),
|
||||
}
|
||||
: {}
|
||||
: {}),
|
||||
}
|
||||
|
||||
config.admin = {
|
||||
...(config.admin ?? {}),
|
||||
@@ -280,6 +287,33 @@ export const ipalKit = (options: IpalOptions): Plugin => {
|
||||
}
|
||||
}
|
||||
|
||||
// --- admin <head>: link previews + noindex (default on) ---
|
||||
// Static parts now; the site name parts come from Site settings in onInit
|
||||
// and after every save (syncAdminMeta). The project's own admin.meta keys win.
|
||||
let adminMeta: null | ResolvedAdminMeta = null
|
||||
const brandFields = options.whiteLabel && options.whiteLabel !== true ? options.whiteLabel : {}
|
||||
const settingsSlug = brandFields.settingsSlug ?? 'site-settings'
|
||||
if (options.adminMeta !== false) {
|
||||
const built = buildAdminMeta({
|
||||
agency,
|
||||
apiRoute: config.routes?.api,
|
||||
defaultLocale: options.i18n.defaultLocale,
|
||||
meta: config.admin?.meta,
|
||||
options: options.adminMeta ?? {},
|
||||
})
|
||||
adminMeta = built.resolved
|
||||
config.admin = { ...(config.admin ?? {}), meta: built.meta }
|
||||
config.endpoints = [
|
||||
...(config.endpoints ?? []),
|
||||
...buildAdminImageEndpoints(built.resolved, {
|
||||
iconField: brandFields.iconField,
|
||||
logoField: brandFields.logoField,
|
||||
nameField: brandFields.nameField,
|
||||
settingsSlug,
|
||||
}),
|
||||
]
|
||||
}
|
||||
|
||||
// --- i18n ---
|
||||
config.localization = buildLocalizationConfig(options.i18n)
|
||||
// Admin languages (en + pl unless the project set its own) and the plugin's texts.
|
||||
@@ -349,6 +383,28 @@ export const ipalKit = (options: IpalOptions): Plugin => {
|
||||
// The project's globalOverrides win (access, admin, hooks merged; a function = full control).
|
||||
config.globals = [...(config.globals ?? []), ...applyGlobalOverrides(withRevalidate, options.globalOverrides)]
|
||||
|
||||
// A new site name refreshes the panel's link preview texts.
|
||||
if (adminMeta) {
|
||||
const resolved = adminMeta
|
||||
config.globals = config.globals.map((g) =>
|
||||
g.slug === settingsSlug
|
||||
? {
|
||||
...g,
|
||||
hooks: {
|
||||
...g.hooks,
|
||||
afterChange: [
|
||||
...(g.hooks?.afterChange ?? []),
|
||||
async ({ doc, req }) => {
|
||||
await syncAdminMeta(req.payload, resolved, { nameField: brandFields.nameField, settingsSlug })
|
||||
return doc
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
: g,
|
||||
)
|
||||
}
|
||||
|
||||
config.endpoints = [...(config.endpoints ?? []), testEmailEndpoint]
|
||||
|
||||
// --- consent log: proof of consent (opt-in) ---
|
||||
@@ -502,6 +558,7 @@ export const ipalKit = (options: IpalOptions): Plugin => {
|
||||
config.onInit = async (payload) => {
|
||||
if (incomingOnInit) {await incomingOnInit(payload)}
|
||||
await migrateCookieSettingsSaveButton(payload)
|
||||
if (adminMeta) {await syncAdminMeta(payload, adminMeta, { nameField: brandFields.nameField, settingsSlug })}
|
||||
payload.logger.info('[ipal] Plugin initialized.')
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ export type TotpPluginFactory = (options: {
|
||||
}) => Plugin
|
||||
import type { GlobalOverrides } from './globals/overrides.js'
|
||||
import type { AccessOption } from './modules/access/types.js'
|
||||
import type { AdminMetaOptions, AgencyOption } from './modules/branding/adminMeta.js'
|
||||
import type { ConsentLogOptions } from './modules/consent/consentLog.js'
|
||||
import type { CookieScannerOptions } from './modules/consent/scanner/types.js'
|
||||
import type { ContentOption } from './modules/content/types.js'
|
||||
@@ -35,6 +36,15 @@ export type IpalOptions = {
|
||||
*/
|
||||
access?: AccessOption
|
||||
|
||||
/**
|
||||
* Admin panel <head> for link previews and search engines (default on):
|
||||
* noindex/nofollow, title suffix "— <site> | Panel", siteName and a short
|
||||
* description from Site settings, a preview image drawn from the site's logo
|
||||
* (GET /api/ipal/admin-og) and the site's favicon (GET /api/ipal/admin-icon).
|
||||
* Keys the project sets in its own `admin.meta` always win. `false` = Payload's defaults.
|
||||
*/
|
||||
adminMeta?: AdminMetaOptions | false
|
||||
|
||||
/**
|
||||
* Custom admin panel route, e.g. '/its' instead of the default '/admin'.
|
||||
* The plugin sets config.routes.admin. IMPORTANT: this alone isn't enough —
|
||||
@@ -47,6 +57,13 @@ export type IpalOptions = {
|
||||
*/
|
||||
adminRoute?: string
|
||||
|
||||
/**
|
||||
* Who supports the technology, named in the admin credit, the panel's link
|
||||
* description and its preview image. Default `{ name: 'Intecion.com', url: 'https://intecion.com' }`.
|
||||
* `false` = no agency anywhere.
|
||||
*/
|
||||
agency?: AgencyOption | false
|
||||
|
||||
/** Internationalization — locales, default locale, fallback behavior */
|
||||
/**
|
||||
* Consent log (proof of consent, GDPR Art. 7(1)): adds the `consent-records`
|
||||
|
||||
Reference in New Issue
Block a user