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, name: string,
encoding: "utf8" | "dataurl" = "utf8", encoding: "utf8" | "dataurl" = "utf8",
): Promise<string> { ): Promise<string> {
const data = await syscall("asset.readAsset", name); const dataUrl = await syscall("asset.readAsset", name) as string;
switch (encoding) { switch (encoding) {
case "utf8": case "utf8":
return new TextDecoder().decode(base64Decode(data)); return new TextDecoder().decode(base64Decode(dataUrl.split(",")[1]));
case "dataurl": case "dataurl":
return "data:application/octet-stream," + data; return dataUrl;
} }
} }

View File

@ -6,13 +6,25 @@ export async function bundleAssets(
patterns: string[], patterns: string[],
): Promise<AssetBundle> { ): Promise<AssetBundle> {
const bundle = new AssetBundle(); const bundle = new AssetBundle();
if (patterns.length === 0) {
return bundle;
}
const matchRegexes = patterns.map((pat) => globToRegExp(pat));
for await ( for await (
const file of walk(rootPath, { const file of walk(rootPath)
match: patterns.map((pat) => globToRegExp(pat)),
})
) { ) {
const cleanPath = file.path.substring("".length); const cleanPath = file.path.substring(rootPath.length + 1);
await bundle.writeFileSync(cleanPath, await Deno.readFile(file.path)); 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; return bundle;
} }
@ -25,7 +37,7 @@ export async function bundleFolder(rootPath: string, bundlePath: string) {
) { ) {
console.log("Bundling", filePath); console.log("Bundling", filePath);
const cleanPath = filePath.substring(`${rootPath}/`.length); const cleanPath = filePath.substring(`${rootPath}/`.length);
await bundle.writeFileSync(cleanPath, await Deno.readFile(filePath)); bundle.writeFileSync(cleanPath, await Deno.readFile(filePath));
} }
await Deno.writeTextFile( await Deno.writeTextFile(
bundlePath, bundlePath,

View File

@ -26,13 +26,15 @@ export async function bundle(
} }
// Dependencies // 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); manifest.dependencies![name] = await sandboxCompileModule(moduleSpec);
} }
// Assets // Assets
const assetsBundle = await bundleAssets( const assetsBundle = await bundleAssets(
rootPath, path.resolve(rootPath),
manifest.assets as string[] || [], manifest.assets as string[] || [],
); );
manifest.assets = assetsBundle.toJSON(); manifest.assets = assetsBundle.toJSON();

View File

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

View File

@ -13,6 +13,5 @@ export async function togglePreview() {
async function hideMarkdownPreview() { async function hideMarkdownPreview() {
const setting = await readSettings({ previewOnRHS: true }); const setting = await readSettings({ previewOnRHS: true });
const hide = setting.previewOnRHS ? editor.hideRhs : editor.hideLhs; await editor.hidePanel(setting.previewOnRHS ? "rhs" : "lhs");
await hide();
} }

View File

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