Skip to content

Commit

Permalink
Exclude excalidraw files from plugin globally
Browse files Browse the repository at this point in the history
Closes #37
  • Loading branch information
dvcrn committed Jan 3, 2022
1 parent 6c05959 commit 7040b3a
Show file tree
Hide file tree
Showing 3 changed files with 242 additions and 211 deletions.
19 changes: 19 additions & 0 deletions exclusions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { App, TFile } from 'obsidian';

export function isExcalidraw(app: App, f: TFile) {
if (f.extension === 'excalidraw' || /.*\.excalidraw\.md$/g.test(f.path)) {
return true;
}
const fileCache = app.metadataCache.getFileCache(f);
return (
!!fileCache?.frontmatter && !!fileCache.frontmatter['excalidraw-plugin']
);
}

export function isExcluded(app: App, f: TFile) {
if (isExcalidraw(app, f)) {
return true;
}

return false;
}
13 changes: 10 additions & 3 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
Editor,
} from 'obsidian';

import { isExcluded } from './exclusions';

const stockIllegalSymbols = /[\\/:|#^[\]]/g;

interface LinePointer {
Expand Down Expand Up @@ -72,7 +74,12 @@ export default class FilenameHeadingSyncPlugin extends Plugin {
});
}

fileIsIgnored(path: string): boolean {
fileIsIgnored(activeFile: TFile, path: string): boolean {
// check exclusions
if (isExcluded(this.app, activeFile)) {
return true;
}

// check manual ignore
if (this.settings.ignoredFiles[path] !== undefined) {
return true;
Expand Down Expand Up @@ -113,7 +120,7 @@ export default class FilenameHeadingSyncPlugin extends Plugin {
}

// if ignored, just bail
if (this.fileIsIgnored(file.path)) {
if (this.fileIsIgnored(file, file.path)) {
return;
}

Expand Down Expand Up @@ -153,7 +160,7 @@ export default class FilenameHeadingSyncPlugin extends Plugin {
}

// if oldpath is ignored, hook in and update the new filepath to be ignored instead
if (this.fileIsIgnored(oldPath.trim())) {
if (this.fileIsIgnored(file, oldPath.trim())) {
// if filename didn't change, just bail, nothing to do here
if (file.path === oldPath) {
return;
Expand Down
Loading

0 comments on commit 7040b3a

Please sign in to comment.