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

Exclusion tags ronzulu #1

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file. Dates are d
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [Unreleased]
- Added the ability to exclude tags from note review [@bitesizing](https://github.com/bitesizing)

- Support RTL flashcards specified by frontmatter "direction" attribute https://github.com/st3v3nmw/obsidian-spaced-repetition/pull/935
- add translation: zh-cn https://github.com/st3v3nmw/obsidian-spaced-repetition/pull/982
Expand Down
7 changes: 7 additions & 0 deletions src/OsrCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ export class OsrCore {
if (matchedNoteTags.length == 0) {
return;
}

// Check if any exlusion tags are present in the note. If so, don't add it to the review queue
const matchedExclusionTags = SettingsUtil.filterForNoteExcludeTag(this.settings, tags);
if (matchedExclusionTags.length > 0) {
return;
}

const noteSchedule: RepItemScheduleInfo =
await DataStoreAlgorithm.getInstance().noteGetSchedule(noteFile);
this._noteReviewQueue.addNoteToQueue(noteFile, noteSchedule, matchedNoteTags);
Expand Down
2 changes: 2 additions & 0 deletions src/lang/locale/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ Note that this setting is common to both Flashcards and Notes.`,
REVIEW_PANE_ON_STARTUP: "Enable note review pane on startup",
TAGS_TO_REVIEW: "Tags to review",
TAGS_TO_REVIEW_DESC: "Enter tags separated by spaces or newlines i.e. #review #tag2 #tag3.",
TAGS_TO_EXCLUDE: "Tags to exclude",
TAGS_TO_EXCLUDE_DESC: "Enter tags you wish to exclude from note review, separated by spaces or newlines i.e. #exclude #tag2 #tag3.",
OPEN_RANDOM_NOTE: "Open a random note for review",
OPEN_RANDOM_NOTE_DESC: "When you turn this off, notes are ordered by importance (PageRank).",
AUTO_NEXT_NOTE: "Open next note automatically after a review",
Expand Down
26 changes: 26 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface SRSettings {
// notes
enableNoteReviewPaneOnStartup: boolean;
tagsToReview: string[];
tagsToExclude: string[];
noteFoldersToIgnore: string[];
openRandomNote: boolean;
autoNextNote: boolean;
Expand Down Expand Up @@ -74,6 +75,7 @@ export const DEFAULT_SETTINGS: SRSettings = {
// notes
enableNoteReviewPaneOnStartup: true,
tagsToReview: ["#review"],
tagsToExclude: ["#exclude"],
noteFoldersToIgnore: [],
openRandomNote: false,
autoNextNote: false,
Expand Down Expand Up @@ -141,6 +143,16 @@ export class SettingsUtil {
return result;
}

static filterForNoteExcludeTag(settings: SRSettings, tags: string[]): string[] {
const result: string[] = [];
for (const tagToExclude of settings.tagsToExclude) {
if (tags.some((tag) => tag === tagToExclude || tag.startsWith(tagToExclude + "/"))) {
result.push(tagToExclude);
}
}
return result;
}

private static isTagInList(tagList: string[], tag: string): boolean {
for (const tagFromList of tagList) {
if (tag === tagFromList || tag.startsWith(tagFromList + "/")) {
Expand Down Expand Up @@ -508,6 +520,20 @@ export class SRSettingTab extends PluginSettingTab {
}),
);

new Setting(containerEl)
.setName(t("TAGS_TO_EXCLUDE"))
.setDesc(t("TAGS_TO_EXCLUDE_DESC"))
.addTextArea((text) =>
text
.setValue(this.plugin.data.settings.tagsToExclude.join(" "))
.onChange((value) => {
applySettingsUpdate(async () => {
this.plugin.data.settings.tagsToExclude = value.split(/\s+/);
await this.plugin.savePluginData();
});
}),
);

this.createSetting_FoldersToIgnore(containerEl);

new Setting(containerEl)
Expand Down