Skip to content

Commit

Permalink
feat(playground): include snippet title key in json hashed
Browse files Browse the repository at this point in the history
  • Loading branch information
matschik committed Oct 25, 2024
1 parent 7ef0af0 commit 9e3185d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
11 changes: 7 additions & 4 deletions build/lib/generateContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ export default async function generateContent() {
frameworkSnippet.files = filesSorter(frameworkSnippet.files);
const playgroundURL = await generatePlaygroundURL(
frameworkId,
frameworkSnippet.files
frameworkSnippet.files,
title
);

if (playgroundURL) {
Expand Down Expand Up @@ -205,7 +206,7 @@ async function writeJsFile(filepath, jsCode) {
await fs.writeFile(filepath, codeFormatted);
}

async function generatePlaygroundURL(frameworkId, files) {
async function generatePlaygroundURL(frameworkId, files, title) {
const frameworkIdPlayground = frameworkPlayground[frameworkId];
if (!frameworkIdPlayground) {
return;
Expand All @@ -220,8 +221,10 @@ async function generatePlaygroundURL(frameworkId, files) {
return acc;
}, {});

const playgroundURL =
await frameworkIdPlayground.fromContentByFilename(contentByFilename);
const playgroundURL = await frameworkIdPlayground.fromContentByFilename(
contentByFilename,
title
);

return playgroundURL;
}
6 changes: 4 additions & 2 deletions build/lib/playground/createSvelte5Playground.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import path from "node:path";
export default function createSvelte5Playground() {
const BASE_URL = "https://svelte.dev/playground/untitled?version=5#";

async function fromContentByFilename(contentByFilename) {
async function fromContentByFilename(contentByFilename, title) {
const filenames = Object.keys(contentByFilename);
if (filenames.some((f) => f.includes(".html"))) {
return;
Expand All @@ -21,7 +21,9 @@ export default function createSvelte5Playground() {
};
});

const hash = await compress_and_encode_text(JSON.stringify({ files }));
const payload = { title, files };

const hash = await compress_and_encode_text(JSON.stringify(payload));

const url = `${BASE_URL}${hash}`;

Expand Down

0 comments on commit 9e3185d

Please sign in to comment.