Skip to content

Commit

Permalink
Added regex file name matching
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonLiur committed Jul 11, 2024
1 parent 91d9d36 commit 875b356
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
23 changes: 21 additions & 2 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ import { loadSummarizationChain } from "langchain/chains";

interface NotesRefresherSettings {
folderPath: string;
notePattern: string;
apiKey: string;
}

const DEFAULT_SETTINGS: NotesRefresherSettings = {
folderPath: "",
notePattern: "",
apiKey: "",
};

Expand All @@ -42,15 +44,18 @@ export default class NotesRefresher extends Plugin {
});
}

onunload() {}
onunload() { }

async getNotesFromFolder(folderPath: string): Promise<TFile[]> {
const folder = this.app.vault.getFolderByPath(folderPath);
const notes: TFile[] = [];
const regexMatcher = new RegExp(this.settings.notePattern);

const traverseFolder = (folder: TFolder) => {
for (const child of folder.children) {
if (child instanceof TFile && child.extension === "md") {
if (child instanceof TFile
&& child.extension === "md"
&& regexMatcher.test(child.basename)) {
notes.push(child);
} else if (child instanceof TFolder) {
traverseFolder(child);
Expand Down Expand Up @@ -153,6 +158,20 @@ class NotesRefresherSettingTab extends PluginSettingTab {
})
);


new Setting(containerEl)
.setName("Note pattern")
.setDesc("[optional] Regex pattern to match for note names")
.addText((text) =>
text
.setPlaceholder("EECS281 (.*)")
.setValue(this.plugin.settings.notePattern)
.onChange(async (value: string) => {
this.plugin.settings.notePattern = value.replace(/\\/g, "\\\\");
await this.plugin.saveSettings();
})
);

new Setting(containerEl)
.setName("OpenAI API key")
.setDesc("API key for OpenAI")
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

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

0 comments on commit 875b356

Please sign in to comment.