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;
|
||||
}
|
||||
|
||||
fileFiltered(fileName: string){
|
||||
return this.settings.fileNameFilter.length > 0 && fileName.includes(this.settings.fileNameFilter);
|
||||
}
|
||||
|
||||
async getTotalWordCount() {
|
||||
let words = 0;
|
||||
const files = this.vault.getFiles();
|
||||
for (const i in files) {
|
||||
const file = files[i];
|
||||
if (file.extension === "md") {
|
||||
const files = this.vault.getMarkdownFiles();
|
||||
for (const file of files) {
|
||||
if (!this.fileFiltered(file.basename)) {
|
||||
words += getWordCount(await this.vault.cachedRead(file));
|
||||
}
|
||||
}
|
||||
|
@ -33,10 +36,9 @@ export class DataCollector {
|
|||
|
||||
async getTotalCharacterCount() {
|
||||
let characters = 0;
|
||||
const files = this.vault.getFiles();
|
||||
for (const i in files) {
|
||||
const file = files[i];
|
||||
if (file.extension === "md") {
|
||||
const files = this.vault.getMarkdownFiles();
|
||||
for (const file of files) {
|
||||
if (!this.fileFiltered(file.basename)) {
|
||||
characters += getCharacterCount(await this.vault.cachedRead(file));
|
||||
}
|
||||
}
|
||||
|
@ -45,15 +47,14 @@ export class DataCollector {
|
|||
}
|
||||
|
||||
async getTotalSentenceCount() {
|
||||
let sentence = 0;
|
||||
const files = this.vault.getFiles();
|
||||
for (const i in files) {
|
||||
const file = files[i];
|
||||
if (file.extension === "md") {
|
||||
sentence += getSentenceCount(await this.vault.cachedRead(file));
|
||||
let sentences = 0;
|
||||
const files = this.vault.getMarkdownFiles();
|
||||
for (const file of files) {
|
||||
if (!this.fileFiltered(file.basename)) {
|
||||
sentences += getSentenceCount(await this.vault.cachedRead(file));
|
||||
}
|
||||
}
|
||||
|
||||
return sentence;
|
||||
return sentences;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,6 +48,16 @@ export class BetterWordCountSettingsTab extends PluginSettingTab {
|
|||
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
|
||||
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",
|
||||
countComments: false,
|
||||
collectStats: false,
|
||||
fileNameFilter: "",
|
||||
};
|
||||
|
||||
export const PRESETS: PresetOption[] = [
|
||||
|
@ -38,6 +39,7 @@ export interface BetterWordCountSettings {
|
|||
statusBarAltQuery: string;
|
||||
countComments: boolean;
|
||||
collectStats: boolean;
|
||||
fileNameFilter: string;
|
||||
}
|
||||
|
||||
export interface PresetOption {
|
||||
|
|
Loading…
Reference in a new issue