Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
37 changes: 13 additions & 24 deletions apps/svelte.dev/src/routes/+layout.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,32 +51,21 @@ const nav_links: NavigationLink[] = [
}
];

const sections: Record<string, string> = {
docs: 'Docs',
playground: 'Playground',
blog: 'Blog',
tutorial: 'Tutorial',
search: 'Search'
};

const banner: BannerData = {
id: 'adventofsvelte2024',
start: new Date('1 December, 2024 00:00:00 UTC'),
end: new Date('25 December, 2024 23:59:59 UTC'),
arrow: true,
content: {
lg: 'Twenty-four days, twenty-four features: Advent of Svelte 2024',
sm: 'Advent of Svelte 2024'
},
href: '/blog/advent-of-svelte'
};

export const load = async ({ url }) => {
const nav_title = sections[url.pathname.split('/')[1]!] ?? '';
// const banner: BannerData = {
// id: 'adventofsvelte2024',
// start: new Date('1 December, 2024 00:00:00 UTC'),
// end: new Date('25 December, 2024 23:59:59 UTC'),
// arrow: true,
// content: {
// lg: 'Twenty-four days, twenty-four features: Advent of Svelte 2024',
// sm: 'Advent of Svelte 2024'
// },
// href: '/blog/advent-of-svelte'
// };

export const load = async () => {
return {
nav_title,
nav_links,
banner
banner: undefined
};
};
16 changes: 12 additions & 4 deletions apps/svelte.dev/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import '@sveltejs/site-kit/styles/index.css';
import { browser, dev } from '$app/environment';
import { page } from '$app/stores';
import { page } from '$app/state';
import { Shell, Banner } from '@sveltejs/site-kit/components';
import { Nav } from '@sveltejs/site-kit/nav';
import { SearchBox } from '@sveltejs/site-kit/search';
Expand All @@ -28,19 +28,27 @@
});

let { data, children: layout_children } = $props();

const sections: Record<string, string> = {
docs: 'Docs',
playground: 'Playground',
blog: 'Blog',
tutorial: 'Tutorial',
search: 'Search'
};
</script>

<svelte:head>
{#if !$page.route.id?.startsWith('/blog/')}
{#if !page.route.id?.startsWith('/blog/')}
<meta name="twitter:card" content="summary" />
<meta name="twitter:image" content="https://svelte.dev/images/twitter-thumbnail.jpg" />
<meta name="og:image" content="https://svelte.dev/images/twitter-thumbnail.jpg" />
{/if}
</svelte:head>

<Shell nav_visible={$page.route.id !== '/(authed)/playground/[id]/embed'}>
<Shell nav_visible={page.route.id !== '/(authed)/playground/[id]/embed'}>
{#snippet top_nav()}
<Nav title={data.nav_title} links={data.nav_links} />
<Nav title={sections[page.url.pathname.split('/')[1]!] ?? ''} links={data.nav_links} />
{/snippet}

{#snippet children()}
Expand Down
8 changes: 8 additions & 0 deletions apps/svelte.dev/src/routes/docs/[topic]/+page.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { docs } from '$lib/server/content';
import { redirect } from '@sveltejs/kit';

export async function load({ params }) {
const document = docs.topics[`docs/${params.topic}`];

redirect(307, `/${document.children[0].children[0].slug}`);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { redirect } from '@sveltejs/kit';
import { error } from '@sveltejs/kit';

export async function load({ params }) {
const topic = params.path.split('/')[0];
const document = docs.topics[`docs/${topic}`];
const document = docs.topics[`docs/${params.topic}`];

if (!document) {
// in many cases, https://svelte.dev/docs/foo is now https://svelte.dev/docs/svelte/foo
Expand All @@ -15,10 +14,6 @@ export async function load({ params }) {
error(404, 'Not found');
}

if (params.path === topic) {
redirect(307, `/${document.children[0].children[0].slug}`);
}

return {
sections: document.children.map(create_summary)
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { render_content } from '$lib/server/renderer';
import { error } from '@sveltejs/kit';

export async function load({ params }) {
const document = docs.pages[`docs/${params.path}`];
const document = docs.pages[`docs/${params.topic}/${params.path}`];

if (!document) {
error(404);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import { generate_llm_content, get_documentation_title, sections } from '$lib/se
export const prerender = true;

export function entries() {
return sections.map((section) => ({ path: section.slug }));
return sections.map((section) => {
const [topic, ...rest] = section.slug.split('/');
return { topic, path: rest.join('/') };
});
}

export function GET({ params }) {
const pkg = params.path;
const pkg = params.path ? `${params.topic}/${params.path}` : params.topic;

const section = sections.find((s) => s.slug === pkg);

Expand Down
4 changes: 1 addition & 3 deletions packages/site-kit/src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

declare global {
namespace App {
interface PageData {
nav_title: string;
}
interface PageData {}
}
}

Expand Down