1
0

Asset fixes

This commit is contained in:
Zef Hemel 2022-10-14 15:53:51 +02:00
parent 7d28b53b75
commit 3a3210ecac
6 changed files with 27 additions and 15 deletions

View File

@ -5,11 +5,11 @@ export async function readAsset(
name: string,
encoding: "utf8" | "dataurl" = "utf8",
): Promise<string> {
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;
}
}

View File

@ -6,13 +6,25 @@ export async function bundleAssets(
patterns: string[],
): Promise<AssetBundle> {
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,

View File

@ -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();

View File

@ -2,7 +2,7 @@ name: markdown
imports:
- https://get.silverbullet.md/global.plug.json
assets:
- styles.css
- "*.css"
functions:
toggle:
path: "./markdown.ts:togglePreview"

View File

@ -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");
}

View File

@ -1,4 +1,3 @@
<style>
body {
font-family: georgia,times,serif;
font-size: 14pt;