forked from hyrijk/logseq-plugin-block-to-page
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.ts
More file actions
30 lines (27 loc) · 773 Bytes
/
Copy pathutil.ts
File metadata and controls
30 lines (27 loc) · 773 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { BlockEntity } from "@logseq/libs/dist/LSPlugin.user";
function hasProperty(block: BlockEntity, propertyKey: string): boolean {
return block.properties?.[propertyKey] !== undefined;
}
export function toBatchBlocks(blocks: BlockEntity[]) {
return blocks.map((c) => ({
content: c.content,
// children: [] 会出错
children: c.children?.length
? toBatchBlocks(c.children as BlockEntity[])
: undefined,
properties: c.properties,
}));
}
export function mayBeReferenced(blocks: BlockEntity[]) {
return blocks.some((b) => {
if (hasProperty(b, "id")) {
return true;
} else {
if (b.children) {
return mayBeReferenced(b.children as BlockEntity[]);
} else {
return false;
}
}
});
}