mirror of
https://github.com/LaconicNetwork/laconic.com.git
synced 2026-09-07 18:44:06 +00:00
Work on client feedback (#45)
This commit is contained in:
+14
-1
@@ -2,12 +2,25 @@ import { render } from 'datocms-structured-text-to-plain-text'
|
||||
import { BlogPostFragment } from 'lib/cms/generated'
|
||||
|
||||
export const getPlainTextContent = (post: BlogPostFragment) => {
|
||||
const text = render(post.content)
|
||||
const children = post?.content?.value.document.children
|
||||
|
||||
const filtered = children.filter((block: any) => block.type === 'paragraph')
|
||||
|
||||
const textBlocks = []
|
||||
|
||||
for (const block of filtered) {
|
||||
const paragraph = render(block)
|
||||
textBlocks.push(paragraph)
|
||||
}
|
||||
|
||||
const text = textBlocks.join(' ')
|
||||
|
||||
return text ?? ''
|
||||
}
|
||||
|
||||
export const getDescription = (post: BlogPostFragment) => {
|
||||
let text = getPlainTextContent(post)
|
||||
|
||||
const charLimit = 200
|
||||
text = text.substring(0, charLimit)
|
||||
let words = text.trim().split(/\s+/)
|
||||
|
||||
Reference in New Issue
Block a user