add: more SEO meta
More seometa, better markdown parser
This commit is contained in:
parent
ca3868299c
commit
fa0435efdf
10 changed files with 52 additions and 14 deletions
27
app/utils/markdown.ts
Normal file
27
app/utils/markdown.ts
Normal file
|
@ -0,0 +1,27 @@
|
|||
import type { MinimalElement, MinimalNode } from '@nuxt/content'
|
||||
|
||||
type TypedRecord<T extends readonly string[]> = Record<T[number], string>
|
||||
|
||||
type PlainText<T extends string[]> = {
|
||||
meta: TypedRecord<T>
|
||||
text: string
|
||||
}
|
||||
|
||||
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 generatePlainText = <T extends string[] = []>(body ?: MinimalNode[]) : PlainText<T>[] => {
|
||||
if (!body) return []
|
||||
return body.map<PlainText<T>>(part => {
|
||||
const [, meta] = part as MinimalElement
|
||||
return {
|
||||
meta : meta as TypedRecord<T>,
|
||||
text: extractText(part).replace(/\n/g, ' ')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue