Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,39 +1,23 @@
<script lang="ts">
import { browser } from '$app/environment';
import { afterNavigate } from '$app/navigation';
import { afterNavigate, replaceState } from '$app/navigation';
import { theme } from '@sveltejs/site-kit/stores';
import { Repl } from '@sveltejs/repl';
import { mapbox_setup } from '../../../../../config.js';
import { onMount } from 'svelte';

let { data } = $props();

let version = $state(data.version);
let repl = $state() as Repl;

function update_query_string(version: string) {
const params = [];

if (version !== 'latest') params.push(`version=${version}`);

const url =
params.length > 0
? `/playground/${data.gist.id}/embed?${params.join('&')}`
: `/playground/${data.gist.id}/embed`;

history.replaceState({}, 'x', url);
}

$effect(() => {
update_query_string(version);
});

onMount(() => {
if (data.version !== 'local') {
fetch(`https://unpkg.com/svelte@${data.version || 'next'}/package.json`)
fetch(`https://unpkg.com/svelte@${data.version}/package.json`)
.then((r) => r.json())
.then((pkg) => {
version = pkg.version;
if (pkg.version !== data.version) {
replaceState(`/playground/${data.gist.id}/embed?version=${pkg.version}`, {});
}
});
}
});
Expand All @@ -44,11 +28,10 @@
});
});

const svelteUrl = $derived(
browser && version === 'local'
const svelteUrl =
browser && data.version === 'local'
? `${location.origin}/playground/local`
: `https://unpkg.com/svelte@${version}`
);
: `https://unpkg.com/svelte@${data.version}`;

const relaxed = $derived(data.gist.relaxed || (data.user && data.user.id === data.gist.owner));
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ export async function GET({ params }) {
}

export async function entries() {
const { get_examples_list } = await import('$lib/server/examples/index.js');

return get_examples_list(examples_data)
.map(({ examples }) => examples)
.flatMap((val) => val.map(({ slug }) => ({ id: slug })));
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { redirect } from '@sveltejs/kit';

export function load({ url }) {
if (url.searchParams.has('example')) {
throw redirect(301, construct_embed_url(url.searchParams, 'example'));
} else if (url.searchParams.has('gist')) {
throw redirect(301, construct_embed_url(url.searchParams, 'gist'));
} else {
throw redirect(301, '/playground/hello-world/embed');
}
}

function construct_embed_url(searchParams: URLSearchParams, param: string) {
const cleaned_params = new URLSearchParams(searchParams);
cleaned_params.delete(param);
return `/playground/${searchParams.get(param)}/embed?${cleaned_params.toString()}`;
}
Loading