From 9d0f7d72799420698950b15531fe2df74816e041 Mon Sep 17 00:00:00 2001 From: Tobias Messner Date: Mon, 22 Jan 2024 10:44:57 +0100 Subject: [PATCH] fix(repl): update broken embed repl to work like regular one, remove obsolete ReplWidget.svelte (#10180) --- .../src/lib/components/ReplWidget.svelte | 95 ------------------- .../(authed)/repl/[id]/embed/+page.server.js | 16 ++++ .../(authed)/repl/[id]/embed/+page.svelte | 92 ++++++++++++++++++ .../src/routes/(authed)/repl/embed/+page.js | 8 -- .../(authed)/repl/embed/+page.server.js | 14 +++ .../routes/(authed)/repl/embed/+page.svelte | 36 ------- sites/svelte.dev/src/routes/+layout.svelte | 5 +- .../src/routes/_components/Example.svelte | 28 +++++- 8 files changed, 152 insertions(+), 142 deletions(-) delete mode 100644 sites/svelte.dev/src/lib/components/ReplWidget.svelte create mode 100644 sites/svelte.dev/src/routes/(authed)/repl/[id]/embed/+page.server.js create mode 100644 sites/svelte.dev/src/routes/(authed)/repl/[id]/embed/+page.svelte delete mode 100644 sites/svelte.dev/src/routes/(authed)/repl/embed/+page.js create mode 100644 sites/svelte.dev/src/routes/(authed)/repl/embed/+page.server.js delete mode 100644 sites/svelte.dev/src/routes/(authed)/repl/embed/+page.svelte diff --git a/sites/svelte.dev/src/lib/components/ReplWidget.svelte b/sites/svelte.dev/src/lib/components/ReplWidget.svelte deleted file mode 100644 index bba3f4aa95..0000000000 --- a/sites/svelte.dev/src/lib/components/ReplWidget.svelte +++ /dev/null @@ -1,95 +0,0 @@ - - -{#if browser} - -{/if} diff --git a/sites/svelte.dev/src/routes/(authed)/repl/[id]/embed/+page.server.js b/sites/svelte.dev/src/routes/(authed)/repl/[id]/embed/+page.server.js new file mode 100644 index 0000000000..5d80a583f3 --- /dev/null +++ b/sites/svelte.dev/src/routes/(authed)/repl/[id]/embed/+page.server.js @@ -0,0 +1,16 @@ +import { error } from '@sveltejs/kit'; + +export async function load({ fetch, params, url }) { + const res = await fetch(`/repl/api/${params.id}.json`); + + if (!res.ok) { + throw error(res.status); + } + + const gist = await res.json(); + + return { + gist, + version: url.searchParams.get('version') || '4' + }; +} diff --git a/sites/svelte.dev/src/routes/(authed)/repl/[id]/embed/+page.svelte b/sites/svelte.dev/src/routes/(authed)/repl/[id]/embed/+page.svelte new file mode 100644 index 0000000000..7592c53c24 --- /dev/null +++ b/sites/svelte.dev/src/routes/(authed)/repl/[id]/embed/+page.svelte @@ -0,0 +1,92 @@ + + + + {data.gist.name} • REPL • Svelte + + + + + + +
+ {#if browser} + + {/if} +
+ + diff --git a/sites/svelte.dev/src/routes/(authed)/repl/embed/+page.js b/sites/svelte.dev/src/routes/(authed)/repl/embed/+page.js deleted file mode 100644 index b27fec14d4..0000000000 --- a/sites/svelte.dev/src/routes/(authed)/repl/embed/+page.js +++ /dev/null @@ -1,8 +0,0 @@ -export function load({ url }) { - const query = url.searchParams; - return { - version: query.get('version') || '3', - gist: query.get('gist'), - example: query.get('example') - }; -} diff --git a/sites/svelte.dev/src/routes/(authed)/repl/embed/+page.server.js b/sites/svelte.dev/src/routes/(authed)/repl/embed/+page.server.js new file mode 100644 index 0000000000..d6f8ab11bb --- /dev/null +++ b/sites/svelte.dev/src/routes/(authed)/repl/embed/+page.server.js @@ -0,0 +1,14 @@ +import { redirect } from '@sveltejs/kit'; + +export function load({ url }) { + if (!url.searchParams.has('gist')) { + throw redirect(301, '/repl/hello-world/embed'); + } else { + const searchParamsWithoutGist = new URLSearchParams(url.searchParams); + searchParamsWithoutGist.delete('gist'); + throw redirect( + 301, + `/repl/${url.searchParams.get('gist')}/embed?${searchParamsWithoutGist.toString()}` + ); + } +} diff --git a/sites/svelte.dev/src/routes/(authed)/repl/embed/+page.svelte b/sites/svelte.dev/src/routes/(authed)/repl/embed/+page.svelte deleted file mode 100644 index 43fed8a1cb..0000000000 --- a/sites/svelte.dev/src/routes/(authed)/repl/embed/+page.svelte +++ /dev/null @@ -1,36 +0,0 @@ - - - - REPL • Svelte - - - - - - -
- {#if browser} - - {/if} -
- - diff --git a/sites/svelte.dev/src/routes/+layout.svelte b/sites/svelte.dev/src/routes/+layout.svelte index ab931bcd7a..9d1e6bdff9 100644 --- a/sites/svelte.dev/src/routes/+layout.svelte +++ b/sites/svelte.dev/src/routes/+layout.svelte @@ -33,7 +33,10 @@
- +