From 4407e23c197622878ac20c2677cad6b3499cef03 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Wed, 11 Jan 2023 03:03:22 -0300 Subject: [PATCH] Only index current vault on Khoj. Remove plugin setting to configure it - Overview Limits using Khoj with a single vault at a time. This is automatically configured to the most recently opened vault. Once directory filters are supported on backend, the plugin will be updated to index multiple vault but search only current vault from current vaults khoj obsidian plugin - Code Details - Remove setting to configure Vault directory from Khoj Obsidian plugin - Automatically configure Khoj to index only current Vault. - Overwrites any previous vaults that were intended to be indexed by Khoj backend - Force update of index after configuring vault - Why It's not helpful for now and can lead to more problems, confusion. Once directory filters --- src/interface/obsidian/src/settings.ts | 12 ------------ src/interface/obsidian/src/utils.ts | 8 ++++---- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/src/interface/obsidian/src/settings.ts b/src/interface/obsidian/src/settings.ts index a551942a..f2ce5a56 100644 --- a/src/interface/obsidian/src/settings.ts +++ b/src/interface/obsidian/src/settings.ts @@ -1,18 +1,15 @@ import { App, Notice, PluginSettingTab, request, Setting } from 'obsidian'; import Khoj from 'src/main'; -import { getVaultAbsolutePath } from 'src/utils'; export interface KhojSetting { resultsCount: number; khojUrl: string; - obsidianVaultPath: string; connectedToBackend: boolean; } export const DEFAULT_SETTINGS: KhojSetting = { resultsCount: 6, khojUrl: 'http://localhost:8000', - obsidianVaultPath: getVaultAbsolutePath(), connectedToBackend: false, } @@ -32,15 +29,6 @@ export class KhojSettingTab extends PluginSettingTab { containerEl.createEl('small', { text: this.getBackendStatusMessage() }); // Add khoj settings configurable from the plugin settings tab - new Setting(containerEl) - .setName('Vault Path') - .setDesc('The Obsidian Vault to search with Khoj') - .addText(text => text - .setValue(`${this.plugin.settings.obsidianVaultPath}`) - .onChange(async (value) => { - this.plugin.settings.obsidianVaultPath = value; - await this.plugin.saveSettings(); - })); new Setting(containerEl) .setName('Khoj URL') .setDesc('The URL of the Khoj backend') diff --git a/src/interface/obsidian/src/utils.ts b/src/interface/obsidian/src/utils.ts index 10d08b3e..7c1cf7df 100644 --- a/src/interface/obsidian/src/utils.ts +++ b/src/interface/obsidian/src/utils.ts @@ -10,7 +10,7 @@ export function getVaultAbsolutePath(): string { } export async function configureKhojBackend(setting: KhojSetting, notify: boolean = true) { - let mdInVault = `${setting.obsidianVaultPath}/**/*.md`; + let mdInVault = `${getVaultAbsolutePath()}/**/*.md`; let khojConfigUrl = `${setting.khojUrl}/api/config/data`; // Check if khoj backend is configured, show error if backend is not running @@ -34,7 +34,7 @@ export async function configureKhojBackend(setting: KhojSetting, notify: boolean // If khoj backend not configured yet if (!khoj_already_configured) { // Create khoj content-type config with only markdown configured - let khojObsidianPluginPath = `${setting.obsidianVaultPath}/${this.app.vault.configDir}/plugins/khoj/`; + let khojObsidianPluginPath = `${getVaultAbsolutePath()}/${this.app.vault.configDir}/plugins/khoj/`; data["content-type"] = { "markdown": { "input-filter": [mdInVault], @@ -55,7 +55,7 @@ export async function configureKhojBackend(setting: KhojSetting, notify: boolean else if (!data["content-type"]["markdown"]) { // Add markdown config to khoj content-type config // Set markdown config to index markdown files in configured obsidian vault - let khojObsidianPluginPath = `${setting.obsidianVaultPath}/${this.app.vault.configDir}/plugins/khoj/`; + let khojObsidianPluginPath = `${getVaultAbsolutePath()}/${this.app.vault.configDir}/plugins/khoj/`; data["content-type"]["markdown"] = { "input-filter": [mdInVault], "input-files": null, @@ -99,5 +99,5 @@ export async function updateKhojBackend(khojUrl: string, khojConfig: Object) { // Save khojConfig on khoj backend at khojConfigUrl await request(requestContent) // Refresh khoj search index after updating config - .then(_ => request(`${khojUrl}/api/update?t=markdown`)); + .then(_ => request(`${khojUrl}/api/update?t=markdown&force=true`)); }