Overwrite existing PDFs in Obsidian as well, make if-block more legible

This commit is contained in:
sabaimran 2023-07-02 16:17:25 -07:00
parent 4b02a8c788
commit eff1436857

View file

@ -73,8 +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"] == null || else if (
data["content-type"]["markdown"]["input-files"] != null || data["content-type"]["markdown"]["input-files"] != null ||
data["content-type"]["markdown"]["input-filter"] == null ||
data["content-type"]["markdown"]["input-filter"].length != 1 || 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
@ -89,12 +90,9 @@ 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 const hasPdfFiles = app.vault.getFiles().some(file => file.extension === 'pdf');
// Set pdf config to index pdf files in configured obsidian vault
let pdfs = fs.readdirSync(vaultPath).filter(file => file.endsWith(".pdf")); if (hasPdfFiles) {
if (pdfs.length > 0) {
data["content-type"]["pdf"] = { data["content-type"]["pdf"] = {
"input-filter": [pdfInVault], "input-filter": [pdfInVault],
"input-files": null, "input-files": null,
@ -107,7 +105,9 @@ export async function configureKhojBackend(vault: Vault, setting: KhojSetting, n
} }
// 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"] == null || (
data["content-type"]["pdf"]["input-files"] != null ||
data["content-type"]["pdf"]["input-filter"] == null ||
data["content-type"]["pdf"]["input-filter"].length != 1 || data["content-type"]["pdf"]["input-filter"].length != 1 ||
data["content-type"]["pdf"]["input-filter"][0] !== pdfInVault)) { data["content-type"]["pdf"]["input-filter"][0] !== pdfInVault)) {