Admin follow-ups: localised stats tab title, scanner names, close label, favicon hint
- Statistics view: the browser-tab title follows the admin language.
Payload's custom-view meta.title is one plain string and its custom-view
metadata ignores i18n, so the view renders <DocumentTitle> (/admin) with the
translated title; it re-applies the title while the view is open because
Next streams the English metadata in after hydration. adminDocumentTitle()
adds admin.meta.titleSuffix the way Payload does.
- Cookie scanner: CookieIntegration.label may be { en, pl, ... }. The built-in
names without a product name come from the shared admin texts
(cookieIntegration*, cookieSourceProject); the scan endpoint answers in the
request's admin language and stored source names use the scanning editor's.
- Maintenance notice: getConstructionMode(locale) returns `locale`; the "x"
close button gets a screen-reader name "Close" / "Zamknij" (locale and
closeLabel props; constructionCloseLabel exported).
- Favicon: FaviconCheck (/admin, afterInput on Site settings -> Site icon)
warns in the admin language when the image is under 48x48 or not square,
without blocking the save; validateFaviconField shares faviconProblems().
- Docs, AGENT.md and skills: the above, plus Next.js 16.4.1 or later as the
minimum safe version (AGENT.md 4.11, ipal-setup, ipal-upgrade).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
6f32ea4cdb
commit
546806fe39
@@ -0,0 +1,78 @@
|
||||
'use client'
|
||||
import { useConfig, useFormFields, useTranslation } from '@payloadcms/ui'
|
||||
import { useEffect, useState } from 'react'
|
||||
|
||||
import { ipalT } from '../admin-i18n/t.js'
|
||||
import { faviconProblems } from './faviconProblems.js'
|
||||
|
||||
export type FaviconCheckProps = {
|
||||
/** Upload field holding the icon. Default: the field this sits under, else 'favicon'. */
|
||||
fieldPath?: string
|
||||
/** Upload collection of the icon. Default 'media'. */
|
||||
mediaSlug?: string
|
||||
/** Set by Payload for a field component. */
|
||||
path?: string
|
||||
}
|
||||
|
||||
const id = (value: unknown) =>
|
||||
typeof value === 'object' && value !== null ? (value as { id?: number | string }).id : (value as number | string | undefined)
|
||||
|
||||
/**
|
||||
* Hint under the site icon in Site settings: Google shows a favicon only when it
|
||||
* is at least 48×48 px, and a non-square one gets cropped. Reads the chosen
|
||||
* image's size and warns; saving is never blocked. SVG icons pass.
|
||||
*/
|
||||
export function FaviconCheck({ fieldPath, mediaSlug = 'media', path }: FaviconCheckProps) {
|
||||
const value = useFormFields(([f]) => f[fieldPath ?? path ?? 'favicon']?.value)
|
||||
const mediaId = id(value)
|
||||
const {
|
||||
config: {
|
||||
routes: { api },
|
||||
serverURL,
|
||||
},
|
||||
} = useConfig()
|
||||
const { t } = useTranslation()
|
||||
const [problems, setProblems] = useState<string[]>([])
|
||||
|
||||
useEffect(() => {
|
||||
if (mediaId === undefined || mediaId === null || mediaId === '') {
|
||||
setProblems([])
|
||||
return
|
||||
}
|
||||
const controller = new AbortController()
|
||||
void (async () => {
|
||||
try {
|
||||
const res = await fetch(`${serverURL ?? ''}${api}/${mediaSlug}/${encodeURIComponent(String(mediaId))}?depth=0`, {
|
||||
credentials: 'include',
|
||||
signal: controller.signal,
|
||||
})
|
||||
const media = res.ok ? ((await res.json()) as { height?: number; mimeType?: string; width?: number }) : null
|
||||
const found = media ? faviconProblems(media) : []
|
||||
setProblems(found.map((p) => ipalT(t, p.key, { height: p.height, width: p.width })))
|
||||
} catch {
|
||||
// aborted or offline — a hint is not worth an error
|
||||
}
|
||||
})()
|
||||
return () => controller.abort()
|
||||
}, [api, mediaId, mediaSlug, serverURL, t])
|
||||
|
||||
if (!problems.length) {return null}
|
||||
|
||||
return (
|
||||
<div
|
||||
role="status"
|
||||
style={{
|
||||
background: 'var(--theme-warning-50, rgba(255, 178, 36, 0.1))',
|
||||
border: '1px solid var(--theme-warning-400, #ffb224)',
|
||||
borderRadius: 4,
|
||||
fontSize: '0.85rem',
|
||||
marginTop: '0.5rem',
|
||||
padding: '0.6rem 0.9rem',
|
||||
}}
|
||||
>
|
||||
{problems.map((text) => (
|
||||
<p key={text} style={{ margin: 0 }}>{text}</p>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/** Smallest favicon Google shows in search results. */
|
||||
export const FAVICON_MIN_SIZE = 48
|
||||
|
||||
export type FaviconProblem = { height: number; key: 'faviconNotSquare' | 'faviconTooSmall'; width: number }
|
||||
|
||||
/**
|
||||
* What is wrong with a favicon for Google: under 48×48 px, or not square.
|
||||
* SVG scales, and an image without known dimensions is not judged.
|
||||
*/
|
||||
export function faviconProblems(media: { height?: null | number; mimeType?: null | string; width?: null | number }): FaviconProblem[] {
|
||||
const { height, mimeType, width } = media
|
||||
if (mimeType === 'image/svg+xml' || typeof width !== 'number' || typeof height !== 'number') {return []}
|
||||
const out: FaviconProblem[] = []
|
||||
if (width < FAVICON_MIN_SIZE || height < FAVICON_MIN_SIZE) {out.push({ height, key: 'faviconTooSmall', width })}
|
||||
if (width !== height) {out.push({ height, key: 'faviconNotSquare', width })}
|
||||
return out
|
||||
}
|
||||
@@ -28,6 +28,8 @@ export { composeTitle } from './composeTitle.js'
|
||||
export type { TitleOrder } from './composeTitle.js'
|
||||
export { createMetadataGenerator } from './createMetadataGenerator.js'
|
||||
export { createPageMetadata } from './createPageMetadata.js'
|
||||
export { FAVICON_MIN_SIZE, faviconProblems } from './faviconProblems.js'
|
||||
export type { FaviconProblem } from './faviconProblems.js'
|
||||
export { formatOpeningHours } from './formatOpeningHours.js'
|
||||
export { buildHreflangAlternates } from './hreflang.js'
|
||||
export {
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import type { FieldHook } from 'payload'
|
||||
|
||||
import { faviconProblems } from './faviconProblems.js'
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* Server-side check of the favicon upload: Google rejects favicons under 48×48,
|
||||
* and a non-square icon gets cropped. Logs a warning on save; it never blocks
|
||||
* the save. Editors see the same check under the field (`FaviconCheck`, /admin).
|
||||
*
|
||||
* 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.
|
||||
* Attach as a beforeValidate hook on your own favicon field; the plugin wires it
|
||||
* on Site settings itself.
|
||||
*
|
||||
* 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.
|
||||
@@ -23,26 +23,12 @@ export const validateFaviconField: FieldHook = async ({ req, value }) => {
|
||||
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.`,
|
||||
)
|
||||
}
|
||||
for (const { height, key, width } of faviconProblems(media as { height?: number; mimeType?: string; width?: number })) {
|
||||
req.payload.logger.warn(
|
||||
key === 'faviconTooSmall'
|
||||
? `[ipal] Favicon is ${width}×${height}px. Google requires ≥48×48 to display it in search results. Upload a larger square icon (96 or 192px).`
|
||||
: `[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.
|
||||
|
||||
Reference in New Issue
Block a user