From 886fdcd1d349beaa3fcff7483b9ed17ed17967fe Mon Sep 17 00:00:00 2001 From: Luke LaValva Date: Sat, 13 Sep 2025 04:50:14 -0700 Subject: [PATCH] feat(marko): udpate examples for v6 (#299) --- build/lib/playgroundUrlByFramework.js | 40 ++++++++++++++++--- .../1-declare-state/marko/Name.marko | 2 +- .../2-update-state/marko/Name.marko | 4 +- .../3-computed-state/marko/DoubleCount.marko | 4 +- .../2-styling/marko/CssStyle.marko | 2 +- .../4-event-click/marko/Counter.marko | 2 +- .../5-dom-ref/marko/InputFocused.marko | 4 +- .../6-conditional/marko/TrafficLight.marko | 6 +-- .../1-on-mount/marko/PageTitle.marko | 4 +- .../3-lifecycle/2-on-unmount/marko/Time.marko | 10 ++--- .../1-props/marko/UserProfile.marko | 2 +- .../2-emit-to-parent/marko/App.marko | 4 +- .../3-slot/marko/FunnyButton.marko | 6 +-- .../4-slot-fallback/marko/FunnyButton.marko | 6 +-- .../5-context/marko/App.marko | 10 ++--- .../5-context/marko/UserProfile.marko | 2 +- .../1-input-text/marko/InputHello.marko | 4 +- .../2-checkbox/marko/IsAvailable.marko | 2 +- .../6-form-input/3-radio/marko/PickPill.marko | 15 +++---- .../4-select/marko/ColorSelect.marko | 6 +-- .../1-render-app/marko/app.js | 3 ++ .../1-render-app/marko/index.html | 7 ++++ .../1-render-app/marko/index.marko | 4 -- .../2-fetch-data/marko/App.marko | 20 +++++----- frameworks.mjs | 2 +- 25 files changed, 101 insertions(+), 70 deletions(-) create mode 100644 content/7-webapp-features/1-render-app/marko/app.js create mode 100644 content/7-webapp-features/1-render-app/marko/index.html delete mode 100644 content/7-webapp-features/1-render-app/marko/index.marko 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 - +