Skip to content

Commit

Permalink
chore: filter out edgeless content from page preview (#5607)
Browse files Browse the repository at this point in the history
Co-authored-by: EYHN <cneyhn@gmail.com>
  • Loading branch information
lawvs and EYHN authored Feb 23, 2024
1 parent 228b0d7 commit 9692a12
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,35 @@ export const getPagePreviewText = (page: Page) => {
console.error('Unexpected empty block');
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) {
queue.unshift(...block.children);
}
if (block.role !== 'content') {
continue;
}
if (block.text) {
// Text block e.g. paragraph/heading/list/code
const text = block.text.toString();
if (!text.length) {
continue;
}
previewLenNeeded -= text.length;
preview.push(text);
} else {
// image/attachment/bookmark
// Other block e.g. image/attachment/bookmark
const type = block.flavour.split('affine:')[1] ?? null;
previewLenNeeded -= type.length + 2;
type && preview.push(`[${type}]`);
if (type) {
previewLenNeeded -= type.length + 2;
preview.push(`[${type}]`);
}
}
}
return preview.join(' ');
return preview.join(' ').slice(0, MAX_PREVIEW_LENGTH);
};

const emptyAtom = atom<string>('');
Expand Down

0 comments on commit 9692a12

Please sign in to comment.