Apply the suggestions

pull/8432/head
Puru Vijay 3 years ago
parent 3efddd28b4
commit fd407a78c8

@ -5,7 +5,9 @@ const examples_data = get_examples_data(
new URL('../../../site/content/examples', import.meta.url).pathname
);
fs.mkdirSync(new URL('../src/lib/generated/', import.meta.url), { recursive: true });
fs.writeFileSync(
new URL('../src/routes/(authed)/repl/[id].json/examples-data.js', import.meta.url),
new URL('../src/lib/generated/examples-data.js', import.meta.url),
`export default ${JSON.stringify(examples_data)}`
);

@ -2,21 +2,20 @@
import { browser } from '$app/environment';
import { process_example } from '$lib/utils/examples';
import Repl from '@sveltejs/repl';
import { getContext, onMount } from 'svelte';
import { onMount } from 'svelte';
export let version = '3';
export let gist = null;
export let example = null;
export let embedded = false;
/** @type {import('@sveltejs/repl').default} */
let repl;
let name = 'loading...';
let mounted = false;
const repl_widget_examples = getContext('repl_widget_examples');
function load(gist, example) {
async function load(gist, example) {
if (version !== 'local') {
fetch(`https://unpkg.com/svelte@${version}/package.json`)
.then((r) => r.json())
@ -60,7 +59,8 @@
});
} else if (example) {
const components = process_example(
repl_widget_examples.find(({ id }) => id === example).files
// repl_widget_examples.find(({ id }) => id === example).files
(await fetch(`/examples/api/${example}.json`).then((r) => r.json())).files
);
repl.set({

@ -2,9 +2,9 @@ import { dev } from '$app/environment';
import { client } from '$lib/db/client';
import * as gist from '$lib/db/gist';
import { get_example } from '$lib/server/examples';
import { get_examples_data, get_examples_list } from '$lib/server/examples/get-examples';
import { get_examples_list } from '$lib/server/examples/get-examples';
import { error, json } from '@sveltejs/kit';
import examples_data from './examples-data.js';
import examples_data from '$lib/generated/examples-data.js';
export const prerender = 'auto';

@ -1,5 +1,5 @@
import { get_example } from '$lib/server/examples';
import { get_examples_data, get_examples_list } from '$lib/server/examples/get-examples';
import { get_examples_data } from '$lib/server/examples/get-examples';
export const prerender = true;

@ -1,16 +1,11 @@
<script>
import { Blurb } from '@sveltejs/site-kit/components';
import { setContext } from 'svelte';
import Balls from './svelte-balls.png?w=640;1280;2560;3840&format=avif;webp;png&picture';
import Demo from './_components/Demo.svelte';
import Hero from './_components/Hero.svelte';
import Image from './_components/Image.svelte';
import Supporters from './_components/Supporters/index.svelte';
import WhosUsingSvelte from './_components/WhosUsingSvelte/index.svelte';
export let data;
setContext('repl_widget_examples', data.examples);
</script>
<svelte:head>

@ -1,9 +1,32 @@
<script>
import { getContext } from 'svelte';
import Example from './Example.svelte';
import Section from './Section.svelte';
const examples = getContext('repl_widget_examples');
const examples = [
{
id: 'hello-world',
title: 'Hello World',
description: 'Svelte components are built on top of HTML. Just add data.',
},
{
id: 'nested-components',
title: 'Scoped CSS',
description:
'CSS is component-scoped by default — no more style collisions or specificity wars. Or you can <a href="/blog/svelte-css-in-js">use your favourite CSS-in-JS library</a >.',
},
{
id: 'reactive-assignments',
title: 'Reactivity',
description:
'Trigger efficient, granular updates by assigning to local variables. The compiler does the rest.',
},
{
id: 'svg-transitions',
title: 'Transitions',
description:
'Build beautiful UIs with a powerful, performant transition engine built right into the framework.',
},
];
$: selected = examples[0];
</script>

@ -0,0 +1,8 @@
// @ts-check
import examples_data from '$lib/generated/examples-data.js';
import { get_examples_list } from '$lib/server/examples/get-examples';
import { json } from '@sveltejs/kit';
export const GET = () => {
return json(get_examples_list(examples_data));
};

@ -0,0 +1,17 @@
import examples_data from '$lib/generated/examples-data.js';
import { get_example } from '$lib/server/examples';
import { get_examples_list } from '$lib/server/examples/get-examples';
import { error, json } from '@sveltejs/kit';
export const GET = ({ params }) => {
const examples = new Set(
get_examples_list(examples_data)
.map((category) => category.examples)
.flat()
.map((example) => example.slug)
);
if (!examples.has(params.slug)) throw error(404, 'Example not found');
return json(get_example(examples_data, params.slug));
};
Loading…
Cancel
Save