mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-08 05:39:13 +00:00
Fix PDF setup in Obsidian plugin and force Obsidian configuration for markdown
This commit is contained in:
@@ -161,7 +161,7 @@ export class KhojSearchModal extends SuggestModal<SearchResult> {
|
|||||||
// Open vault file at heading of chosen search result
|
// Open vault file at heading of chosen search result
|
||||||
if (file_match) {
|
if (file_match) {
|
||||||
let resultHeading = file_match.extension !== 'pdf' ? result.entry.split('\n', 1)[0] : '';
|
let resultHeading = file_match.extension !== 'pdf' ? result.entry.split('\n', 1)[0] : '';
|
||||||
let linkToEntry = `${file_match.path}${resultHeading}`
|
let linkToEntry = resultHeading.startsWith('#') ? `${file_match.path}${resultHeading}` : file_match.path;
|
||||||
this.app.workspace.openLinkText(linkToEntry, '');
|
this.app.workspace.openLinkText(linkToEntry, '');
|
||||||
console.log(`Link: ${linkToEntry}, File: ${file_match.path}, Heading: ${resultHeading}`);
|
console.log(`Link: ${linkToEntry}, File: ${file_match.path}, Heading: ${resultHeading}`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { FileSystemAdapter, Notice, RequestUrlParam, request, Vault, Modal } from 'obsidian';
|
import { FileSystemAdapter, Notice, RequestUrlParam, request, Vault, Modal } from 'obsidian';
|
||||||
import { KhojSetting } from 'src/settings'
|
import { KhojSetting } from 'src/settings'
|
||||||
|
import * as fs from 'fs';
|
||||||
|
|
||||||
export function getVaultAbsolutePath(vault: Vault): string {
|
export function getVaultAbsolutePath(vault: Vault): string {
|
||||||
let adaptor = vault.adapter;
|
let adaptor = vault.adapter;
|
||||||
@@ -72,7 +73,9 @@ export async function configureKhojBackend(vault: Vault, setting: KhojSetting, n
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Else if khoj is not configured to index markdown files in configured obsidian vault
|
// Else if khoj is not configured to index markdown files in configured obsidian vault
|
||||||
else if (data["content-type"]["markdown"]["input-filter"].length != 1 ||
|
else if (data["content-type"]["markdown"]["input-filter"] == null ||
|
||||||
|
data["content-type"]["markdown"]["input-files"] != null ||
|
||||||
|
data["content-type"]["markdown"]["input-filter"].length != 1 ||
|
||||||
data["content-type"]["markdown"]["input-filter"][0] !== mdInVault) {
|
data["content-type"]["markdown"]["input-filter"][0] !== mdInVault) {
|
||||||
// Update markdown config in khoj content-type config
|
// Update markdown config in khoj content-type config
|
||||||
// Set markdown config to only index markdown files in configured obsidian vault
|
// Set markdown config to only index markdown files in configured obsidian vault
|
||||||
@@ -88,17 +91,29 @@ export async function configureKhojBackend(vault: Vault, setting: KhojSetting, n
|
|||||||
if (khoj_already_configured && !data["content-type"]["pdf"]) {
|
if (khoj_already_configured && !data["content-type"]["pdf"]) {
|
||||||
// Add pdf config to khoj content-type config
|
// Add pdf config to khoj content-type config
|
||||||
// Set pdf config to index pdf files in configured obsidian vault
|
// Set pdf config to index pdf files in configured obsidian vault
|
||||||
|
|
||||||
|
let pdfs = fs.readdirSync(vaultPath).filter(file => file.endsWith(".pdf"));
|
||||||
|
|
||||||
|
if (pdfs.length > 0) {
|
||||||
data["content-type"]["pdf"] = {
|
data["content-type"]["pdf"] = {
|
||||||
"input-filter": [pdfInVault],
|
"input-filter": [pdfInVault],
|
||||||
"input-files": null,
|
"input-files": null,
|
||||||
"embeddings-file": `${khojDefaultPdfIndexDirectory}/${indexName}.pt`,
|
"embeddings-file": `${khojDefaultPdfIndexDirectory}/${indexName}.pt`,
|
||||||
"compressed-jsonl": `${khojDefaultPdfIndexDirectory}/${indexName}.jsonl.gz`,
|
"compressed-jsonl": `${khojDefaultPdfIndexDirectory}/${indexName}.jsonl.gz`,
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
data["content-type"]["pdf"] = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Else if khoj is not configured to index pdf files in configured obsidian vault
|
// Else if khoj is not configured to index pdf files in configured obsidian vault
|
||||||
else if (khoj_already_configured &&
|
else if (khoj_already_configured &&
|
||||||
(data["content-type"]["pdf"]["input-filter"].length != 1 ||
|
(data["content-type"]["pdf"]["input-filter"] == null ||
|
||||||
|
data["content-type"]["pdf"]["input-filter"].length != 1 ||
|
||||||
data["content-type"]["pdf"]["input-filter"][0] !== pdfInVault)) {
|
data["content-type"]["pdf"]["input-filter"][0] !== pdfInVault)) {
|
||||||
|
|
||||||
|
let pdfs = fs.readdirSync(vaultPath).filter(file => file.endsWith(".pdf"));
|
||||||
|
|
||||||
|
if (pdfs.length > 0) {
|
||||||
// Update pdf config in khoj content-type config
|
// Update pdf config in khoj content-type config
|
||||||
// Set pdf config to only index pdf files in configured obsidian vault
|
// Set pdf config to only index pdf files in configured obsidian vault
|
||||||
let khojPdfIndexDirectory = getIndexDirectoryFromBackendConfig(data["content-type"]["pdf"]["embeddings-file"]);
|
let khojPdfIndexDirectory = getIndexDirectoryFromBackendConfig(data["content-type"]["pdf"]["embeddings-file"]);
|
||||||
@@ -108,6 +123,9 @@ export async function configureKhojBackend(vault: Vault, setting: KhojSetting, n
|
|||||||
"embeddings-file": `${khojPdfIndexDirectory}/${indexName}.pt`,
|
"embeddings-file": `${khojPdfIndexDirectory}/${indexName}.pt`,
|
||||||
"compressed-jsonl": `${khojPdfIndexDirectory}/${indexName}.jsonl.gz`,
|
"compressed-jsonl": `${khojPdfIndexDirectory}/${indexName}.jsonl.gz`,
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
data["content-type"]["pdf"] = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If OpenAI API key not set in Khoj plugin settings
|
// If OpenAI API key not set in Khoj plugin settings
|
||||||
|
|||||||
Reference in New Issue
Block a user