Skip to content

Commit 931a1d0

Browse files
authored
feature: Skip pages with exclude-from-graph-view: true (#77)
* chore: Add exclude-from-graph-view property to list of properties to fetch * feat: Add exclusion for pages with exclude-from-graph-view set * test: Add test to ensure exclude-from-graph-view pages are skipped * test: Add snapshot for exclude-from-graph-view tests * docs: Add exclude-to-graph-view support to README
1 parent 09f0df9 commit 931a1d0

File tree

4 files changed

+59
-2
lines changed

4 files changed

+59
-2
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ Learn more about the relationships between between your notes using network anal
1919
- Adamic Adar - Find secret connections between your notes. Click a note to learn which notes the algorithm thinks are linked
2020
- CoCitation - Checks how alike documents are by looking at how close their shared references are
2121
- Shift-click node to add it to sidebar
22-
- If there are nodes you wish to hide from your graph add the page property `graph-hide:: true`
22+
- If there are nodes you wish to hide from your graph add the page property `graph-hide:: true` or `exclude-from-graph-view:: true`
23+
- `graph-hide:: true` hides nodes from this plugin's `graph analysis` mode
24+
- `exclude-from-graph-view:: true` hides nodes from both this plugin and Logseq's native global graph view, see [the Logseq documentation](https://docs.logseq.com/#/page/built-in%20properties)
2325
- If you are interested in seeing suprising paths in your notes its a good idea to add this to notes that have lots of connections.
2426

2527
## Search and filters

src/__snapshots__/graph.ts.snap

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,30 @@ exports[`buildGraph > shows journal pages when requested 1`] = `
396396
}
397397
`;
398398

399+
exports[`buildGraph > skips pages with exclude-from-graph-view: true 1`] = `
400+
{
401+
"attributes": {
402+
"isInited": true,
403+
},
404+
"edges": [],
405+
"nodes": [
406+
{
407+
"attributes": {
408+
"aliases": [],
409+
"label": "A",
410+
"rawAliases": [],
411+
"type": "circle",
412+
},
413+
},
414+
],
415+
"options": {
416+
"allowSelfLoops": true,
417+
"multi": false,
418+
"type": "mixed",
419+
},
420+
}
421+
`;
422+
399423
exports[`buildGraph > skips pages with graph-hide: true 1`] = `
400424
{
401425
"attributes": {

src/graph.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export async function buildGraph(
3434
const journals = pages.filter((p) => p["journal?"]);
3535

3636
for (const page of pages) {
37-
if (page.properties && page.properties.graphHide) {
37+
if (page.properties && (page.properties.graphHide || page.properties.excludeFromGraphView)) {
3838
continue;
3939
}
4040
if (g.hasNode(page.id)) {
@@ -445,6 +445,36 @@ if (import.meta.vitest) {
445445
expect(graphToJson(graph)).toMatchSnapshot();
446446
});
447447

448+
it("skips pages with exclude-from-graph-view: true", async () => {
449+
const getAllPages = async () => [
450+
{ id: 1, "journal?": false, name: "A" },
451+
{
452+
id: 2,
453+
"journal?": false,
454+
name: "B",
455+
properties: { excludeFromGraphView: true },
456+
},
457+
];
458+
const getBlockReferences = async () => [
459+
[
460+
{
461+
refs: [{ id: 2 }],
462+
"path-refs": [{ id: 1 }, { id: 2 }],
463+
page: { id: 1 },
464+
},
465+
],
466+
];
467+
const getSettings = () => ({ journal: false });
468+
const getBlock = async (ref: BlockIdentity | EntityID) => null;
469+
const graph = await buildGraph(
470+
getAllPages,
471+
getBlockReferences,
472+
getSettings,
473+
getBlock
474+
);
475+
expect(graphToJson(graph)).toMatchSnapshot();
476+
});
477+
448478
it("merges alias nodes", async () => {
449479
const getAllPages = async () => [
450480
{ id: 1, "journal?": false, name: "A", properties: { alias: ["B"] } },

src/logseq.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface Page {
1010
name: string;
1111
properties?: {
1212
graphHide?: boolean;
13+
excludeFromGraphView?: boolean;
1314
alias?: string[] | string;
1415
icon?: string;
1516
pageIcon?: string;

0 commit comments

Comments
 (0)