Add basic filename filtering functionality
Adds a new setting fileNameFilter that omits filenames including that string from total word/character/sentence counts.
This commit is contained in:
parent
ba22ec7db9
commit
60ea70cfff
3 changed files with 28 additions and 15 deletions
|
@ -18,12 +18,15 @@ export class DataCollector {
|
||||||
return this.vault.getMarkdownFiles().length;
|
return this.vault.getMarkdownFiles().length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fileFiltered(fileName: string){
|
||||||
|
return this.settings.fileNameFilter.length > 0 && fileName.includes(this.settings.fileNameFilter);
|
||||||
|
}
|
||||||
|
|
||||||
async getTotalWordCount() {
|
async getTotalWordCount() {
|
||||||
let words = 0;
|
let words = 0;
|
||||||
const files = this.vault.getFiles();
|
const files = this.vault.getMarkdownFiles();
|
||||||
for (const i in files) {
|
for (const file of files) {
|
||||||
const file = files[i];
|
if (!this.fileFiltered(file.basename)) {
|
||||||
if (file.extension === "md") {
|
|
||||||
words += getWordCount(await this.vault.cachedRead(file));
|
words += getWordCount(await this.vault.cachedRead(file));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,10 +36,9 @@ export class DataCollector {
|
||||||
|
|
||||||
async getTotalCharacterCount() {
|
async getTotalCharacterCount() {
|
||||||
let characters = 0;
|
let characters = 0;
|
||||||
const files = this.vault.getFiles();
|
const files = this.vault.getMarkdownFiles();
|
||||||
for (const i in files) {
|
for (const file of files) {
|
||||||
const file = files[i];
|
if (!this.fileFiltered(file.basename)) {
|
||||||
if (file.extension === "md") {
|
|
||||||
characters += getCharacterCount(await this.vault.cachedRead(file));
|
characters += getCharacterCount(await this.vault.cachedRead(file));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,15 +47,14 @@ export class DataCollector {
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTotalSentenceCount() {
|
async getTotalSentenceCount() {
|
||||||
let sentence = 0;
|
let sentences = 0;
|
||||||
const files = this.vault.getFiles();
|
const files = this.vault.getMarkdownFiles();
|
||||||
for (const i in files) {
|
for (const file of files) {
|
||||||
const file = files[i];
|
if (!this.fileFiltered(file.basename)) {
|
||||||
if (file.extension === "md") {
|
sentences += getSentenceCount(await this.vault.cachedRead(file));
|
||||||
sentence += getSentenceCount(await this.vault.cachedRead(file));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return sentence;
|
return sentences;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,16 @@ export class BetterWordCountSettingsTab extends PluginSettingTab {
|
||||||
await this.plugin.saveSettings();
|
await this.plugin.saveSettings();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
new Setting(containerEl)
|
||||||
|
.setName("Filter Out Filenames")
|
||||||
|
.setDesc("Filenames including this string will be omitted from total counts. Leave blank to count all files.")
|
||||||
|
.addText((text) => {
|
||||||
|
text.setValue(this.plugin.settings.fileNameFilter)
|
||||||
|
text.onChange(async (value: string) => {
|
||||||
|
this.plugin.settings.fileNameFilter = value;
|
||||||
|
await this.plugin.saveSettings();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// Status Bar Settings
|
// Status Bar Settings
|
||||||
containerEl.createEl("h3", { text: "Status Bar Settings" });
|
containerEl.createEl("h3", { text: "Status Bar Settings" });
|
||||||
|
|
|
@ -10,6 +10,7 @@ export const DEFAULT_SETTINGS: BetterWordCountSettings = {
|
||||||
"{file_count} files {total_word_count} words {total_character_count} characters",
|
"{file_count} files {total_word_count} words {total_character_count} characters",
|
||||||
countComments: false,
|
countComments: false,
|
||||||
collectStats: false,
|
collectStats: false,
|
||||||
|
fileNameFilter: "",
|
||||||
};
|
};
|
||||||
|
|
||||||
export const PRESETS: PresetOption[] = [
|
export const PRESETS: PresetOption[] = [
|
||||||
|
@ -38,6 +39,7 @@ export interface BetterWordCountSettings {
|
||||||
statusBarAltQuery: string;
|
statusBarAltQuery: string;
|
||||||
countComments: boolean;
|
countComments: boolean;
|
||||||
collectStats: boolean;
|
collectStats: boolean;
|
||||||
|
fileNameFilter: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PresetOption {
|
export interface PresetOption {
|
||||||
|
|
Loading…
Reference in a new issue