Skip to content

Commit

Permalink
fix: ignore with glob patterns (#1086)
Browse files Browse the repository at this point in the history
  • Loading branch information
st3v3nmw authored Sep 22, 2024
1 parent 8734d88 commit 150523b
Show file tree
Hide file tree
Showing 22 changed files with 105 additions and 38 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Lint and Test
name: Lint and Test Code

on:
pull_request:
Expand All @@ -8,7 +8,7 @@ env:
COREPACK_ENABLE_STRICT: 0

jobs:
lint_and_test:
lint_and_test_code:
runs-on: ubuntu-latest

steps:
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
},
"dependencies": {
"chart.js": "^4.4.4",
"minimatch": "^10.0.1",
"pagerank.js": "^1.0.2",
"peggy": "^4.0.3"
},
Expand Down
12 changes: 10 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/gui/flashcard-review-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ export class FlashcardReviewView {
}
result += separator + context;
});
return result + separator + "...";
return result;
}

// -> Header
Expand Down
4 changes: 2 additions & 2 deletions src/lang/locale/ar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ export default {
PROJECT_CONTRIBUTIONS:
'Raise an issue <a href="${issues_url}">here</a> if you have a feature request or a bug-report',
FOLDERS_TO_IGNORE: "مجلدات لتجاهلها",
FOLDERS_TO_IGNORE_DESC: `Templates Meta/Scripts.
Note that this setting is common to both Flashcards and Notes. : أدخل مسارات المجلد مفصولة بواسطة سطور جديدة,مثال`,
FOLDERS_TO_IGNORE_DESC:
"Enter folder paths or glob patterns on separate lines e.g. Templates Meta/Scripts or **/*.excalidraw.md. This setting is common to both flashcards and notes.",
OBSIDIAN_INTEGRATION: "Integration into Obsidian",
FLASHCARDS: "البطاقات",
FLASHCARD_EASY_LABEL: "نص الزر سهل",
Expand Down
4 changes: 2 additions & 2 deletions src/lang/locale/cz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ export default {
PROJECT_CONTRIBUTIONS:
'Raise an issue <a href="${issues_url}">here</a> if you have a feature request or a bug-report',
FOLDERS_TO_IGNORE: "Ignorované složky",
FOLDERS_TO_IGNORE_DESC: `Zadejte cesty ke složkám oddělené odřádkováním napříkad. Šablony Meta/Scripts.
Note that this setting is common to both Flashcards and Notes.`,
FOLDERS_TO_IGNORE_DESC:
"Enter folder paths or glob patterns on separate lines e.g. Templates Meta/Scripts or **/*.excalidraw.md. This setting is common to both flashcards and notes.",
OBSIDIAN_INTEGRATION: "Integration into Obsidian",
FLASHCARDS: "Kartičky",
FLASHCARD_EASY_LABEL: "Easy Button Text",
Expand Down
4 changes: 2 additions & 2 deletions src/lang/locale/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ export default {
PROJECT_CONTRIBUTIONS:
'Raise an issue <a href="${issues_url}">here</a> if you have a feature request or a bug-report',
FOLDERS_TO_IGNORE: "Ausgeschlossene Ordner",
FOLDERS_TO_IGNORE_DESC: `Mehrere Ordner mit Zeilenumbrüchen getrennt angeben. Bsp. OrdnerA[Zeilenumbruch]OrdnerB/Unterordner.
Note that this setting is common to both Flashcards and Notes.`,
FOLDERS_TO_IGNORE_DESC:
"Enter folder paths or glob patterns on separate lines e.g. Templates Meta/Scripts or **/*.excalidraw.md. This setting is common to both flashcards and notes.",
OBSIDIAN_INTEGRATION: "Integration into Obsidian",
FLASHCARDS: "Lernkarten",
FLASHCARD_EASY_LABEL: "Einfach Knopf Text",
Expand Down
4 changes: 2 additions & 2 deletions src/lang/locale/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ export default {
PROJECT_CONTRIBUTIONS:
'Raise an issue <a href="${issues_url}">here</a> if you have a feature request or a bug-report',
FOLDERS_TO_IGNORE: "Folders to ignore",
FOLDERS_TO_IGNORE_DESC: `Enter folder paths separated by newlines e.g. Templates Meta/Scripts.
Note that this setting is common to both Flashcards and Notes.`,
FOLDERS_TO_IGNORE_DESC:
"Enter folder paths or glob patterns on separate lines e.g. Templates Meta/Scripts or **/*.excalidraw.md. This setting is common to both flashcards and notes.",
OBSIDIAN_INTEGRATION: "Integration into Obsidian",
FLASHCARDS: "Flashcards",
FLASHCARD_EASY_LABEL: "Easy Button Text",
Expand Down
4 changes: 2 additions & 2 deletions src/lang/locale/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ export default {
PROJECT_CONTRIBUTIONS:
'Raise an issue <a href="${issues_url}">here</a> if you have a feature request or a bug-report',
FOLDERS_TO_IGNORE: "Directorios a ignorar",
FOLDERS_TO_IGNORE_DESC: `Escriba las rutas de los directorios separadas por saltos de línea, por ejemplo, Plantillas Extra/Guiones.
Note that this setting is common to both Flashcards and Notes.`,
FOLDERS_TO_IGNORE_DESC:
"Enter folder paths or glob patterns on separate lines e.g. Templates Meta/Scripts or **/*.excalidraw.md. This setting is common to both flashcards and notes.",
OBSIDIAN_INTEGRATION: "Integration into Obsidian",
FLASHCARDS: "Tarjetas de Memorización",
FLASHCARD_EASY_LABEL: "Texto del botón: Fácil",
Expand Down
4 changes: 2 additions & 2 deletions src/lang/locale/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ export default {
PROJECT_CONTRIBUTIONS:
'Créez un ticket <a href="${issues_url}">sur GitHub</a> si vous trouvez un bug ou voulez demander une fonctionnalité',
FOLDERS_TO_IGNORE: "Dossiers à ignorer",
FOLDERS_TO_IGNORE_DESC: `Entrez les chemins des dossiers. Un chemin par ligne, ex. Templates Meta/Scripts.
Ce réglage est le même pour les flashcards et les notes.`,
FOLDERS_TO_IGNORE_DESC:
"Enter folder paths or glob patterns on separate lines e.g. Templates Meta/Scripts or **/*.excalidraw.md. This setting is common to both flashcards and notes.",
OBSIDIAN_INTEGRATION: "Integration into Obsidian",
FLASHCARDS: "Flashcards",
FLASHCARD_EASY_LABEL: "Bouton Facile",
Expand Down
4 changes: 2 additions & 2 deletions src/lang/locale/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ export default {
PROJECT_CONTRIBUTIONS:
'Raise an issue <a href="${issues_url}">here</a> if you have a feature request or a bug-report',
FOLDERS_TO_IGNORE: "Cartelle da ignorare",
FOLDERS_TO_IGNORE_DESC: `Inserisci i percorsi delle cartelle separati da a capo, per esempio, Templates Meta/Scripts.
Note that this setting is common to both Flashcards and Notes.`,
FOLDERS_TO_IGNORE_DESC:
"Enter folder paths or glob patterns on separate lines e.g. Templates Meta/Scripts or **/*.excalidraw.md. This setting is common to both flashcards and notes.",
OBSIDIAN_INTEGRATION: "Integration into Obsidian",
FLASHCARDS: "Schede",
FLASHCARD_EASY_LABEL: "Testo del bottone facile",
Expand Down
4 changes: 2 additions & 2 deletions src/lang/locale/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ export default {
PROJECT_CONTRIBUTIONS:
'Raise an issue <a href="${issues_url}">here</a> if you have a feature request or a bug-report',
FOLDERS_TO_IGNORE: "無視するフォルダ",
FOLDERS_TO_IGNORE_DESC: `フォルダパスを改行で区切って入力してください。"Templates Meta/Scripts" のようなスペースによる区切りでの書き方は無効です。.
Note that this setting is common to both Flashcards and Notes.`,
FOLDERS_TO_IGNORE_DESC:
"Enter folder paths or glob patterns on separate lines e.g. Templates Meta/Scripts or **/*.excalidraw.md. This setting is common to both flashcards and notes.",
OBSIDIAN_INTEGRATION: "Integration into Obsidian",
FLASHCARDS: "フラッシュカード",
FLASHCARD_EASY_LABEL: "Easy Button Text",
Expand Down
4 changes: 2 additions & 2 deletions src/lang/locale/ko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ export default {
PROJECT_CONTRIBUTIONS:
'Raise an issue <a href="${issues_url}">here</a> if you have a feature request or a bug-report',
FOLDERS_TO_IGNORE: "무시할 폴더들",
FOLDERS_TO_IGNORE_DESC: `폴더 경로를 빈 줄로 구분해서 입력해주세요. 'Templates Meta/Scripts' 와 같이 입력하는 것은 유효하지 않습니다.
Note that this setting is common to both Flashcards and Notes.`,
FOLDERS_TO_IGNORE_DESC:
"Enter folder paths or glob patterns on separate lines e.g. Templates Meta/Scripts or **/*.excalidraw.md. This setting is common to both flashcards and notes.",
OBSIDIAN_INTEGRATION: "Integration into Obsidian",
FLASHCARDS: "플래시카드",
FLASHCARD_EASY_LABEL: "Easy Button Text",
Expand Down
4 changes: 2 additions & 2 deletions src/lang/locale/pl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ export default {
PROJECT_CONTRIBUTIONS:
'Raise an issue <a href="${issues_url}">here</a> if you have a feature request or a bug-report',
FOLDERS_TO_IGNORE: "Foldery do zignorowania",
FOLDERS_TO_IGNORE_DESC: `Wprowadź ścieżki folderów oddzielone nowymi liniami, np. Szablony Meta/Scripts.
Note that this setting is common to both Flashcards and Notes.`,
FOLDERS_TO_IGNORE_DESC:
"Enter folder paths or glob patterns on separate lines e.g. Templates Meta/Scripts or **/*.excalidraw.md. This setting is common to both flashcards and notes.",
OBSIDIAN_INTEGRATION: "Integration into Obsidian",
FLASHCARDS: "Fiszki",
FLASHCARD_EASY_LABEL: "Tekst przycisku Łatwe",
Expand Down
4 changes: 2 additions & 2 deletions src/lang/locale/pt-br.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ export default {
PROJECT_CONTRIBUTIONS:
'Raise an issue <a href="${issues_url}">here</a> if you have a feature request or a bug-report',
FOLDERS_TO_IGNORE: "Pastas para ignorar",
FOLDERS_TO_IGNORE_DESC: `Insira o caminho das pastas separado por quebras de linha ex: Templates Meta/Scripts.
Note that this setting is common to both Flashcards and Notes.`,
FOLDERS_TO_IGNORE_DESC:
"Enter folder paths or glob patterns on separate lines e.g. Templates Meta/Scripts or **/*.excalidraw.md. This setting is common to both flashcards and notes.",
OBSIDIAN_INTEGRATION: "Integration into Obsidian",
FLASHCARDS: "Flashcards",
FLASHCARD_EASY_LABEL: "Texto do Botão de Fácil",
Expand Down
4 changes: 2 additions & 2 deletions src/lang/locale/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ export default {
PROJECT_CONTRIBUTIONS:
'Raise an issue <a href="${issues_url}">here</a> if you have a feature request or a bug-report',
FOLDERS_TO_IGNORE: "Игнорируемые папки",
FOLDERS_TO_IGNORE_DESC: `Укажите пути папок, каждый на своей строке, например: Templates Meta/Scripts.
Note that this setting is common to both Flashcards and Notes.`,
FOLDERS_TO_IGNORE_DESC:
"Enter folder paths or glob patterns on separate lines e.g. Templates Meta/Scripts or **/*.excalidraw.md. This setting is common to both flashcards and notes.",
OBSIDIAN_INTEGRATION: "Integration into Obsidian",
FLASHCARDS: "Карточки",
FLASHCARD_EASY_LABEL: 'Текст кнопки "Легко"',
Expand Down
4 changes: 2 additions & 2 deletions src/lang/locale/tr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ export default {
PROJECT_CONTRIBUTIONS:
'Bir özellik isteğiniz ya da hata bildiriminiz varsa <a href="${issues_url}">buradan</a> bildirin.',
FOLDERS_TO_IGNORE: "Yoksayılan Klasörler",
FOLDERS_TO_IGNORE_DESC: `Klasör yollarını yeni satırlarla ayırarak girin, örneğin: Templates Meta/Scripts.
Bu ayarın hem Flash Kartlar hem de Notlar için geçerli olduğunu unutmayın.`,
FOLDERS_TO_IGNORE_DESC:
"Enter folder paths or glob patterns on separate lines e.g. Templates Meta/Scripts or **/*.excalidraw.md. This setting is common to both flashcards and notes.",
OBSIDIAN_INTEGRATION: "Integration into Obsidian",
FLASHCARDS: "Flash Kartlar",
FLASHCARD_EASY_LABEL: "Kolay Butonu Metni",
Expand Down
4 changes: 2 additions & 2 deletions src/lang/locale/zh-cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ export default {
PROJECT_CONTRIBUTIONS:
'Raise an issue <a href="${issues_url}">here</a> if you have a feature request or a bug-report',
FOLDERS_TO_IGNORE: "忽略此文件夹",
FOLDERS_TO_IGNORE_DESC: `输入文件夹路径,用新建行分隔,例如:Templates Meta/Scripts.
Note that this setting is common to both Flashcards and Notes.`,
FOLDERS_TO_IGNORE_DESC:
"Enter folder paths or glob patterns on separate lines e.g. Templates Meta/Scripts or **/*.excalidraw.md. This setting is common to both flashcards and notes.",
OBSIDIAN_INTEGRATION: "Integration into Obsidian",
FLASHCARDS: "卡片",
FLASHCARD_EASY_LABEL: "“简单”按钮文本",
Expand Down
4 changes: 2 additions & 2 deletions src/lang/locale/zh-tw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ export default {
PROJECT_CONTRIBUTIONS:
'Raise an issue <a href="${issues_url}">here</a> if you have a feature request or a bug-report',
FOLDERS_TO_IGNORE: "忽略此資料夾",
FOLDERS_TO_IGNORE_DESC: `輸入資料夾路徑(用換行字元分隔),例如:Templates Meta/Scripts.
Note that this setting is common to both Flashcards and Notes.`,
FOLDERS_TO_IGNORE_DESC:
"Enter folder paths or glob patterns on separate lines e.g. Templates Meta/Scripts or **/*.excalidraw.md. This setting is common to both flashcards and notes.",
OBSIDIAN_INTEGRATION: "Integration into Obsidian",
FLASHCARDS: "卡片",
FLASHCARD_EASY_LABEL: "簡單按鈕文字",
Expand Down
6 changes: 4 additions & 2 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { createTabs, TabStructure } from "src/gui/tabs";
import { t } from "src/lang/helpers";
import type SRPlugin from "src/main";
import { setDebugParser } from "src/parser";
import { pathMatchesPattern } from "src/utils/utils";

export interface SRSettings {
// flashcards
Expand Down Expand Up @@ -123,7 +124,7 @@ export class SettingsUtil {
}

static isPathInNoteIgnoreFolder(settings: SRSettings, path: string): boolean {
return settings.noteFoldersToIgnore.some((folder) => path.startsWith(folder));
return settings.noteFoldersToIgnore.some((folder) => pathMatchesPattern(path, folder));
}

static isAnyTagANoteReviewTag(settings: SRSettings, tags: string[]): boolean {
Expand Down Expand Up @@ -619,7 +620,8 @@ export class SRSettingTab extends PluginSettingTab {
applySettingsUpdate(async () => {
this.plugin.data.settings.noteFoldersToIgnore = value
.split(/\n+/)
.map((v) => v.trim());
.map((v) => v.trim())
.filter((v) => v);
await this.plugin.savePluginData();
});
}),
Expand Down
9 changes: 9 additions & 0 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { minimatch } from "minimatch";
import moment, { Moment } from "moment";
import { sep } from "path";

Expand Down Expand Up @@ -388,3 +389,11 @@ export function parseObsidianFrontmatterTag(tagStr: string): string[] {
}
return result;
}

// This checks if the given path matches the given pattern
// We match based on:
// 1. The `path` starts with `pattern`
// 2. The `path` matches the glob `pattern`
export function pathMatchesPattern(path: string, pattern: string) {
return path.startsWith(pattern) || minimatch(path, pattern);
}
Loading

0 comments on commit 150523b

Please sign in to comment.