feat: add page preview (#2620)

This commit is contained in:
Whitewater
2023-05-31 01:18:48 -07:00
committed by GitHub
parent 4c9bda1406
commit 20f1d487c8
2 changed files with 13 additions and 2 deletions

View File

@@ -5,11 +5,15 @@ import { atom } from 'jotai';
const weakMap = new WeakMap<Page, Atom<string>>();
const getPagePreviewText = (page: Page) => {
export const getPagePreviewText = (page: Page) => {
// TODO this is incorrect, since the order of blocks is not guaranteed
const paragraphBlocks = page.getBlockByFlavour(
'affine:paragraph'
) as ParagraphBlockModel[];
const text = paragraphBlocks.map(block => block.text.toString()).join('\n');
const text = paragraphBlocks
.slice(0, 10)
.map(block => block.text.toString())
.join('\n');
return text.slice(0, 30);
};