import { Setting } from 'obsidian' import type { LocatorSettings } from './utils' import { saveSettings } from './utils' import { htmlDescription } from './utils' import type LocatorPlugin from 'src/main' import { debounce } from 'lodash-es' export function injectSettingsIndexing( plugin: LocatorPlugin, settings: LocatorSettings, containerEl: HTMLElement ) { const textExtractor = plugin.getTextExtractor() const aiImageAnalyzer = plugin.getAIImageAnalyzer() const database = plugin.database const clearCacheDebounced = debounce(async () => { await database.clearCache() }, 1000) new Setting(containerEl) .setName('Indexing') .setHeading() .setDesc( htmlDescription(`⚠️ Changing indexing settings will clear the cache, and requires a restart of Obsidian.

${ textExtractor ? `👍 You have installed Text Extractor, Locator can use it to index PDFs and images contents.
Text extraction only works on desktop, but the cache can be synchronized with your mobile device.` : `⚠️ Locator requires Text Extractor to index PDFs and images.` } ${ aiImageAnalyzer ? `
👍 You have installed AI Image Analyzer, Locator can use it to index images contents with ai.` : `
⚠️ Locator requires AI Image Analyzer to index images with ai.` }`) ) // PDF Indexing new Setting(containerEl) .setName(`PDFs content indexing ${textExtractor ? '' : '⚠️ Disabled'}`) .setDesc( htmlDescription( `Locator will use Text Extractor to index the content of your PDFs.` ) ) .addToggle(toggle => toggle.setValue(settings.PDFIndexing).onChange(async v => { await database.clearCache() settings.PDFIndexing = v await saveSettings(plugin) }) ) .setDisabled(!textExtractor) // Images Indexing new Setting(containerEl) .setName(`Images OCR indexing ${textExtractor ? '' : '⚠️ Disabled'}`) .setDesc( htmlDescription( `Locator will use Text Extractor to OCR your images and index their content.` ) ) .addToggle(toggle => toggle.setValue(settings.imagesIndexing).onChange(async v => { await database.clearCache() settings.imagesIndexing = v await saveSettings(plugin) }) ) .setDisabled(!textExtractor) // Office Documents Indexing const indexOfficesDesc = new DocumentFragment() indexOfficesDesc.createSpan({}, span => { span.innerHTML = `Locator will use Text Extractor to index the content of your office documents (currently
.docx
and
.xlsx
).` }) new Setting(containerEl) .setName(`Documents content indexing ${textExtractor ? '' : '⚠️ Disabled'}`) .setDesc(indexOfficesDesc) .addToggle(toggle => toggle.setValue(settings.officeIndexing).onChange(async v => { await database.clearCache() settings.officeIndexing = v await saveSettings(plugin) }) ) .setDisabled(!textExtractor) // AI Images Indexing const aiIndexImagesDesc = new DocumentFragment() aiIndexImagesDesc.createSpan({}, span => { span.innerHTML = `Locator will use AI Image Analyzer to index the content of your images with ai.` }) new Setting(containerEl) .setName(`Images AI indexing ${aiImageAnalyzer ? '' : '⚠️ Disabled'}`) .setDesc(aiIndexImagesDesc) .addToggle(toggle => toggle.setValue(settings.aiImageIndexing).onChange(async v => { await database.clearCache() settings.aiImageIndexing = v await saveSettings(plugin) }) ) .setDisabled(!aiImageAnalyzer) // Index filenames of unsupported files new Setting(containerEl) .setName('Index paths of unsupported files') .setDesc( htmlDescription(` Locator can index filenames of "unsupported" files, such as e.g.
.mp4
or non-extracted PDFs & images.
"Obsidian setting" will respect the value of "Files & Links > Detect all file extensions".`) ) .addDropdown(dropdown => { dropdown .addOptions({ yes: 'Yes', no: 'No', default: 'Obsidian setting' }) .setValue(settings.unsupportedFilesIndexing) .onChange(async v => { await clearCacheDebounced() ;(settings.unsupportedFilesIndexing as any) = v await saveSettings(plugin) }) }) // Custom display title new Setting(containerEl) .setName('Set frontmatter property key as title') .setDesc( htmlDescription(`If you have a custom property in your notes that you want to use as the title in search results. If you set this to '#heading', then use the first heading from a file as the title.
Leave empty to disable.`) ) .addText(component => { component.setValue(settings.displayTitle).onChange(async v => { await clearCacheDebounced() settings.displayTitle = v await saveSettings(plugin) }) }) // Additional text files to index new Setting(containerEl) .setName('Additional TEXT files to index') .setDesc( htmlDescription(`In addition to standard md files, Locator can also index other PLAINTEXT files.
Add extensions separated by a space, without the dot. Example: "txt org csv".
⚠️ Using extensions of non-plaintext files (like .pptx) WILL cause crashes, because Locator will try to index their content.`) ) .addText(component => { component .setValue(settings.indexedFileTypes.join(' ')) .setPlaceholder('Example: txt org csv') .onChange(async v => { await database.clearCache() settings.indexedFileTypes = v.split(' ') await saveSettings(plugin) }) }) }