Skip to content

Commit

Permalink
Fix foambubble#1242 - attachments are not considered in the context o…
Browse files Browse the repository at this point in the history
…f orphan notes

A note that only has outbound links to attachments is now still considered an orphan.
  • Loading branch information
riccardoferretti committed Sep 3, 2023
1 parent 5e8b817 commit c019767
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ import { FoamWorkspace } from '../model/workspace';
import { IDisposable } from '../common/lifecycle';
import { ResourceProvider } from '../model/provider';

const imageExtensions = ['.png', '.jpg', '.jpeg', '.gif', '.svg', '.webp'];
export const imageExtensions = [
'.png',
'.jpg',
'.jpeg',
'.gif',
'.svg',
'.webp',
];

const asResource = (uri: URI): Resource => {
const type = imageExtensions.includes(uri.getExtension())
Expand Down
13 changes: 11 additions & 2 deletions packages/foam-vscode/src/features/panels/orphans.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import * as vscode from 'vscode';
import { Foam } from '../../core/model/foam';
import { createMatcherAndDataStore } from '../../services/editor';
import { getOrphansConfig } from '../../settings';
import { getAttachmentsExtensions, getOrphansConfig } from '../../settings';
import { GroupedResourcesTreeDataProvider } from './utils/grouped-resources-tree-data-provider';
import { ResourceTreeItem, UriTreeItem } from './utils/tree-view-utils';
import { IMatcher } from '../../core/services/datastore';
import { FoamWorkspace } from '../../core/model/workspace';
import { FoamGraph } from '../../core/model/graph';
import { URI } from '../../core/model/uri';
import { imageExtensions } from '../../core/services/attachment-provider';

const EXCLUDE_TYPES = ['image', 'attachment'];
export default async function activate(
Expand Down Expand Up @@ -66,6 +68,13 @@ export class OrphanTreeView extends GroupedResourcesTreeDataProvider {
.filter(
uri =>
!EXCLUDE_TYPES.includes(this.workspace.find(uri)?.type) &&
this.graph.getConnections(uri).length === 0
this.graph.getBacklinks(uri).length === 0 &&
this.graph.getLinks(uri).filter(c => !isAttachment(c.target))
.length === 0
);
}

function isAttachment(uri: URI) {
const ext = [...getAttachmentsExtensions(), ...imageExtensions];
return ext.includes(uri.getExtension());
}

0 comments on commit c019767

Please sign in to comment.