diff --git a/build/lib/playgroundUrlByFramework.js b/build/lib/playgroundUrlByFramework.js index 9d4cf54..cfdd5dd 100644 --- a/build/lib/playgroundUrlByFramework.js +++ b/build/lib/playgroundUrlByFramework.js @@ -92,16 +92,17 @@ export default { return generateURLFromData(data); }, - marko: (contentByFilename) => { - const BASE_URL = "https://markojs.com/playground/#"; - + marko: async (contentByFilename) => { + let firstFile = true; const data = Object.entries(contentByFilename).map(([path, content]) => ({ - name: nodePath.parse(path).base, - path: `/components/${path}`, + path: firstFile ? (firstFile = false) || "index.marko" : path, content, })); - return BASE_URL + compressToURL(JSON.stringify(data)); + return ( + "https://markojs.com/playground#" + + (await markoCompress(JSON.stringify(data))) + ); }, }; @@ -158,3 +159,30 @@ async function compress_and_encode_text(input) { } } } + +// method `compress` from https://github.com/marko-js/website/blob/main/src/util/hasher.ts#L8-L25 +export async function markoCompress(value) { + const stream = new CompressionStream("gzip"); + const writer = stream.writable.getWriter(); + writer.write(new TextEncoder().encode(value)); + writer.close(); + + let result = "v2"; + const reader = stream.readable.getReader(); + try { + while (true) { + const { value, done } = await reader.read(); + if (done) break; + for (const byte of value) { + result += String.fromCharCode(byte); + } + } + + return btoa(result) + .replace(/=+$/, "") + .replace(/\+/g, "-") + .replace(/\//g, "_"); + } finally { + reader.releaseLock(); + } +} diff --git a/content/1-reactivity/1-declare-state/marko/Name.marko b/content/1-reactivity/1-declare-state/marko/Name.marko index 81e0519..b5ae1f5 100644 --- a/content/1-reactivity/1-declare-state/marko/Name.marko +++ b/content/1-reactivity/1-declare-state/marko/Name.marko @@ -1,2 +1,2 @@ - +

Hello ${name}

diff --git a/content/1-reactivity/2-update-state/marko/Name.marko b/content/1-reactivity/2-update-state/marko/Name.marko index d2cfcb4..d56c8e0 100644 --- a/content/1-reactivity/2-update-state/marko/Name.marko +++ b/content/1-reactivity/2-update-state/marko/Name.marko @@ -1,3 +1,3 @@ - - + +

Hello ${name}

diff --git a/content/1-reactivity/3-computed-state/marko/DoubleCount.marko b/content/1-reactivity/3-computed-state/marko/DoubleCount.marko index 6cda107..920a268 100644 --- a/content/1-reactivity/3-computed-state/marko/DoubleCount.marko +++ b/content/1-reactivity/3-computed-state/marko/DoubleCount.marko @@ -1,3 +1,3 @@ - - + +
${doubleCount}
diff --git a/content/2-templating/2-styling/marko/CssStyle.marko b/content/2-templating/2-styling/marko/CssStyle.marko index e186e7c..da95261 100644 --- a/content/2-templating/2-styling/marko/CssStyle.marko +++ b/content/2-templating/2-styling/marko/CssStyle.marko @@ -1,5 +1,5 @@ I am red - +