Merge branch 'master' into svelte

# Conflicts:
#	pnpm-lock.yaml
#	src/main.ts
#	src/modal.ts
This commit is contained in:
Simon Cambier
2022-04-15 17:43:56 +02:00
8 changed files with 19 additions and 43 deletions

View File

@@ -1,7 +1,7 @@
{ {
"id": "scambier.obsidian-omnisearch", "id": "scambier.obsidian-omnisearch",
"name": "Omnisearch", "name": "Omnisearch",
"version": "0.1.6", "version": "0.1.7",
"minAppVersion": "0.14.2", "minAppVersion": "0.14.2",
"description": "Search over organization", "description": "Search over organization",
"author": "Simon Cambier", "author": "Simon Cambier",

View File

@@ -1,6 +1,6 @@
{ {
"name": "scambier.obsidian-search", "name": "scambier.obsidian-search",
"version": "0.1.6", "version": "0.1.7",
"description": "Search over organization", "description": "Search over organization",
"main": "dist/main.js", "main": "dist/main.js",
"scripts": { "scripts": {
@@ -34,7 +34,6 @@
"typescript": "^4.6.3" "typescript": "^4.6.3"
}, },
"dependencies": { "dependencies": {
"markdown-to-txt": "^2.0.0",
"minisearch": "^5.0.0-beta1" "minisearch": "^5.0.0-beta1"
} }
} }

24
pnpm-lock.yaml generated
View File

@@ -14,7 +14,6 @@ specifiers:
eslint-plugin-import: 2.22.1 eslint-plugin-import: 2.22.1
eslint-plugin-node: 11.1.0 eslint-plugin-node: 11.1.0
eslint-plugin-promise: 5.0.0 eslint-plugin-promise: 5.0.0
markdown-to-txt: ^2.0.0
minisearch: ^5.0.0-beta1 minisearch: ^5.0.0-beta1
obsidian: latest obsidian: latest
prettier: ^2.6.2 prettier: ^2.6.2
@@ -25,7 +24,6 @@ specifiers:
typescript: ^4.6.3 typescript: ^4.6.3
dependencies: dependencies:
markdown-to-txt: 2.0.0
minisearch: 5.0.0-beta1 minisearch: 5.0.0-beta1
devDependencies: devDependencies:
@@ -1536,18 +1534,10 @@ packages:
path-exists: 3.0.0 path-exists: 3.0.0
dev: true dev: true
/lodash.escape/4.0.1:
resolution: {integrity: sha1-yQRGkMIeBClL6qUXcS/e0fqI3pg=}
dev: false
/lodash.merge/4.6.2: /lodash.merge/4.6.2:
resolution: {integrity: sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==} resolution: {integrity: sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==}
dev: true dev: true
/lodash.unescape/4.0.1:
resolution: {integrity: sha1-vyJJiGzlFM2hEvrpIYzcBlIR/Jw=}
dev: false
/lodash/4.17.21: /lodash/4.17.21:
resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==} resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==}
dev: true dev: true
@@ -1577,20 +1567,6 @@ packages:
sourcemap-codec: 1.4.8 sourcemap-codec: 1.4.8
dev: true 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: /merge2/1.4.1:
resolution: {integrity: sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==} resolution: {integrity: sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==}
engines: {node: '>= 8'} engines: {node: '>= 8'}

View File

@@ -1,7 +1,7 @@
import { Notice, Plugin, TAbstractFile, TFile } from 'obsidian' import { Notice, Plugin, TAbstractFile, TFile } from 'obsidian'
import MiniSearch from 'minisearch' import MiniSearch from 'minisearch'
import { clearContent, extractHeadingsFromCache, wait } from './utils'
import type { IndexedNote } from './globals' import type { IndexedNote } from './globals'
import { escapeHTML, extractHeadingsFromCache, wait } from './utils'
import { OmnisearchModal } from './modal' import { OmnisearchModal } from './modal'
export default class OmnisearchPlugin extends Plugin { export default class OmnisearchPlugin extends Plugin {
@@ -93,7 +93,7 @@ export default class OmnisearchPlugin extends Plugin {
} }
// Fetch content from the cache, // Fetch content from the cache,
// trim the markdown, remove embeds and clear wikilinks // 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 // Purge HTML before indexing
const tmp = document.createElement('div') const tmp = document.createElement('div')
@@ -102,7 +102,7 @@ export default class OmnisearchPlugin extends Plugin {
// Make the document and index it // Make the document and index it
const note: IndexedNote = { const note: IndexedNote = {
basename: file.basename, basename: file.basename,
content: tmp.innerText, content: tmp.innerText, // content,
path: file.path, path: file.path,
headings1: fileCache headings1: fileCache
? extractHeadingsFromCache(fileCache, 1).join(' ') ? extractHeadingsFromCache(fileCache, 1).join(' ')

View File

@@ -1,8 +1,8 @@
import { MarkdownView, SuggestModal, TFile } from 'obsidian' import { MarkdownView, SuggestModal, TFile } from 'obsidian'
import type { ResultNote } from './globals' import type { ResultNote } from './globals'
import type OmnisearchPlugin from './main' import type OmnisearchPlugin from './main'
import { escapeRegex, getAllIndexes, highlighter } from './utils'
import Component from './Component.svelte' import Component from './Component.svelte'
import { escapeHTML, escapeRegex, getAllIndexes, highlighter } from './utils'
export class OmnisearchModal extends SuggestModal<ResultNote> { export class OmnisearchModal extends SuggestModal<ResultNote> {
private plugin: OmnisearchPlugin private plugin: OmnisearchPlugin
@@ -121,7 +121,9 @@ export class OmnisearchModal extends SuggestModal<ResultNote> {
results.map(async result => { results.map(async result => {
const file = this.app.vault.getAbstractFileByPath(result.id) as TFile const file = this.app.vault.getAbstractFileByPath(result.id) as TFile
// const metadata = this.app.metadataCache.getFileCache(file) // 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 let basename = file.basename
// Sort the terms from smaller to larger // Sort the terms from smaller to larger

View File

@@ -1,4 +1,3 @@
import markdownToTxt from 'markdown-to-txt'
import { CachedMetadata } from 'obsidian' import { CachedMetadata } from 'obsidian'
import { import {
isSearchMatch, isSearchMatch,
@@ -12,12 +11,13 @@ export function highlighter(str: string): string {
return '<span class="search-result-file-matched-text">' + str + '</span>' return '<span class="search-result-file-matched-text">' + str + '</span>'
} }
/** export function escapeHTML(html: string): string {
* Strips the markdown and frontmatter return html
* @param text .replaceAll('&', '&amp;')
*/ .replaceAll('<', '&lt;')
export function clearContent(text: string): string { .replaceAll('>', '&gt;')
return markdownToTxt(removeFrontMatter(text)) .replaceAll('"', '&quot;')
.replaceAll("'", '&#039;')
} }
/** /**

View File

@@ -16,9 +16,7 @@
"isolatedModules": true, "isolatedModules": true,
"lib": [ "lib": [
"DOM", "DOM",
"ES5", "ES2021"
"ES6",
"ES7"
] ]
}, },
"include": [ "include": [

View File

@@ -5,5 +5,6 @@
"0.1.3": "0.14.2", "0.1.3": "0.14.2",
"0.1.4": "0.14.2", "0.1.4": "0.14.2",
"0.1.5": "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"
} }