Skip to content

Commit

Permalink
#256 - Support for .loom files for the Dataloom plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
scambier committed Jul 15, 2023
1 parent 34ef17b commit afca069
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/cache-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
getAliasesFromMetadata,
getTagsFromMetadata,
isFileCanvas,
isFileFromDataloomPlugin,
isFilePlaintext,
logDebug,
makeMD5,
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions src/tools/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ export function isFileIndexable(path: string): boolean {
return (
isFilePlaintext(path) ||
isFileCanvas(path) ||
isFileFromDataloomPlugin(path) ||
(canIndexPDF && isFilePDF(path)) ||
(canIndexImages && isFileImage(path))
)
Expand All @@ -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] ?? ''
Expand Down

0 comments on commit afca069

Please sign in to comment.