Skip to content

Commit

Permalink
Added support for excluding paths
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolevanderhoeven committed May 18, 2021
1 parent 77fa85a commit 422ac13
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const DEFAULT_SETTINGS: ChangelogSettings = {
numberOfFilesToShow: 10,
changelogFilePath: "",
watchVaultChange: false,
excludePaths: "",
};

declare global {
Expand Down Expand Up @@ -73,13 +74,28 @@ export default class Changelog extends Plugin {
}

buildChangelog(): string {
const pathsToExclude = this.settings.excludePaths.split(',');
const files = this.app.vault.getMarkdownFiles();
const recentlyEditedFiles = files
// Remove changelog file from recentlyEditedFiles list
.filter(
(recentlyEditedFile) =>
recentlyEditedFile.path !== this.settings.changelogFilePath
)
// Remove files from paths to be excluded from recentlyEditedFiles list
.filter(
function (recentlyEditedFile) {
let i;
let keep = true;
for (i = 0; i < pathsToExclude.length; i++) {
if (recentlyEditedFile.path.includes(pathsToExclude[i])) {
keep = false;
break;
}
}
return keep;
}
)
.sort((a, b) => (a.stat.mtime < b.stat.mtime ? 1 : -1))
.slice(0, this.settings.numberOfFilesToShow);
let changelogContent = ``;
Expand Down Expand Up @@ -119,6 +135,7 @@ interface ChangelogSettings {
changelogFilePath: string;
numberOfFilesToShow: number;
watchVaultChange: boolean;
excludePaths: string;
}

class ChangelogSettingsTab extends PluginSettingTab {
Expand Down Expand Up @@ -177,5 +194,18 @@ class ChangelogSettingsTab extends PluginSettingTab {
this.plugin.registerWatchVaultEvents();
})
);

new Setting(containerEl)
.setName("Excluded paths")
.setDesc("Paths or folders to ignore from changelog, separated by a comma")
.addText((text) => {
text
.setPlaceholder("Example: Meetings,People")
.setValue(settings.excludePaths)
.onChange((value) => {
settings.excludePaths = value;
this.plugin.saveSettings();
});
});
}
}

0 comments on commit 422ac13

Please sign in to comment.