Merge branch 'master' into svelte
# Conflicts: # pnpm-lock.yaml # src/main.ts # src/modal.ts
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "scambier.obsidian-omnisearch",
|
||||
"name": "Omnisearch",
|
||||
"version": "0.1.6",
|
||||
"version": "0.1.7",
|
||||
"minAppVersion": "0.14.2",
|
||||
"description": "Search over organization",
|
||||
"author": "Simon Cambier",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "scambier.obsidian-search",
|
||||
"version": "0.1.6",
|
||||
"version": "0.1.7",
|
||||
"description": "Search over organization",
|
||||
"main": "dist/main.js",
|
||||
"scripts": {
|
||||
@@ -34,7 +34,6 @@
|
||||
"typescript": "^4.6.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"markdown-to-txt": "^2.0.0",
|
||||
"minisearch": "^5.0.0-beta1"
|
||||
}
|
||||
}
|
||||
24
pnpm-lock.yaml
generated
24
pnpm-lock.yaml
generated
@@ -14,7 +14,6 @@ specifiers:
|
||||
eslint-plugin-import: 2.22.1
|
||||
eslint-plugin-node: 11.1.0
|
||||
eslint-plugin-promise: 5.0.0
|
||||
markdown-to-txt: ^2.0.0
|
||||
minisearch: ^5.0.0-beta1
|
||||
obsidian: latest
|
||||
prettier: ^2.6.2
|
||||
@@ -25,7 +24,6 @@ specifiers:
|
||||
typescript: ^4.6.3
|
||||
|
||||
dependencies:
|
||||
markdown-to-txt: 2.0.0
|
||||
minisearch: 5.0.0-beta1
|
||||
|
||||
devDependencies:
|
||||
@@ -1536,18 +1534,10 @@ packages:
|
||||
path-exists: 3.0.0
|
||||
dev: true
|
||||
|
||||
/lodash.escape/4.0.1:
|
||||
resolution: {integrity: sha1-yQRGkMIeBClL6qUXcS/e0fqI3pg=}
|
||||
dev: false
|
||||
|
||||
/lodash.merge/4.6.2:
|
||||
resolution: {integrity: sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==}
|
||||
dev: true
|
||||
|
||||
/lodash.unescape/4.0.1:
|
||||
resolution: {integrity: sha1-vyJJiGzlFM2hEvrpIYzcBlIR/Jw=}
|
||||
dev: false
|
||||
|
||||
/lodash/4.17.21:
|
||||
resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==}
|
||||
dev: true
|
||||
@@ -1577,20 +1567,6 @@ packages:
|
||||
sourcemap-codec: 1.4.8
|
||||
dev: true
|
||||
|
||||
/markdown-to-txt/2.0.0:
|
||||
resolution: {integrity: sha512-H5DSAY6frUQ6/CR0nJMlGCEuSA3pvi14dYfICJPKLAvd/rDk6eb+cj84zU5XTNYzECyCcujoAL1PHhjmOgeqUw==}
|
||||
dependencies:
|
||||
lodash.escape: 4.0.1
|
||||
lodash.unescape: 4.0.1
|
||||
marked: 3.0.8
|
||||
dev: false
|
||||
|
||||
/marked/3.0.8:
|
||||
resolution: {integrity: sha512-0gVrAjo5m0VZSJb4rpL59K1unJAMb/hm8HRXqasD8VeC8m91ytDPMritgFSlKonfdt+rRYYpP/JfLxgIX8yoSw==}
|
||||
engines: {node: '>= 12'}
|
||||
hasBin: true
|
||||
dev: false
|
||||
|
||||
/merge2/1.4.1:
|
||||
resolution: {integrity: sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==}
|
||||
engines: {node: '>= 8'}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Notice, Plugin, TAbstractFile, TFile } from 'obsidian'
|
||||
import MiniSearch from 'minisearch'
|
||||
import { clearContent, extractHeadingsFromCache, wait } from './utils'
|
||||
import type { IndexedNote } from './globals'
|
||||
import { escapeHTML, extractHeadingsFromCache, wait } from './utils'
|
||||
import { OmnisearchModal } from './modal'
|
||||
|
||||
export default class OmnisearchPlugin extends Plugin {
|
||||
@@ -93,7 +93,7 @@ export default class OmnisearchPlugin extends Plugin {
|
||||
}
|
||||
// Fetch content from the cache,
|
||||
// trim the markdown, remove embeds and clear wikilinks
|
||||
const content = clearContent(await this.app.vault.cachedRead(file))
|
||||
const content = escapeHTML(await this.app.vault.cachedRead(file))
|
||||
|
||||
// Purge HTML before indexing
|
||||
const tmp = document.createElement('div')
|
||||
@@ -102,7 +102,7 @@ export default class OmnisearchPlugin extends Plugin {
|
||||
// Make the document and index it
|
||||
const note: IndexedNote = {
|
||||
basename: file.basename,
|
||||
content: tmp.innerText,
|
||||
content: tmp.innerText, // content,
|
||||
path: file.path,
|
||||
headings1: fileCache
|
||||
? extractHeadingsFromCache(fileCache, 1).join(' ')
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { MarkdownView, SuggestModal, TFile } from 'obsidian'
|
||||
import type { ResultNote } from './globals'
|
||||
import type OmnisearchPlugin from './main'
|
||||
import { escapeRegex, getAllIndexes, highlighter } from './utils'
|
||||
import Component from './Component.svelte'
|
||||
import { escapeHTML, escapeRegex, getAllIndexes, highlighter } from './utils'
|
||||
|
||||
export class OmnisearchModal extends SuggestModal<ResultNote> {
|
||||
private plugin: OmnisearchPlugin
|
||||
@@ -121,7 +121,9 @@ export class OmnisearchModal extends SuggestModal<ResultNote> {
|
||||
results.map(async result => {
|
||||
const file = this.app.vault.getAbstractFileByPath(result.id) as TFile
|
||||
// const metadata = this.app.metadataCache.getFileCache(file)
|
||||
let content = (await this.app.vault.cachedRead(file)).toLowerCase()
|
||||
let content = escapeHTML(
|
||||
await this.app.vault.cachedRead(file),
|
||||
).toLowerCase()
|
||||
let basename = file.basename
|
||||
|
||||
// Sort the terms from smaller to larger
|
||||
|
||||
14
src/utils.ts
14
src/utils.ts
@@ -1,4 +1,3 @@
|
||||
import markdownToTxt from 'markdown-to-txt'
|
||||
import { CachedMetadata } from 'obsidian'
|
||||
import {
|
||||
isSearchMatch,
|
||||
@@ -12,12 +11,13 @@ export function highlighter(str: string): string {
|
||||
return '<span class="search-result-file-matched-text">' + str + '</span>'
|
||||
}
|
||||
|
||||
/**
|
||||
* Strips the markdown and frontmatter
|
||||
* @param text
|
||||
*/
|
||||
export function clearContent(text: string): string {
|
||||
return markdownToTxt(removeFrontMatter(text))
|
||||
export function escapeHTML(html: string): string {
|
||||
return html
|
||||
.replaceAll('&', '&')
|
||||
.replaceAll('<', '<')
|
||||
.replaceAll('>', '>')
|
||||
.replaceAll('"', '"')
|
||||
.replaceAll("'", ''')
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,9 +16,7 @@
|
||||
"isolatedModules": true,
|
||||
"lib": [
|
||||
"DOM",
|
||||
"ES5",
|
||||
"ES6",
|
||||
"ES7"
|
||||
"ES2021"
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
|
||||
@@ -5,5 +5,6 @@
|
||||
"0.1.3": "0.14.2",
|
||||
"0.1.4": "0.14.2",
|
||||
"0.1.5": "0.14.2",
|
||||
"0.1.6": "0.14.2"
|
||||
"0.1.6": "0.14.2",
|
||||
"0.1.7": "0.14.2"
|
||||
}
|
||||
Reference in New Issue
Block a user