Work on client feedback (#45)

This commit is contained in:
Fede Álvarez
2022-04-18 09:23:31 -03:00
committed by GitHub
parent b39cf400f9
commit 5ffb93b105
12 changed files with 66 additions and 45 deletions
+14 -1
View File
@@ -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+/)