Added pageNamespace hook support
This commit is contained in:
@@ -8,3 +8,19 @@ functions:
|
||||
path: ./search.ts:queryProvider
|
||||
events:
|
||||
- query:full-text
|
||||
searchCommand:
|
||||
path: ./search.ts:searchCommand
|
||||
command:
|
||||
name: "Search Space"
|
||||
key: Ctrl-Shift-f
|
||||
mac: Cmd-Shift-f
|
||||
readPageSearch:
|
||||
path: ./search.ts:readPageSearch
|
||||
pageNamespace:
|
||||
pattern: "@search/.+"
|
||||
operation: readPage
|
||||
getPageMetaSearch:
|
||||
path: ./search.ts:getPageMetaSearch
|
||||
pageNamespace:
|
||||
pattern: "@search/.+"
|
||||
operation: getPageMeta
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import { fullTextIndex, fullTextSearch } from "@plugos/plugos-syscall/fulltext";
|
||||
import { renderToText } from "@silverbulletmd/common/tree";
|
||||
import { PageMeta } from "@silverbulletmd/common/types";
|
||||
import { scanPrefixGlobal } from "@silverbulletmd/plugos-silverbullet-syscall";
|
||||
import {
|
||||
navigate,
|
||||
prompt,
|
||||
} from "@silverbulletmd/plugos-silverbullet-syscall/editor";
|
||||
import { IndexTreeEvent } from "@silverbulletmd/web/app_event";
|
||||
import { applyQuery, QueryProviderEvent } from "../query/engine";
|
||||
import { removeQueries } from "../query/util";
|
||||
@@ -38,3 +43,37 @@ export async function queryProvider({
|
||||
results = applyQuery(query, results);
|
||||
return results;
|
||||
}
|
||||
|
||||
export async function searchCommand() {
|
||||
let phrase = await prompt("Search for: ");
|
||||
if (phrase) {
|
||||
await navigate(`@search/${phrase}`);
|
||||
}
|
||||
}
|
||||
|
||||
export async function readPageSearch(
|
||||
name: string
|
||||
): Promise<{ text: string; meta: PageMeta }> {
|
||||
let phrase = name.substring("@search/".length);
|
||||
let results = await fullTextSearch(phrase, 100);
|
||||
const text = `# Search results for "${phrase}"\n${results
|
||||
.map((r: any) => `* [[${r.name}]] (score: ${r.rank})`)
|
||||
.join("\n")}
|
||||
`;
|
||||
return {
|
||||
text: text,
|
||||
meta: {
|
||||
name,
|
||||
lastModified: 0,
|
||||
perm: "ro",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export async function getPageMetaSearch(name: string): Promise<PageMeta> {
|
||||
return {
|
||||
name,
|
||||
lastModified: 0,
|
||||
perm: "ro",
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user