Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for excluding paths #10

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ node_modules
package-lock.json

# build
main.js
*.js.map
313 changes: 313 additions & 0 deletions main.js

Large diffs are not rendered by default.

51 changes: 49 additions & 2 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,22 +74,54 @@ export default class Changelog extends Plugin {
}

buildChangelog(): string {
const pathsToExclude = this.settings.excludePaths.split(',');
const cache = this.app.metadataCache;
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.startsWith(pathsToExclude[i].trim())) {
keep = false;
break;
}
}
return keep;
}
)
// exclude if specifically told not to
.filter(
function (recentlyEditedFile) {
const frontMatter = cache.getFileCache(recentlyEditedFile).frontmatter;
if (frontMatter && frontMatter.publish === false) {
return false;
}
return true;
}
)
.sort((a, b) => (a.stat.mtime < b.stat.mtime ? 1 : -1))
.slice(0, this.settings.numberOfFilesToShow);
let changelogContent = ``;
let header = ``;
for (let recentlyEditedFile of recentlyEditedFiles) {
// TODO: make date format configurable (and validate it)
const humanTime = window
.moment(recentlyEditedFile.stat.mtime)
.format("YYYY-MM-DD [at] HH[h]mm");
changelogContent += `- ${humanTime} · [[${recentlyEditedFile.basename}]]\n`;
// date is already shown in the titles
.format("YYYY-MM-DD HH[h]mm");
if (header != humanTime.substring(0,10)) {
header = humanTime.substring(0,10)
changelogContent += `## ${header}\n`
}
changelogContent += `- ${humanTime.substring(10,16)} · [[${recentlyEditedFile.basename}]]\n`;
}
return changelogContent;
}
Expand Down Expand Up @@ -119,6 +152,7 @@ interface ChangelogSettings {
changelogFilePath: string;
numberOfFilesToShow: number;
watchVaultChange: boolean;
excludePaths: string;
}

class ChangelogSettingsTab extends PluginSettingTab {
Expand Down Expand Up @@ -177,5 +211,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();
});
});
}
}
10 changes: 10 additions & 0 deletions manifest-beta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"id": "obsidian-vault-changelog",
"name": "Vault Changelog",
"version": "0.1.1",
"minAppVersion": "0.9.7",
"description": "Obsidian plugin to maintain a notes changelog in a vault",
"author": "Badr Bouslikhin, Nicole van der Hoeven",
"authorUrl": "https://github.com/MrZeroo00",
"isDesktopOnly": false
}