diff --git a/sites/svelte.dev/package.json b/sites/svelte.dev/package.json index 9a6d904b7b..243e6fcc2e 100644 --- a/sites/svelte.dev/package.json +++ b/sites/svelte.dev/package.json @@ -5,9 +5,9 @@ "description": "Docs and examples for Svelte", "type": "module", "scripts": { - "dev": "node scripts/update.js && pnpm run generate && vite dev", - "build": "node scripts/update.js && pnpm run generate && vite build", - "generate": "node scripts/type-gen/index.js && node scripts/generate_examples.js", + "dev": "node scripts/update.js && vite dev", + "build": "node scripts/update.js && vite build", + "generate": "node scripts/type-gen/index.js", "update": "node scripts/update.js --force=true", "preview": "vite preview", "start": "node build", diff --git a/sites/svelte.dev/scripts/generate_examples.js b/sites/svelte.dev/scripts/generate_examples.js deleted file mode 100644 index 360cba79bd..0000000000 --- a/sites/svelte.dev/scripts/generate_examples.js +++ /dev/null @@ -1,16 +0,0 @@ -import { fileURLToPath } from 'node:url'; -import { get_examples_data } from '../src/lib/server/examples/index.js'; -import { mkdir, writeFile } from 'node:fs/promises'; - -const examples_data = await get_examples_data( - fileURLToPath(new URL('../../../documentation/examples', import.meta.url)) -); - -try { - await mkdir(new URL('../src/lib/generated/', import.meta.url), { recursive: true }); -} catch {} - -writeFile( - new URL('../src/lib/generated/examples-data.js', import.meta.url), - `export default ${JSON.stringify(examples_data)}` -); diff --git a/sites/svelte.dev/src/lib/server/blog/index.js b/sites/svelte.dev/src/lib/server/blog/index.js deleted file mode 100644 index 1cd3a16178..0000000000 --- a/sites/svelte.dev/src/lib/server/blog/index.js +++ /dev/null @@ -1,84 +0,0 @@ -// @ts-check -import { extractFrontmatter } from '@sveltejs/site-kit/markdown'; -import { CONTENT_BASE_PATHS } from '../../../constants.js'; -import { render_content } from '../renderer.js'; -import { get_sections } from '../docs/index.js'; - -/** - * @param {import('./types').BlogData} blog_data - * @param {string} slug - */ -export async function get_processed_blog_post(blog_data, slug) { - for (const post of blog_data) { - if (post.slug === slug) { - return { - ...post, - content: await render_content(post.file, post.content) - }; - } - } - - return null; -} - -const BLOG_NAME_REGEX = /^(\d{4}-\d{2}-\d{2})-(.+)\.md$/; - -/** @returns {Promise} */ -export async function get_blog_data(base = CONTENT_BASE_PATHS.BLOG) { - const { readdir, readFile } = await import('node:fs/promises'); - - /** @type {import('./types').BlogData} */ - const blog_posts = []; - - for (const file of (await readdir(base)).reverse()) { - if (!BLOG_NAME_REGEX.test(file)) continue; - - const { date, date_formatted, slug } = get_date_and_slug(file); - const { metadata, body } = extractFrontmatter(await readFile(`${base}/${file}`, 'utf-8')); - const authors = metadata.author.split(',').map((author) => author.trim()); - const authorUrls = metadata.authorURL.split(',').map((author) => author.trim()); - - blog_posts.push({ - date, - date_formatted, - content: body, - description: metadata.description, - draft: metadata.draft === 'true', - slug, - title: metadata.title, - file, - authors: authors.map((author, i) => ({ - name: author, - url: authorUrls[i] - })), - sections: await get_sections(body) - }); - } - - return blog_posts; -} - -/** @param {import('./types').BlogData} blog_data */ -export function get_blog_list(blog_data) { - return blog_data.map(({ slug, date, title, description, draft }) => ({ - slug, - date, - title, - description, - draft - })); -} - -/** @param {string} filename */ -function get_date_and_slug(filename) { - const match = BLOG_NAME_REGEX.exec(filename); - if (!match) throw new Error(`Invalid filename for blog: '${filename}'`); - - const [, date, slug] = match; - const [y, m, d] = date.split('-'); - const date_formatted = `${months[+m - 1]} ${+d} ${y}`; - - return { date, date_formatted, slug }; -} - -const months = 'Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec'.split(' '); diff --git a/sites/svelte.dev/src/lib/server/blog/types.d.ts b/sites/svelte.dev/src/lib/server/blog/types.d.ts deleted file mode 100644 index fc922ca54c..0000000000 --- a/sites/svelte.dev/src/lib/server/blog/types.d.ts +++ /dev/null @@ -1,27 +0,0 @@ -import type { Section } from '../docs/types'; - -export interface BlogPost { - title: string; - description: string; - date: string; - date_formatted: string; - slug: string; - file: string; - authors: { - name: string; - url?: string; - }[]; - draft: boolean; - content: string; - sections: Section[]; -} - -export type BlogData = BlogPost[]; - -export interface BlogPostSummary { - slug: string; - title: string; - description: string; - date: string; - draft: boolean; -} diff --git a/sites/svelte.dev/src/lib/server/examples/index.js b/sites/svelte.dev/src/lib/server/examples/index.js deleted file mode 100644 index 759a72746e..0000000000 --- a/sites/svelte.dev/src/lib/server/examples/index.js +++ /dev/null @@ -1,98 +0,0 @@ -import { CONTENT_BASE_PATHS } from '../../../constants.js'; - -/** - * @param {import('./types').ExamplesData} examples_data - * @param {string} slug - */ -export function get_example(examples_data, slug) { - for (const section of examples_data) { - for (const example of section.examples) { - if (example.slug === slug) { - return example; - } - } - } - - return null; -} - -/** - * @returns {Promise} - */ -export async function get_examples_data(base = CONTENT_BASE_PATHS.EXAMPLES) { - const { readdir, stat, readFile } = await import('node:fs/promises'); - - const examples = []; - - for (const subdir of await readdir(base)) { - /** @type {import('./types').ExamplesDatum} */ - const section = { - title: '', // Initialise with empty - slug: subdir.split('-').slice(1).join('-'), - examples: [] - }; - - if (!((await stat(`${base}/${subdir}`)).isDirectory() || subdir.endsWith('meta.json'))) - continue; - - if (!subdir.endsWith('meta.json')) - section.title = - JSON.parse(await readFile(`${base}/${subdir}/meta.json`, 'utf-8')).title ?? 'Embeds'; - - for (const section_dir of await readdir(`${base}/${subdir}`)) { - const match = /\d{2}-(.+)/.exec(section_dir); - if (!match) continue; - - const slug = match[1]; - - const example_base_dir = `${base}/${subdir}/${section_dir}`; - - // Get title for - const example_title = JSON.parse( - await readFile(`${example_base_dir}/meta.json`, 'utf-8') - ).title; - - /** - * @type {Array<{ - * name: string; - * type: string; - * content: string; - * }>} - */ - const files = []; - for (const file of (await readdir(example_base_dir)).filter( - (file) => !file.endsWith('meta.json') - )) { - const type = file.split('.').at(-1); - if (!type) { - throw new Error(`Could not determine type from ${file}`); - } - files.push({ - name: file, - type, - content: await readFile(`${example_base_dir}/${file}`, 'utf-8') - }); - } - - section.examples.push({ title: example_title, slug, files }); - } - - examples.push(section); - } - - return examples; -} - -/** - * @param {import('./types').ExamplesData} examples_data - * @returns {import('./types').ExamplesList} - */ -export function get_examples_list(examples_data) { - return examples_data.map((section) => ({ - title: section.title, - examples: section.examples.map((example) => ({ - title: example.title, - slug: example.slug - })) - })); -} diff --git a/sites/svelte.dev/src/lib/server/examples/types.d.ts b/sites/svelte.dev/src/lib/server/examples/types.d.ts deleted file mode 100644 index 4be706354d..0000000000 --- a/sites/svelte.dev/src/lib/server/examples/types.d.ts +++ /dev/null @@ -1,27 +0,0 @@ -export interface ExamplesDatum { - title: string; - slug: string; - examples: { - title: string; - slug: string; - files: { - content: string; - type: string; - name: string; - }[]; - }[]; -} - -export type ExamplesData = ExamplesDatum[]; - -export interface Example { - title: string; - slug: string; -} - -export interface ExampleSection { - title: string; - examples: Example[]; -} - -export type ExamplesList = ExampleSection[]; diff --git a/sites/svelte.dev/src/routes/(authed)/+layout.server.js b/sites/svelte.dev/src/routes/(authed)/+layout.server.js deleted file mode 100644 index 4a0c545f5d..0000000000 --- a/sites/svelte.dev/src/routes/(authed)/+layout.server.js +++ /dev/null @@ -1,12 +0,0 @@ -import * as session from '$lib/db/session'; - -/** @type {import('@sveltejs/adapter-vercel').Config} */ -export const config = { - runtime: 'nodejs18.x' // see https://github.com/sveltejs/svelte/pull/9136 -}; - -export async function load({ request }) { - return { - user: await session.from_cookie(request.headers.get('cookie')) - }; -} diff --git a/sites/svelte.dev/src/routes/(authed)/+layout.svelte b/sites/svelte.dev/src/routes/(authed)/+layout.svelte deleted file mode 100644 index b3c90243eb..0000000000 --- a/sites/svelte.dev/src/routes/(authed)/+layout.svelte +++ /dev/null @@ -1,28 +0,0 @@ - - - diff --git a/sites/svelte.dev/src/routes/(authed)/apps/+page.server.js b/sites/svelte.dev/src/routes/(authed)/apps/+page.server.js deleted file mode 100644 index a85cb5796b..0000000000 --- a/sites/svelte.dev/src/routes/(authed)/apps/+page.server.js +++ /dev/null @@ -1,20 +0,0 @@ -import * as gist from '$lib/db/gist'; - -export async function load({ url, parent }) { - let gists = []; - let next = null; - - const search = url.searchParams.get('search'); - - const { user } = await parent(); - - if (user) { - const offset_param = url.searchParams.get('offset'); - const offset = offset_param ? parseInt(offset_param) : 0; - const search = url.searchParams.get('search'); - - ({ gists, next } = await gist.list(user, { offset, search })); - } - - return { user, gists, next, search }; -} diff --git a/sites/svelte.dev/src/routes/(authed)/apps/+page.svelte b/sites/svelte.dev/src/routes/(authed)/apps/+page.svelte deleted file mode 100644 index 64a6c1d6a1..0000000000 --- a/sites/svelte.dev/src/routes/(authed)/apps/+page.svelte +++ /dev/null @@ -1,328 +0,0 @@ - - - - Your apps • Svelte - - -
- {#if data.user} -
-

Your apps

-
- {data.user.github_name || data.user.github_login} avatar - - {data.user.github_name || data.user.github_login} - (log out) - -
-
- -
- {#if selected.length > 0} - - - - {:else} -
{ - const search = new FormData(/** @type {HTMLFormElement} */ (e.target)).get('search'); - goto(search ? `/apps?search=${encodeURIComponent(search.toString())}` : '/apps'); - }} - > - -
- {/if} -
- - {#if data.gists.length > 0} - - - - {:else} -

No apps here. Go make one!

- {/if} - {:else} -

- Please log in to see your saved apps. -

- {/if} -
- - diff --git a/sites/svelte.dev/src/routes/(authed)/apps/destroy/+server.js b/sites/svelte.dev/src/routes/(authed)/apps/destroy/+server.js deleted file mode 100644 index d898111a60..0000000000 --- a/sites/svelte.dev/src/routes/(authed)/apps/destroy/+server.js +++ /dev/null @@ -1,12 +0,0 @@ -import * as session from '$lib/db/session'; -import * as gist from '$lib/db/gist'; - -export async function POST({ request }) { - const user = await session.from_cookie(request.headers.get('cookie')); - if (!user) return new Response(undefined, { status: 401 }); - - const body = await request.json(); - await gist.destroy(user.id, body.ids); - - return new Response(undefined, { status: 204 }); -} diff --git a/sites/svelte.dev/src/routes/(authed)/repl/+page.js b/sites/svelte.dev/src/routes/(authed)/repl/+page.js deleted file mode 100644 index c6e63444fd..0000000000 --- a/sites/svelte.dev/src/routes/(authed)/repl/+page.js +++ /dev/null @@ -1,21 +0,0 @@ -import { redirect } from '@sveltejs/kit'; - -export function load({ url }) { - const query = url.searchParams; - const gist = query.get('gist'); - const example = query.get('example'); - const version = query.get('version'); - const vim = query.get('vim'); - - // redirect to v2 REPL if appropriate - if (version && /^[^>]?[12]/.test(version)) { - redirect(302, `https://v2.svelte.dev/repl?${query}`); - } - - const id = gist || example || 'hello-world'; - // we need to filter out null values - const q = new URLSearchParams(); - if (version) q.set('version', version); - if (vim) q.set('vim', vim); - redirect(301, `/repl/${id}?${q}`); -} diff --git a/sites/svelte.dev/src/routes/(authed)/repl/+page.svelte b/sites/svelte.dev/src/routes/(authed)/repl/+page.svelte deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/sites/svelte.dev/src/routes/(authed)/repl/[id]/+page.js b/sites/svelte.dev/src/routes/(authed)/repl/[id]/+page.js deleted file mode 100644 index b130a6663c..0000000000 --- a/sites/svelte.dev/src/routes/(authed)/repl/[id]/+page.js +++ /dev/null @@ -1,18 +0,0 @@ -import { browser } from '$app/environment'; - -export function load({ data, url }) { - // initialize vim with the search param - const vim_search_params = url.searchParams.get('vim'); - let vim = vim_search_params !== null && vim_search_params !== 'false'; - // when in the browser check if there's a local storage entry and eventually override - // vim if there's not a search params otherwise update the local storage - if (browser) { - const vim_local_storage = window.localStorage.getItem('svelte:vim-enabled'); - if (vim_search_params !== null) { - window.localStorage.setItem('svelte:vim-enabled', vim.toString()); - } else if (vim_local_storage) { - vim = vim_local_storage !== 'false'; - } - } - return { ...data, vim }; -} diff --git a/sites/svelte.dev/src/routes/(authed)/repl/[id]/+page.server.js b/sites/svelte.dev/src/routes/(authed)/repl/[id]/+page.server.js deleted file mode 100644 index 62d5d419dd..0000000000 --- a/sites/svelte.dev/src/routes/(authed)/repl/[id]/+page.server.js +++ /dev/null @@ -1,16 +0,0 @@ -import { error } from '@sveltejs/kit'; - -export async function load({ fetch, params, url }) { - const res = await fetch(`/repl/api/${params.id}.json`); - - if (!res.ok) { - error(/** @type {import('@sveltejs/kit').NumericRange<400, 599>} */(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]/+page.svelte b/sites/svelte.dev/src/routes/(authed)/repl/[id]/+page.svelte deleted file mode 100644 index 02694bef33..0000000000 --- a/sites/svelte.dev/src/routes/(authed)/repl/[id]/+page.svelte +++ /dev/null @@ -1,151 +0,0 @@ - - - - {name} • REPL • Svelte - - - - - - -
- - - {#if browser} - - {/if} -
- - diff --git a/sites/svelte.dev/src/routes/(authed)/repl/[id]/AppControls.svelte b/sites/svelte.dev/src/routes/(authed)/repl/[id]/AppControls.svelte deleted file mode 100644 index fd14487d6d..0000000000 --- a/sites/svelte.dev/src/routes/(authed)/repl/[id]/AppControls.svelte +++ /dev/null @@ -1,339 +0,0 @@ - - - - -
- e.target.select()} - use:enter={(e) => /** @type {HTMLInputElement} */ (e.target).blur()} - /> - -
- - - - - - - - - {#if user} - - {:else} - - {/if} -
-
- - diff --git a/sites/svelte.dev/src/routes/(authed)/repl/[id]/UserMenu.svelte b/sites/svelte.dev/src/routes/(authed)/repl/[id]/UserMenu.svelte deleted file mode 100644 index 5449191a30..0000000000 --- a/sites/svelte.dev/src/routes/(authed)/repl/[id]/UserMenu.svelte +++ /dev/null @@ -1,134 +0,0 @@ - - -
(showMenu = false)} - use:click_outside={() => (showMenu = false)} -> - - - {#if showMenu} - - {/if} -
- - diff --git a/sites/svelte.dev/src/routes/(authed)/repl/[id]/downloadBlob.js b/sites/svelte.dev/src/routes/(authed)/repl/[id]/downloadBlob.js deleted file mode 100644 index 5815e2217b..0000000000 --- a/sites/svelte.dev/src/routes/(authed)/repl/[id]/downloadBlob.js +++ /dev/null @@ -1,15 +0,0 @@ -/** - * @param {Blob} blob - * @param {string} filename - */ -export default (blob, filename) => { - const url = URL.createObjectURL(blob); - const link = document.createElement('a'); - link.href = url; - link.download = filename; - link.style.display = 'none'; - document.body.appendChild(link); - link.click(); - URL.revokeObjectURL(url); - link.remove(); -}; 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 deleted file mode 100644 index f9d55d0846..0000000000 --- a/sites/svelte.dev/src/routes/(authed)/repl/[id]/embed/+page.server.js +++ /dev/null @@ -1,16 +0,0 @@ -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(/** @type {any} */ (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 deleted file mode 100644 index 7592c53c24..0000000000 --- a/sites/svelte.dev/src/routes/(authed)/repl/[id]/embed/+page.svelte +++ /dev/null @@ -1,92 +0,0 @@ - - - - {data.gist.name} • REPL • Svelte - - - - - - -
- {#if browser} - - {/if} -
- - diff --git a/sites/svelte.dev/src/routes/(authed)/repl/api/[id].json/+server.js b/sites/svelte.dev/src/routes/(authed)/repl/api/[id].json/+server.js deleted file mode 100644 index f0854a819a..0000000000 --- a/sites/svelte.dev/src/routes/(authed)/repl/api/[id].json/+server.js +++ /dev/null @@ -1,93 +0,0 @@ -import { dev } from '$app/environment'; -import { client } from '$lib/db/client.js'; -import * as gist from '$lib/db/gist.js'; -import examples_data from '$lib/generated/examples-data.js'; -import { get_example, get_examples_list } from '$lib/server/examples/index.js'; -import { error, json } from '@sveltejs/kit'; - -export const prerender = 'auto'; - -const UUID_REGEX = /^[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12}$/; - - -/** @param {import('$lib/server/examples/types').ExamplesData[number]['examples'][number]['files'][number][]} files */ -function munge(files) { - return files - .map((file) => { - const dot = file.name.lastIndexOf('.'); - let name = file.name.slice(0, dot); - let type = file.name.slice(dot + 1); - - if (type === 'html') type = 'svelte'; - // @ts-expect-error what is file.source? by @PuruVJ - return { name, type, source: file.source ?? file.content ?? '' }; - }) - .sort((a, b) => { - if (a.name === 'App' && a.type === 'svelte') return -1; - if (b.name === 'App' && b.type === 'svelte') return 1; - - if (a.type !== b.type) return a.type === 'svelte' ? -1 : 1; - - return a.name < b.name ? -1 : 1; - }); -} - -export async function GET({ params }) { - // Currently, these pages(that are in examples/) are prerendered. To avoid making any FS requests, - // We prerender examples pages during build time. That means, when something like `/repl/hello-world.json` - // is accessed, this function won't be run at all, as it will be served from the filesystem - - const example = get_example(examples_data, params.id); - if (example) { - return json({ - id: params.id, - name: example.title, - owner: null, - relaxed: false, // TODO is this right? EDIT: It was example.relaxed before, which no example return to my knowledge. By @PuruVJ - components: munge(example.files) - }); - } - - if (dev && !client) { - // in dev with no local Supabase configured, proxy to production - // this lets us at least load saved REPLs - const res = await fetch(`https://svelte.dev/repl/api/${params.id}.json`); - - // returning the response directly results in a bizarre - // content encoding error, so we create a new one - return new Response(await res.text(), { - status: res.status, - headers: { - 'content-type': 'application/json' - } - }); - } - - if (!UUID_REGEX.test(params.id)) { - error(404); - } - - const app = await gist.read(params.id); - - if (!app) { - error(404, 'not found'); - } - - return json({ - id: params.id, - name: app.name, - // @ts-ignore - owner: app.userid, - relaxed: false, - // @ts-expect-error app.files has a `source` property - components: munge(app.files) - }); -} - -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 }))); -} diff --git a/sites/svelte.dev/src/routes/(authed)/repl/create.json/+server.js b/sites/svelte.dev/src/routes/(authed)/repl/create.json/+server.js deleted file mode 100644 index e7794ffbf2..0000000000 --- a/sites/svelte.dev/src/routes/(authed)/repl/create.json/+server.js +++ /dev/null @@ -1,18 +0,0 @@ -import * as gist from '$lib/db/gist'; -import * as session from '$lib/db/session'; -import { error, json } from '@sveltejs/kit'; - -export async function POST({ request }) { - const user = await session.from_cookie(request.headers.get('cookie')); - if (!user) error(401); - - const body = await request.json(); - const result = await gist.create(user, body); - - // normalize id - result.id = result.id.replace(/-/g, ''); - - return json(result, { - status: 201 - }); -} 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 deleted file mode 100644 index d6f8ab11bb..0000000000 --- a/sites/svelte.dev/src/routes/(authed)/repl/embed/+page.server.js +++ /dev/null @@ -1,14 +0,0 @@ -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/local/[...path]/+server.js b/sites/svelte.dev/src/routes/(authed)/repl/local/[...path]/+server.js deleted file mode 100644 index f141ee2021..0000000000 --- a/sites/svelte.dev/src/routes/(authed)/repl/local/[...path]/+server.js +++ /dev/null @@ -1,15 +0,0 @@ -import { env } from '$env/dynamic/private'; - -const local_svelte_path = env.LOCAL_SVELTE_PATH || '../../../svelte'; - -export async function GET({ params: { path } }) { - if (import.meta.env.PROD || ('/' + path).includes('/.')) { - return new Response(undefined, { status: 403 }); - } - - const { readFile } = await import('node:fs/promises'); - - return new Response(await readFile(`${local_svelte_path}/${path}`), { - headers: { 'Content-Type': 'text/javascript' } - }); -} diff --git a/sites/svelte.dev/src/routes/(authed)/repl/save/[id].json/+server.js b/sites/svelte.dev/src/routes/(authed)/repl/save/[id].json/+server.js deleted file mode 100644 index f37f699432..0000000000 --- a/sites/svelte.dev/src/routes/(authed)/repl/save/[id].json/+server.js +++ /dev/null @@ -1,14 +0,0 @@ -import * as gist from '$lib/db/gist'; -import * as session from '$lib/db/session'; -import { error } from '@sveltejs/kit'; - -// TODO reimplement as an action -export async function PUT({ params, request }) { - const user = await session.from_cookie(request.headers.get('cookie')); - if (!user) error(401, 'Unauthorized'); - - const body = await request.json(); - await gist.update(user, params.id, body); - - return new Response(undefined, { status: 204 }); -} diff --git a/sites/svelte.dev/src/routes/+layout.svelte b/sites/svelte.dev/src/routes/+layout.svelte index a08469bed7..e5cf42a2ad 100644 --- a/sites/svelte.dev/src/routes/+layout.svelte +++ b/sites/svelte.dev/src/routes/+layout.svelte @@ -2,7 +2,7 @@ import '@sveltejs/site-kit/styles/index.css'; import { injectSpeedInsights } from '@vercel/speed-insights/sveltekit'; - import { inject } from '@vercel/analytics' + import { inject } from '@vercel/analytics'; import { browser } from '$app/environment'; import { page } from '$app/stores'; import { Icon, Shell, Banners } from '@sveltejs/site-kit/components'; @@ -58,9 +58,7 @@ - Tutorial - - SvelteKit + Current version diff --git a/sites/svelte.dev/src/routes/banner.json/+server.js b/sites/svelte.dev/src/routes/banner.json/+server.js index ffe27fd996..b9a2fe8977 100644 --- a/sites/svelte.dev/src/routes/banner.json/+server.js +++ b/sites/svelte.dev/src/routes/banner.json/+server.js @@ -9,29 +9,15 @@ export const GET = async () => { return json( defineBanner([ { - id: 'advent2023', + id: 'deprecated', start: new Date('1 Dec, 2023 00:00:00 UTC'), - end: new Date('24 Dec, 2023 23:59:59 UTC'), + end: new Date('24 Dec, 2050 23:59:59 UTC'), arrow: true, content: { - lg: 'Advent of Svelte 2023 is here!', - sm: 'Advent of Svelte' + lg: 'This documentation is for Svelte 3 and 4. Go to the latest docs.', + sm: 'These docs are for Svelte 3/4' }, - href: 'https://advent.sveltesociety.dev/' - }, - - // This one skips the blog post and just changes the link - { - id: 'advent2023-finished', - start: new Date('25 Dec, 2023 00:00:00 UTC'), - end: new Date('1 Jan, 2024 00:00:00 UTC'), - arrow: true, - content: { - lg: 'Advent of Svelte 2023 is over. See you next year!', - sm: 'Advent of Svelte 2023 is over!' - }, - href: 'https://advent.sveltesociety.dev/' - // scope: ['svelte.dev, kit.svelte.dev'] // Dont show on learn.svelte.dev by not adding it to the array + href: 'https://svelte.dev/' } ]) ); diff --git a/sites/svelte.dev/src/routes/blog/+page.server.js b/sites/svelte.dev/src/routes/blog/+page.server.js deleted file mode 100644 index 367fc36e70..0000000000 --- a/sites/svelte.dev/src/routes/blog/+page.server.js +++ /dev/null @@ -1,9 +0,0 @@ -import { get_blog_data, get_blog_list } from '$lib/server/blog/index.js'; - -export const prerender = true; - -export async function load() { - return { - posts: get_blog_list(await get_blog_data()) - }; -} diff --git a/sites/svelte.dev/src/routes/blog/+page.svelte b/sites/svelte.dev/src/routes/blog/+page.svelte deleted file mode 100644 index 39bd289603..0000000000 --- a/sites/svelte.dev/src/routes/blog/+page.svelte +++ /dev/null @@ -1,91 +0,0 @@ - - - - Blog • Svelte - - - - - - - -

Blog

-
- {#each data.posts as post} - {#if !post.draft} - - {/if} - {/each} -
- - diff --git a/sites/svelte.dev/src/routes/blog/[slug]/+page.server.js b/sites/svelte.dev/src/routes/blog/[slug]/+page.server.js deleted file mode 100644 index dc91f6a824..0000000000 --- a/sites/svelte.dev/src/routes/blog/[slug]/+page.server.js +++ /dev/null @@ -1,18 +0,0 @@ -import { get_blog_data, get_processed_blog_post } from '$lib/server/blog/index.js'; -import { error } from '@sveltejs/kit'; - -export const prerender = true; - -export async function load({ params }) { - const post = await get_processed_blog_post(await get_blog_data(), params.slug); - - if (!post) error(404); - - // forgive me — terrible hack necessary to get diffs looking sensible - // on the `runes` blog post - post.content = post.content.replace(/( )+/gm, (match) => ' '.repeat(match.length / 4)); - - return { - post - }; -} diff --git a/sites/svelte.dev/src/routes/blog/[slug]/+page.svelte b/sites/svelte.dev/src/routes/blog/[slug]/+page.svelte deleted file mode 100644 index bb13ba2a2e..0000000000 --- a/sites/svelte.dev/src/routes/blog/[slug]/+page.svelte +++ /dev/null @@ -1,137 +0,0 @@ - - - - {data.post.title} - - - - - - - - - - -
-
-

{data.post.title}

-

{data.post.description}

- - - - - - {@html data.post.content} -
-
- - diff --git a/sites/svelte.dev/src/routes/blog/[slug]/card.png/+server.js b/sites/svelte.dev/src/routes/blog/[slug]/card.png/+server.js deleted file mode 100644 index ed8a177ce6..0000000000 --- a/sites/svelte.dev/src/routes/blog/[slug]/card.png/+server.js +++ /dev/null @@ -1,51 +0,0 @@ -import { get_blog_data, get_processed_blog_post } from '$lib/server/blog/index.js'; -import { Resvg } from '@resvg/resvg-js'; -import { error } from '@sveltejs/kit'; -import satori from 'satori'; -import { html as toReactNode } from 'satori-html'; -import Card from './Card.svelte'; -import OverpassRegular from './Overpass-Regular.ttf'; - -const height = 630; -const width = 1200; - -export const prerender = true; - -export async function GET({ params }) { - const post = await get_processed_blog_post(await get_blog_data(), params.slug); - - if (!post) error(404); - - // @ts-ignore - const result = Card.render({ post }); - const element = toReactNode(`${result.html}`); - - const svg = await satori(element, { - fonts: [ - { - name: 'Overpass', - data: Buffer.from(OverpassRegular), - style: 'normal', - weight: 400 - } - ], - height, - width - }); - - const resvg = new Resvg(svg, { - fitTo: { - mode: 'width', - value: width - } - }); - - const image = resvg.render(); - - return new Response(image.asPng(), { - headers: { - 'content-type': 'image/png', - 'cache-control': 'public, max-age=600' // cache for 10 minutes - } - }); -} diff --git a/sites/svelte.dev/src/routes/blog/[slug]/card.png/Card.svelte b/sites/svelte.dev/src/routes/blog/[slug]/card.png/Card.svelte deleted file mode 100644 index 5e433eeed3..0000000000 --- a/sites/svelte.dev/src/routes/blog/[slug]/card.png/Card.svelte +++ /dev/null @@ -1,58 +0,0 @@ - - -
- Svelte Machine - -
-

{post.title}

-

{post.date_formatted}

-
-
- - diff --git a/sites/svelte.dev/src/routes/blog/[slug]/card.png/Overpass-Regular.ttf b/sites/svelte.dev/src/routes/blog/[slug]/card.png/Overpass-Regular.ttf deleted file mode 100644 index 3b32102d83..0000000000 Binary files a/sites/svelte.dev/src/routes/blog/[slug]/card.png/Overpass-Regular.ttf and /dev/null differ diff --git a/sites/svelte.dev/src/routes/blog/rss.xml/+server.js b/sites/svelte.dev/src/routes/blog/rss.xml/+server.js deleted file mode 100644 index 42ba7b80d7..0000000000 --- a/sites/svelte.dev/src/routes/blog/rss.xml/+server.js +++ /dev/null @@ -1,72 +0,0 @@ -import { get_blog_data, get_blog_list } from '$lib/server/blog/index.js'; - -export const prerender = true; - -const months = ',Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec'.split(','); - -/** @param {string} str */ -function formatPubdate(str) { - const [y, m, d] = str.split('-'); - return `${d} ${months[+m]} ${y} 12:00 +0000`; -} - -/** @param {string} html */ -function escapeHTML(html) { - /** @type {{ [key: string]: string }} */ - const chars = { - '"': 'quot', - "'": '#39', - '&': 'amp', - '<': 'lt', - '>': 'gt' - }; - - return html.replace(/["'&<>]/g, (c) => `&${chars[c]};`); -} - -/** @param {import('$lib/server/blog/types').BlogPostSummary[]} posts */ -const get_rss = (posts) => - ` - - - - - Svelte blog - https://svelte.dev/blog - News and information about the magical disappearing UI framework - - https://svelte.dev/favicon.png - Svelte - https://svelte.dev/blog - - ${posts - .filter((post) => !post.draft) - .map( - (post) => ` - - ${escapeHTML(post.title)} - https://svelte.dev/blog/${post.slug} - ${escapeHTML(post.description)} - ${formatPubdate(post.date)} - - ` - ) - .join('')} - - - -` - .replace(/>[^\S]+/gm, '>') - .replace(/[^\S]+ - - - - {data.example?.title} {data.example?.title ? '•' : ''} Svelte Examples - - - - - - -

Examples

-
-
- -
- -
-
- {#if mobile} - - {/if} -
- - diff --git a/sites/svelte.dev/src/routes/examples/[slug]/TableOfContents.svelte b/sites/svelte.dev/src/routes/examples/[slug]/TableOfContents.svelte deleted file mode 100644 index 1aa8a7965a..0000000000 --- a/sites/svelte.dev/src/routes/examples/[slug]/TableOfContents.svelte +++ /dev/null @@ -1,123 +0,0 @@ - - -
    - {#each sections as section} - - {#if section.title !== 'Embeds'} -
  • - {section.title} - - {#each section.examples as example} -
    - - {example.title} thumbnail - - {example.title} - - {#if example.slug === active_section} - REPL - {/if} -
    - {/each} -
  • - {/if} - {/each} -
- - diff --git a/sites/svelte.dev/src/routes/examples/api/+server.js b/sites/svelte.dev/src/routes/examples/api/+server.js deleted file mode 100644 index 36107147ba..0000000000 --- a/sites/svelte.dev/src/routes/examples/api/+server.js +++ /dev/null @@ -1,8 +0,0 @@ -// @ts-check -import examples_data from '$lib/generated/examples-data.js'; -import { get_examples_list } from '$lib/server/examples/index.js'; -import { json } from '@sveltejs/kit'; - -export const GET = () => { - return json(get_examples_list(examples_data)); -}; diff --git a/sites/svelte.dev/src/routes/examples/api/[slug].json/+server.js b/sites/svelte.dev/src/routes/examples/api/[slug].json/+server.js deleted file mode 100644 index 5255475f2f..0000000000 --- a/sites/svelte.dev/src/routes/examples/api/[slug].json/+server.js +++ /dev/null @@ -1,26 +0,0 @@ -import examples_data from '$lib/generated/examples-data.js'; -import { get_example, get_examples_list } from '$lib/server/examples/index.js'; -import { error, json } from '@sveltejs/kit'; - -export const prerender = true; - -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)) error(404, 'Example not found'); - - return json(get_example(examples_data, params.slug)); -}; - -export async function entries() { - const examples_list = get_examples_list(examples_data); - - return examples_list - .map(({ examples }) => examples) - .flatMap((val) => val.map(({ slug }) => ({ slug }))); -} diff --git a/sites/svelte.dev/src/routes/faq/+server.js b/sites/svelte.dev/src/routes/faq/+server.js deleted file mode 100644 index 6f35cdc67e..0000000000 --- a/sites/svelte.dev/src/routes/faq/+server.js +++ /dev/null @@ -1,7 +0,0 @@ -import { redirect } from '@sveltejs/kit'; - -export const prerender = true; - -export function GET() { - redirect(308, '/docs/faq'); -} diff --git a/sites/svelte.dev/src/routes/nav.json/+server.js b/sites/svelte.dev/src/routes/nav.json/+server.js index aa7c1eb069..ad2acb44b8 100644 --- a/sites/svelte.dev/src/routes/nav.json/+server.js +++ b/sites/svelte.dev/src/routes/nav.json/+server.js @@ -1,7 +1,5 @@ -import { get_blog_data, get_blog_list } from '$lib/server/blog/index.js'; import { get_docs_data, get_docs_list } from '$lib/server/docs/index.js'; -import { get_examples_list } from '$lib/server/examples/index.js'; -import examples_data from '$lib/generated/examples-data.js'; +import { get_tutorial_list, get_tutorial_data } from '$lib/server/tutorial/index.js'; import { json } from '@sveltejs/kit'; export const prerender = true; @@ -14,9 +12,9 @@ export const GET = async () => { * @returns {Promise} */ async function get_nav_list() { - const [docs_list, blog_list] = await Promise.all([ + const [docs_list, tutorial_list] = await Promise.all([ get_docs_list(await get_docs_data()), - get_blog_list(await get_blog_data()) + get_tutorial_list(await get_tutorial_data()) ]); const processed_docs_list = docs_list.map(({ title, pages }) => ({ @@ -24,25 +22,10 @@ async function get_nav_list() { sections: pages.map(({ title, path }) => ({ title, path })) })); - const processed_blog_list = [ - { - title: '', - sections: blog_list.map(({ title, slug, date }) => ({ - title, - path: '/blog/' + slug, - // Put a NEW badge on blog posts that are less than 14 days old - badge: (+new Date() - +new Date(date)) / (1000 * 60 * 60 * 24) < 14 ? 'NEW' : undefined - })) - } - ]; - - const examples_list = get_examples_list(examples_data); - const processed_examples_list = examples_list - .map(({ title, examples }) => ({ - title, - sections: examples.map(({ title, slug }) => ({ title, path: '/examples/' + slug })) - })) - .filter(({ title }) => title !== 'Embeds'); + const processed_tutorial_list = tutorial_list.map(({ title, tutorials }) => ({ + title, + sections: tutorials.map(({ title, slug }) => ({ title, path: '/tutorial/' + slug })) + })); return [ { @@ -57,31 +40,25 @@ async function get_nav_list() { ] }, { - title: 'Examples', - prefix: 'examples', - pathname: '/examples', + title: 'Tutorial', + prefix: 'tutorial', + pathname: '/tutorial', sections: [ { - title: 'EXAMPLES', - sections: processed_examples_list + title: 'TUTORIAL', + sections: processed_tutorial_list } ] }, { title: 'REPL', prefix: 'repl', - pathname: '/repl' + pathname: 'https://svelte.dev/playground' }, { title: 'Blog', prefix: 'blog', - pathname: '/blog', - sections: [ - { - title: 'BLOG', - sections: processed_blog_list - } - ] + pathname: 'https://svelte.dev/blog' } ]; } diff --git a/sites/svelte.dev/src/routes/roadmap/+page.js b/sites/svelte.dev/src/routes/roadmap/+page.js deleted file mode 100644 index 2010d73c9f..0000000000 --- a/sites/svelte.dev/src/routes/roadmap/+page.js +++ /dev/null @@ -1,8 +0,0 @@ -import { redirect } from '@sveltejs/kit'; - -export function load() { - redirect( - 307, - 'https://docs.google.com/document/d/1IA9Z5rcIm_KRxvh_L42d2NDdYRHZ72MfszhyJrsmf5A' - ); -} diff --git a/sites/svelte.dev/src/routes/stopwar.svg b/sites/svelte.dev/src/routes/stopwar.svg deleted file mode 100644 index 6e497c2c79..0000000000 --- a/sites/svelte.dev/src/routes/stopwar.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file