mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-22 19:53:48 +08:00
chore: filter out edgeless content from page preview (#5607)
Co-authored-by: EYHN <cneyhn@gmail.com>
This commit is contained in:
@@ -23,6 +23,11 @@ export const getPagePreviewText = (page: Page) => {
|
|||||||
console.error('Unexpected empty block');
|
console.error('Unexpected empty block');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (block.flavour === 'affine:surface') {
|
||||||
|
// The surface block is a special block that contains canvas data,
|
||||||
|
// it should not be included in the preview.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (block.children) {
|
if (block.children) {
|
||||||
queue.unshift(...block.children);
|
queue.unshift(...block.children);
|
||||||
}
|
}
|
||||||
@@ -30,6 +35,7 @@ export const getPagePreviewText = (page: Page) => {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (block.text) {
|
if (block.text) {
|
||||||
|
// Text block e.g. paragraph/heading/list/code
|
||||||
const text = block.text.toString();
|
const text = block.text.toString();
|
||||||
if (!text.length) {
|
if (!text.length) {
|
||||||
continue;
|
continue;
|
||||||
@@ -37,13 +43,15 @@ export const getPagePreviewText = (page: Page) => {
|
|||||||
previewLenNeeded -= text.length;
|
previewLenNeeded -= text.length;
|
||||||
preview.push(text);
|
preview.push(text);
|
||||||
} else {
|
} else {
|
||||||
// image/attachment/bookmark
|
// Other block e.g. image/attachment/bookmark
|
||||||
const type = block.flavour.split('affine:')[1] ?? null;
|
const type = block.flavour.split('affine:')[1] ?? null;
|
||||||
previewLenNeeded -= type.length + 2;
|
if (type) {
|
||||||
type && preview.push(`[${type}]`);
|
previewLenNeeded -= type.length + 2;
|
||||||
|
preview.push(`[${type}]`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return preview.join(' ');
|
return preview.join(' ').slice(0, MAX_PREVIEW_LENGTH);
|
||||||
};
|
};
|
||||||
|
|
||||||
const emptyAtom = atom<string>('');
|
const emptyAtom = atom<string>('');
|
||||||
|
|||||||
Reference in New Issue
Block a user