Skip to content
Open
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ The script needs to be able to:

Current features (check out the wiki for more details):
* **Custom note types** - You're not limited to the 6 built-in note types of Anki.
* **Custom scan directory**
* **Custom scan directories**
* The plugin will scan the entire vault by default
* You can also set which directory (includes all sub-directories as well) to scan via plugin settings
* You can also set which directories (includes all sub-directories as well) to scan via plugin settings
* **Ignore Folders and Files**
* You can specify which files and folders to ignore
* This can be done in the settings of this plugin with [Glob syntax](https://en.wikipedia.org/wiki/Glob_(programming)#Syntax).
Expand Down
20 changes: 11 additions & 9 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default class MyPlugin extends Plugin {
"Frozen Fields Line": "FROZEN"
},
Defaults: {
"Scan Directory": "",
"Scan Directories": [],
"Tag": "Obsidian_to_Anki",
"Deck": "Default",
"Scheduling Interval": 0,
Expand Down Expand Up @@ -195,16 +195,18 @@ export default class MyPlugin extends Plugin {
}
new Notice("Successfully connected to Anki! This could take a few minutes - please don't close Anki until the plugin is finished")
const data: ParsedSettings = await settingToData(this.app, this.settings, this.fields_dict)
const scanDir = this.app.vault.getAbstractFileByPath(this.settings.Defaults["Scan Directory"])
const scanDirs = this.settings.Defaults["Scan Directories"];
let manager = null;
if (scanDir !== null) {
if (scanDirs && scanDirs.length > 0) {
let markdownFiles = [];
if (scanDir instanceof TFolder) {
console.info("Using custom scan directory: " + scanDir.path)
markdownFiles = this.getAllTFilesInFolder(scanDir);
} else {
new Notice("Error: incorrect path for scan directory " + this.settings.Defaults["Scan Directory"])
return
for (const dirPath of scanDirs) {
const scanDir = this.app.vault.getAbstractFileByPath(dirPath);
if (scanDir instanceof TFolder) {
console.info("Using custom scan directory: " + scanDir.path)
markdownFiles.push(...this.getAllTFilesInFolder(scanDir));
} else {
new Notice("Error: incorrect path for scan directory " + dirPath)
}
}
manager = new FileManager(this.app, data, markdownFiles, this.file_hashes, this.added_media)
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/settings-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface PluginSettings {
"Frozen Fields Line": string
},
Defaults: {
"Scan Directory": string,
"Scan Directories": string[],
"Tag": string,
"Deck": string,
"Scheduling Interval": number
Expand Down
38 changes: 33 additions & 5 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { PluginSettingTab, Setting, Notice, TFolder } from 'obsidian'
import * as AnkiConnect from './anki'

const defaultDescs = {
"Scan Directory": "The directory to scan. Leave empty to scan the entire vault",
"Scan Directories": "The directories to scan. Leave empty to scan the entire vault. One path per line.",
"Tag": "The tag that the plugin automatically adds to any generated cards.",
"Deck": "The deck the plugin adds cards to if TARGET DECK is not specified in the file.",
"Scheduling Interval": "The time, in minutes, between automatic scans of the vault. Set this to 0 to disable automatic scanning.",
Expand Down Expand Up @@ -175,10 +175,22 @@ export class SettingsTab extends PluginSettingTab {
const plugin = (this as any).plugin
let defaults_settings = containerEl.createEl('h3', {text: 'Defaults'})

// To account for new scan directory
if (!(plugin.settings["Defaults"].hasOwnProperty("Scan Directory"))) {
plugin.settings["Defaults"]["Scan Directory"] = ""
// Migration from old setting
if (plugin.settings["Defaults"].hasOwnProperty("Scan Directory")) {
const oldValue = plugin.settings["Defaults"]["Scan Directory"];
if (typeof oldValue === 'string' && oldValue.trim() !== '') {
plugin.settings["Defaults"]["Scan Directories"] = [oldValue];
} else {
plugin.settings["Defaults"]["Scan Directories"] = [];
}
delete plugin.settings["Defaults"]["Scan Directory"];
plugin.saveAllData();
}

if (!(plugin.settings["Defaults"].hasOwnProperty("Scan Directories"))) {
plugin.settings["Defaults"]["Scan Directories"] = []
}

// To account for new add context
if (!(plugin.settings["Defaults"].hasOwnProperty("Add Context"))) {
plugin.settings["Defaults"]["Add Context"] = false
Expand All @@ -195,9 +207,25 @@ export class SettingsTab extends PluginSettingTab {
if (!(plugin.settings["Defaults"].hasOwnProperty("Add Obsidian Tags"))) {
plugin.settings["Defaults"]["Add Obsidian Tags"] = false
}

new Setting(defaults_settings)
.setName("Scan Directories")
.setDesc(defaultDescs["Scan Directories"])
.addTextArea(text => {
text.setValue(plugin.settings.Defaults["Scan Directories"].join("\n"))
.setPlaceholder("path/to/folder1\npath/to/folder2")
.onChange((value) => {
let scanDirs = value.split("\n").map(dir => dir.trim()).filter(dir => dir !== "");
plugin.settings.Defaults["Scan Directories"] = scanDirs;
plugin.saveAllData();
})
text.inputEl.rows = 5;
text.inputEl.cols = 30;
});

for (let key of Object.keys(plugin.settings["Defaults"])) {
// To account for removal of regex setting
if (key === "Regex") {
if (key === "Regex" || key === "Scan Directories") {
continue
}
if (typeof plugin.settings["Defaults"][key] === "string") {
Expand Down