import { EditorState } from 'draft-js'; export const editorStateToFirstParagraph = ( editorState: EditorState ): string => { const firstUnstyledBlock = editorState .getCurrentContent() .getBlocksAsArray() .find((block) => block.getType() === 'unstyled'); return firstUnstyledBlock ? firstUnstyledBlock.getText() : ''; }; export const editorStateToMetaDescription = ( editorState: EditorState ): string => editorStateToFirstParagraph(editorState) .slice(0, 200) .replace(/^(.*[.?!])(.*)/, '$1') .trim();