mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-13 06:43:06 +00:00
Adds the `schema-dts` dependency to `package.json` for structured data. Updates the petition page to include JSON-LD schema markup for improved SEO and rich results. This involves extracting the first image from the Lexical editor or falling back to a global image for Open Graph and schema.org metadata.
39 lines
956 B
TypeScript
39 lines
956 B
TypeScript
import type { Media } from '@/payload-types'
|
|
|
|
type LexicalNode = {
|
|
type?: string
|
|
relationTo?: string
|
|
value?: unknown
|
|
children?: LexicalNode[]
|
|
[key: string]: unknown
|
|
}
|
|
|
|
type LexicalRoot = {
|
|
root: LexicalNode
|
|
[key: string]: unknown
|
|
}
|
|
|
|
const isImageMedia = (value: unknown): value is Media =>
|
|
typeof value === 'object' &&
|
|
value !== null &&
|
|
typeof (value as Media).url === 'string' &&
|
|
typeof (value as Media).mimeType === 'string' &&
|
|
(value as Media).mimeType!.startsWith('image/')
|
|
|
|
const findImage = (node: LexicalNode): Media | null => {
|
|
if (node.type === 'upload' && node.relationTo === 'media' && isImageMedia(node.value)) {
|
|
return node.value
|
|
}
|
|
|
|
if (Array.isArray(node.children)) {
|
|
for (const child of node.children) {
|
|
const found = findImage(child)
|
|
if (found) return found
|
|
}
|
|
}
|
|
|
|
return null
|
|
}
|
|
|
|
export const extractFirstImageFromLexical = (data: LexicalRoot): Media | null =>
|
|
findImage(data.root)
|