提交正式官网
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import type { FaqAnswerBlock, FaqItem } from '~/data/faq-content'
|
||||
import type { JsonLdNode } from '~/utils/seo'
|
||||
|
||||
function partText(part: { kind: string; value?: string; label?: string }): string {
|
||||
if (part.kind === 'text') return part.value ?? ''
|
||||
if (part.kind === 'link') return part.label ?? ''
|
||||
return ''
|
||||
}
|
||||
|
||||
function blockPlainText(block: FaqAnswerBlock): string {
|
||||
if (block.type === 'paragraph') {
|
||||
return block.parts.map(partText).join('')
|
||||
}
|
||||
|
||||
return block.items
|
||||
.map((row) => row.map(partText).join(''))
|
||||
.join(' ')
|
||||
}
|
||||
|
||||
export function faqItemPlainText(item: FaqItem): string {
|
||||
return item.blocks.map(blockPlainText).join(' ')
|
||||
}
|
||||
|
||||
export function buildFaqPageJsonLd(items: readonly FaqItem[]): JsonLdNode {
|
||||
return {
|
||||
'@type': 'FAQPage',
|
||||
mainEntity: items.map((item) => ({
|
||||
'@type': 'Question',
|
||||
name: item.question,
|
||||
acceptedAnswer: {
|
||||
'@type': 'Answer',
|
||||
text: faqItemPlainText(item)
|
||||
}
|
||||
}))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user