add: extract plain faq
Add Schema Org for FAQ
This commit is contained in:
parent
bb77bb6a5b
commit
a86b89dc98
5 changed files with 40 additions and 12 deletions
20
app/composables/faq.ts
Normal file
20
app/composables/faq.ts
Normal file
|
@ -0,0 +1,20 @@
|
|||
import type { MinimalElement, MinimalNode } from '@nuxt/content'
|
||||
|
||||
const extractText = (element ?: MinimalNode) : string => {
|
||||
if (!element) return ''
|
||||
if (typeof element === 'string') return element
|
||||
const [,, ...nodes] = element
|
||||
return nodes?.map((el : MinimalNode) => typeof el === 'string' ? el : extractText(el)).join(' ') ?? ''
|
||||
}
|
||||
|
||||
export const usePlainFaq = (body ?: MinimalNode[]) => {
|
||||
if (!body) return []
|
||||
return body.map(part => {
|
||||
const [, meta] = part as MinimalElement
|
||||
return {
|
||||
question: meta.title,
|
||||
answer: extractText(part).replace(/\n/g, ' ')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue