Skip to content

Commit

Permalink
Adds setting for #28 word counts of additional file types
Browse files Browse the repository at this point in the history
  • Loading branch information
lynchjames committed Sep 10, 2023
1 parent 6dff18d commit cc45c7f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/core/note-goal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class NoteGoalHelper {
const todaysDailyGoal = await this.goalHistoryHelper.todaysGoalItem(fileOrFolder.path);
const result = {
path: fileOrFolder.path,
title: fileOrFolder.name.replace('.md', ''),
title: fileOrFolder.name.split('.')[0],
goalType: isFile ? GoalType.Note : GoalType.Folder,
goalCount: goalCount,
dailyGoalCount: dailyGoalCount,
Expand Down Expand Up @@ -98,6 +98,10 @@ export class NoteGoalHelper {
}

isFile(fileOrFolder:TAbstractFile){
return fileOrFolder instanceof TFile && fileOrFolder.extension == "md";
return fileOrFolder instanceof TFile && (fileOrFolder.extension == "md" || this.additionalFileTypes(fileOrFolder));
}

additionalFileTypes(file:TFile) {
return this.settings.additionalFileTypes.contains(file.extension);
}
}
20 changes: 20 additions & 0 deletions src/core/settings/settings-tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,26 @@ import { DAILY_GOAL_BAR_COLOR, DAILY_GOAL_FRONTMATTER_KEY, GOAL_BAR_COLOR, GOAL_
this.plugin.loadNoteGoalData();
}));

new Setting(containerEl)
.setName('Additional file types')
.setDesc('Markdown files are included in word counts by default. Add other file types to include in word counts. Comma delimited with only file extension')
.addButton(button =>
button
.setButtonText("Reindex")
.setCta()
.onClick(evt => {
this.plugin.loadNoteGoalData(true);
}))
.addTextArea(text =>
text
.setValue(this.plugin.settings.additionalFileTypes?.join(','))
.setPlaceholder('md,')
.onChange(async (value:string) => {
this.plugin.settings.additionalFileTypes =
value.split(',').map(v => v.trim()).filter(v => v && v.length > 0);
await this.plugin.saveData(this.plugin.settings);
}));

new Setting(containerEl)
.setName('Exclude comments')
.setDesc('Exclude markdown (%% %%) and HTML (<!-- -->) comments when counting words')
Expand Down
1 change: 1 addition & 0 deletions src/core/settings/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export class WritingGoalsSettings {
allowNegativeGoalProgress: boolean= false;
customGoalBarColor: string = GOAL_BAR_COLOR;
customDailyGoalBarColor: string = DAILY_GOAL_BAR_COLOR;
additionalFileTypes: string[];

noGoal(path:string): boolean{
return !this.noteGoals.contains(path) && this.folderGoals.filter(fg => fg.path == path).length == 0;
Expand Down

0 comments on commit cc45c7f

Please sign in to comment.