From a4a5070e883ff71fb40d22373e2711e35fef3154 Mon Sep 17 00:00:00 2001 From: igar1991 Date: Thu, 13 Jul 2023 20:57:40 +0300 Subject: [PATCH 1/2] feat: add extractArticleText --- src/utils/index.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/utils/index.ts b/src/utils/index.ts index 4d0b832..52ad83f 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,3 +1,4 @@ +import { OutputBlockData } from '@editorjs/editorjs' import { Article } from '../types' export const shortenString = (str: string | null): string => { @@ -65,3 +66,14 @@ export const stripHtmlTags = (html: string): string => { return tempElement.textContent || tempElement.innerText || '' } + +export const extractArticleText = (jsonArticle: string, symbols: number): string => { + const blocks: [OutputBlockData] = JSON.parse(jsonArticle).blocks + const paragraphs = blocks + .filter(block => block.type === 'paragraph') + .map(block => block.data.text.replace(/<\/?[^>]+(>|$)/g, '')) + .join(' ') + const concatenatedText = paragraphs.slice(0, symbols) + + return concatenatedText +} From d2e5eb88a52dede0d8d850f7146474aa2e97f0d2 Mon Sep 17 00:00:00 2001 From: igar1991 Date: Wed, 6 Mar 2024 12:54:04 +0300 Subject: [PATCH 2/2] refactor: remove duplicates --- src/utils/index.ts | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/utils/index.ts b/src/utils/index.ts index f2a7e9f..41d3e2b 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -184,14 +184,3 @@ export const shortenName = (name: string): string => { return name } - -export const extractArticleText = (jsonArticle: string, symbols: number): string => { - const blocks: [OutputBlockData] = JSON.parse(jsonArticle).blocks - const paragraphs = blocks - .filter(block => block.type === 'paragraph') - .map(block => block.data.text.replace(/<\/?[^>]+(>|$)/g, '')) - .join(' ') - const concatenatedText = paragraphs.slice(0, symbols) - - return concatenatedText -}