From 3a3210ecac51199b063ff72271785e3814976b9e Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Fri, 14 Oct 2022 15:53:51 +0200 Subject: [PATCH] Asset fixes --- plug-api/plugos-syscall/asset.ts | 6 +++--- plugos/asset_bundle/builder.ts | 24 ++++++++++++++++++------ plugos/bin/plugos-bundle.ts | 6 ++++-- plugs/markdown/markdown.plug.yaml | 2 +- plugs/markdown/markdown.ts | 3 +-- plugs/markdown/styles.css | 1 - 6 files changed, 27 insertions(+), 15 deletions(-) diff --git a/plug-api/plugos-syscall/asset.ts b/plug-api/plugos-syscall/asset.ts index a709989..f4b799e 100644 --- a/plug-api/plugos-syscall/asset.ts +++ b/plug-api/plugos-syscall/asset.ts @@ -5,11 +5,11 @@ export async function readAsset( name: string, encoding: "utf8" | "dataurl" = "utf8", ): Promise { - const data = await syscall("asset.readAsset", name); + const dataUrl = await syscall("asset.readAsset", name) as string; switch (encoding) { case "utf8": - return new TextDecoder().decode(base64Decode(data)); + return new TextDecoder().decode(base64Decode(dataUrl.split(",")[1])); case "dataurl": - return "data:application/octet-stream," + data; + return dataUrl; } } diff --git a/plugos/asset_bundle/builder.ts b/plugos/asset_bundle/builder.ts index 6d84b95..a1a967b 100644 --- a/plugos/asset_bundle/builder.ts +++ b/plugos/asset_bundle/builder.ts @@ -6,13 +6,25 @@ export async function bundleAssets( patterns: string[], ): Promise { const bundle = new AssetBundle(); + if (patterns.length === 0) { + return bundle; + } + const matchRegexes = patterns.map((pat) => globToRegExp(pat)); for await ( - const file of walk(rootPath, { - match: patterns.map((pat) => globToRegExp(pat)), - }) + const file of walk(rootPath) ) { - const cleanPath = file.path.substring("".length); - await bundle.writeFileSync(cleanPath, await Deno.readFile(file.path)); + const cleanPath = file.path.substring(rootPath.length + 1); + let match = false; + // console.log("Considering", rootPath, file.path, cleanPath); + for (const matchRegex of matchRegexes) { + if (matchRegex.test(cleanPath)) { + match = true; + break; + } + } + if (match) { + bundle.writeFileSync(cleanPath, await Deno.readFile(file.path)); + } } return bundle; } @@ -25,7 +37,7 @@ export async function bundleFolder(rootPath: string, bundlePath: string) { ) { console.log("Bundling", filePath); const cleanPath = filePath.substring(`${rootPath}/`.length); - await bundle.writeFileSync(cleanPath, await Deno.readFile(filePath)); + bundle.writeFileSync(cleanPath, await Deno.readFile(filePath)); } await Deno.writeTextFile( bundlePath, diff --git a/plugos/bin/plugos-bundle.ts b/plugos/bin/plugos-bundle.ts index a922683..9b204b1 100755 --- a/plugos/bin/plugos-bundle.ts +++ b/plugos/bin/plugos-bundle.ts @@ -26,13 +26,15 @@ export async function bundle( } // Dependencies - for (let [name, moduleSpec] of Object.entries(manifest.dependencies || {})) { + for ( + const [name, moduleSpec] of Object.entries(manifest.dependencies || {}) + ) { manifest.dependencies![name] = await sandboxCompileModule(moduleSpec); } // Assets const assetsBundle = await bundleAssets( - rootPath, + path.resolve(rootPath), manifest.assets as string[] || [], ); manifest.assets = assetsBundle.toJSON(); diff --git a/plugs/markdown/markdown.plug.yaml b/plugs/markdown/markdown.plug.yaml index b4fedd8..0d579f7 100644 --- a/plugs/markdown/markdown.plug.yaml +++ b/plugs/markdown/markdown.plug.yaml @@ -2,7 +2,7 @@ name: markdown imports: - https://get.silverbullet.md/global.plug.json assets: - - styles.css + - "*.css" functions: toggle: path: "./markdown.ts:togglePreview" diff --git a/plugs/markdown/markdown.ts b/plugs/markdown/markdown.ts index e3cd7b0..69c043f 100644 --- a/plugs/markdown/markdown.ts +++ b/plugs/markdown/markdown.ts @@ -13,6 +13,5 @@ export async function togglePreview() { async function hideMarkdownPreview() { const setting = await readSettings({ previewOnRHS: true }); - const hide = setting.previewOnRHS ? editor.hideRhs : editor.hideLhs; - await hide(); + await editor.hidePanel(setting.previewOnRHS ? "rhs" : "lhs"); } diff --git a/plugs/markdown/styles.css b/plugs/markdown/styles.css index e4dd9c7..43b84c6 100644 --- a/plugs/markdown/styles.css +++ b/plugs/markdown/styles.css @@ -1,4 +1,3 @@ -