Replaced by an explicit list of forms only (ten exported names, runtime env names, project file names and marks, commands, skill names, the log prefix, the brand in prose). Package name, import paths, routes, CSS tokens, data attributes, custom keys, context flags, the cookie and kv keys are not touched. package.json keeps the five old bin names beside the five new ones. The old names stop working in this commit and come back as aliases in the next; docs follow. Co-Authored-By: Claude Fable 5.2 <[email protected]>
39 lines
1.5 KiB
TypeScript
39 lines
1.5 KiB
TypeScript
import type { FieldHook } from 'payload'
|
||
|
||
import { faviconProblems } from './faviconProblems.js'
|
||
|
||
/**
|
||
* 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 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.
|
||
*/
|
||
export const validateFaviconField: FieldHook = async ({ req, value }) => {
|
||
if (!value) {return value} // no favicon set → nothing to validate (optional field)
|
||
|
||
try {
|
||
const media = await req.payload.findByID({
|
||
id: typeof value === 'object' ? (value as { id: string }).id : value,
|
||
collection: 'media',
|
||
depth: 0,
|
||
})
|
||
|
||
for (const { height, key, width } of faviconProblems(media as { height?: number; mimeType?: string; width?: number })) {
|
||
req.payload.logger.warn(
|
||
key === 'faviconTooSmall'
|
||
? `[iapl] Favicon is ${width}×${height}px. Google requires ≥48×48 to display it in search results. Upload a larger square icon (96 or 192px).`
|
||
: `[iapl] 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.
|
||
}
|
||
|
||
return value
|
||
}
|