Skip to content

Commit e0ae1b8

Browse files
authored
Merge pull request #52 from philoserf/add-exclusion
Add exluded folders
2 parents 8cb479b + 3e5b82c commit e0ae1b8

File tree

2 files changed

+130
-4
lines changed

2 files changed

+130
-4
lines changed

src/main.ts

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,38 @@ import {
66
DEFAULT_SETTINGS,
77
} from "./settings";
88

9+
// Add styles for the excluded folders list
10+
const EXCLUDED_FOLDERS_STYLES = `
11+
.excluded-folders-list {
12+
margin-bottom: 1em;
13+
}
14+
15+
.excluded-folder-item {
16+
display: flex;
17+
justify-content: space-between;
18+
align-items: center;
19+
background-color: var(--background-secondary);
20+
border-radius: 4px;
21+
padding: 4px 8px;
22+
margin-bottom: 6px;
23+
}
24+
25+
.excluded-folder-remove {
26+
cursor: pointer;
27+
border: none;
28+
background: transparent;
29+
color: var(--text-muted);
30+
padding: 0 4px;
31+
font-size: 14px;
32+
}
33+
34+
.excluded-folder-remove:hover {
35+
color: var(--text-error);
36+
}`;
37+
938
export default class ChangelogPlugin extends Plugin {
1039
settings: ChangelogSettings = DEFAULT_SETTINGS;
40+
private styleEl: HTMLStyleElement;
1141

1242
async onload() {
1343
await this.loadSettings();
@@ -19,10 +49,22 @@ export default class ChangelogPlugin extends Plugin {
1949
callback: () => this.updateChangelog(),
2050
});
2151

52+
// Add styles for the excluded folders feature
53+
this.styleEl = document.createElement("style");
54+
this.styleEl.textContent = EXCLUDED_FOLDERS_STYLES;
55+
document.head.appendChild(this.styleEl);
56+
2257
this.onVaultChange = debounce(this.onVaultChange.bind(this), 200);
2358
this.enableAutoUpdate();
2459
}
2560

61+
onunload() {
62+
// Remove styles when plugin is disabled
63+
if (this.styleEl && this.styleEl.parentNode) {
64+
this.styleEl.parentNode.removeChild(this.styleEl);
65+
}
66+
}
67+
2668
enableAutoUpdate() {
2769
if (this.settings.autoUpdate) {
2870
this.registerEvent(this.app.vault.on("modify", this.onVaultChange));
@@ -65,7 +107,21 @@ export default class ChangelogPlugin extends Plugin {
65107
getRecentlyEditedFiles() {
66108
return this.app.vault
67109
.getMarkdownFiles()
68-
.filter((file) => file.path !== this.settings.changelogPath)
110+
.filter((file) => {
111+
// Exclude the changelog file itself
112+
if (file.path === this.settings.changelogPath) {
113+
return false;
114+
}
115+
116+
// Exclude files in excluded folders
117+
for (const folder of this.settings.excludedFolders) {
118+
if (file.path.startsWith(folder)) {
119+
return false;
120+
}
121+
}
122+
123+
return true;
124+
})
69125
.sort((a, b) => b.stat.mtime - a.stat.mtime)
70126
.slice(0, this.settings.maxRecentFiles);
71127
}

src/settings.ts

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export interface ChangelogSettings {
1616
changelogPath: string;
1717
datetimeFormat: string;
1818
maxRecentFiles: number;
19+
excludedFolders: string[];
1920
}
2021

2122
// Define the default settings
@@ -24,6 +25,7 @@ export const DEFAULT_SETTINGS: ChangelogSettings = {
2425
changelogPath: "Changelog.md",
2526
datetimeFormat: "YYYY-MM-DD[T]HHmm",
2627
maxRecentFiles: 25,
28+
excludedFolders: [],
2729
};
2830

2931
// Define the settings tab
@@ -35,6 +37,36 @@ export class ChangelogSettingsTab extends PluginSettingTab {
3537
this.plugin = plugin;
3638
}
3739

40+
// Helper method to render the list of excluded folders
41+
renderExcludedFolders(container: HTMLElement) {
42+
container.empty();
43+
44+
if (this.plugin.settings.excludedFolders.length === 0) {
45+
container.createEl("div", { text: "No excluded folders" });
46+
return;
47+
}
48+
49+
this.plugin.settings.excludedFolders.forEach((folder) => {
50+
const folderDiv = container.createDiv("excluded-folder-item");
51+
folderDiv.createSpan({ text: folder });
52+
53+
const removeButton = folderDiv.createEl("button", {
54+
text: "✕",
55+
cls: "excluded-folder-remove",
56+
});
57+
58+
removeButton.addEventListener("click", async () => {
59+
const index =
60+
this.plugin.settings.excludedFolders.indexOf(folder);
61+
if (index > -1) {
62+
this.plugin.settings.excludedFolders.splice(index, 1);
63+
await this.plugin.saveSettings();
64+
this.renderExcludedFolders(container);
65+
}
66+
});
67+
});
68+
}
69+
3870
display() {
3971
const { containerEl } = this;
4072
const { settings } = this.plugin;
@@ -53,7 +85,7 @@ export class ChangelogSettingsTab extends PluginSettingTab {
5385
} else {
5486
this.plugin.disableAutoUpdate();
5587
}
56-
})
88+
}),
5789
);
5890

5991
new Setting(containerEl)
@@ -94,7 +126,7 @@ export class ChangelogSettingsTab extends PluginSettingTab {
94126
// Save valid format and persist settings
95127
settings.datetimeFormat = format;
96128
await this.plugin.saveSettings();
97-
})
129+
}),
98130
);
99131

100132
new Setting(containerEl)
@@ -112,7 +144,45 @@ export class ChangelogSettingsTab extends PluginSettingTab {
112144
}
113145
settings.maxRecentFiles = numValue;
114146
await this.plugin.saveSettings();
115-
})
147+
}),
116148
);
149+
150+
// Excluded folders section header
151+
containerEl.createEl("h3", { text: "Excluded Folders" });
152+
153+
// Create a list of currently excluded folders with delete buttons
154+
const excludedFoldersList = containerEl.createDiv(
155+
"excluded-folders-list",
156+
);
157+
this.renderExcludedFolders(excludedFoldersList);
158+
159+
// Add a new excluded folder with path suggestions
160+
new Setting(containerEl)
161+
.setName("Add excluded folder")
162+
.setDesc("Folders to exclude from the changelog")
163+
.addText((text) => {
164+
text.setPlaceholder("folder/path/");
165+
166+
// Add path autocompletion
167+
new PathSuggest(this.app, text.inputEl);
168+
})
169+
.addButton((button) => {
170+
button.setButtonText("Add").onClick(async () => {
171+
const input =
172+
button.buttonEl.parentElement?.querySelector("input");
173+
if (input) {
174+
const folderPath = input.value;
175+
if (
176+
folderPath &&
177+
!settings.excludedFolders.includes(folderPath)
178+
) {
179+
settings.excludedFolders.push(folderPath);
180+
await this.plugin.saveSettings();
181+
input.value = "";
182+
this.renderExcludedFolders(excludedFoldersList);
183+
}
184+
}
185+
});
186+
});
117187
}
118188
}

0 commit comments

Comments
 (0)