From a2ff27f511ce29a6fb9b0ed4451b8c7f5cb2b49a Mon Sep 17 00:00:00 2001 From: Evgenii Karagodin Date: Wed, 28 Dec 2022 14:51:55 +0700 Subject: [PATCH] Fixes #129: add "attachment" query source (#239) --- common/spaces/space.ts | 4 +++- plugs/core/attachment.ts | 7 +++++++ plugs/core/core.plug.yaml | 6 ++++++ website/๐Ÿ”Œ Directive/Query.md | 9 +++++---- 4 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 plugs/core/attachment.ts diff --git a/common/spaces/space.ts b/common/spaces/space.ts index 1d62dbf..b320366 100644 --- a/common/spaces/space.ts +++ b/common/spaces/space.ts @@ -180,7 +180,9 @@ export class Space extends EventEmitter { async fetchAttachmentList(): Promise { return (await this.space.fetchFileList()).filter( (fileMeta) => - !fileMeta.name.endsWith(".md") && !fileMeta.name.endsWith(".plug.json"), + !fileMeta.name.endsWith(".md") && + !fileMeta.name.endsWith(".plug.json") && + fileMeta.name !== "data.db", ); } diff --git a/plugs/core/attachment.ts b/plugs/core/attachment.ts new file mode 100644 index 0000000..d1285f8 --- /dev/null +++ b/plugs/core/attachment.ts @@ -0,0 +1,7 @@ +import { QueryProviderEvent } from "$sb/app_event.ts"; +import { applyQuery } from "$sb/lib/query.ts"; +import { space } from "$sb/silverbullet-syscall/mod.ts"; + +export async function attachmentQueryProvider({ query }: QueryProviderEvent) { + return applyQuery(query, await space.listAttachments()); +} diff --git a/plugs/core/core.plug.yaml b/plugs/core/core.plug.yaml index 758c8fa..1c51173 100644 --- a/plugs/core/core.plug.yaml +++ b/plugs/core/core.plug.yaml @@ -66,6 +66,12 @@ functions: command: name: "Editor: Toggle Read Only Mode" + # Attachments + attachmentQueryProvider: + path: ./attachment.ts:attachmentQueryProvider + events: + - query:attachment + # Backlinks indexLinks: path: "./page.ts:indexLinks" diff --git a/website/๐Ÿ”Œ Directive/Query.md b/website/๐Ÿ”Œ Directive/Query.md index 49ce923..620c253 100644 --- a/website/๐Ÿ”Œ Directive/Query.md +++ b/website/๐Ÿ”Œ Directive/Query.md @@ -54,6 +54,7 @@ Start writing ` |name |lastModified |contentType |size|perm|type|repo |uri |author |share-support| @@ -199,10 +200,10 @@ from a visual perspective. **Result:** Here you go. This is the result we would like to achieve ๐ŸŽ‰. Did you see how I used `render` and `template/plug` in a query? ๐Ÿš€ -* [[๐Ÿ”Œ Directive]] +* [[๐Ÿ”Œ Directive]] * [[๐Ÿ”Œ Backlinks]] by **Guillermo Vayรก** ([repo](https://github.com/Willyfrog/silverbullet-backlinks)) -* [[๐Ÿ”Œ Collab]] -* [[๐Ÿ”Œ Tasks]] +* [[๐Ÿ”Œ Collab]] +* [[๐Ÿ”Œ Tasks]] * [[๐Ÿ”Œ Share]]