#256 - Support for .loom files for the Dataloom plugin

This commit is contained in:
Simon Cambier
2023-07-15 21:58:22 +02:00
parent 34ef17b4ed
commit afca0694ca
2 changed files with 30 additions and 0 deletions

View File

@@ -10,6 +10,7 @@ import {
getAliasesFromMetadata,
getTagsFromMetadata,
isFileCanvas,
isFileFromDataloomPlugin,
isFilePlaintext,
logDebug,
makeMD5,
@@ -58,6 +59,30 @@ async function getAndMapIndexedDocument(
content = texts.join('\r\n')
}
// ** Dataloom plugin **
else if (isFileFromDataloomPlugin(path)) {
try {
const data = JSON.parse(await app.vault.cachedRead(file))
// data is a json object, we recursively iterate the keys
// and concatenate the values if the key is "markdown"
const texts: string[] = []
const iterate = (obj: any) => {
for (const key in obj) {
if (typeof obj[key] === 'object') {
iterate(obj[key])
} else if (key === 'markdown') {
texts.push(obj[key])
}
}
}
iterate(data)
content = texts.join('\r\n')
} catch (e) {
console.error('Omnisearch: Error while parsing Dataloom file', path)
console.error(e)
}
}
// ** Image or PDF **
else if (extractor?.canFileBeExtracted(path)) {
content = await extractor.extractText(file)

View File

@@ -270,6 +270,7 @@ export function isFileIndexable(path: string): boolean {
return (
isFilePlaintext(path) ||
isFileCanvas(path) ||
isFileFromDataloomPlugin(path) ||
(canIndexPDF && isFilePDF(path)) ||
(canIndexImages && isFileImage(path))
)
@@ -292,6 +293,10 @@ export function isFileCanvas(path: string): boolean {
return path.endsWith('.canvas')
}
export function isFileFromDataloomPlugin(path: string): boolean {
return path.endsWith('.loom')
}
export function getExtension(path: string): string {
const split = path.split('.')
return split[split.length - 1] ?? ''