Skip to content

Commit 041bdfa

Browse files
authored
Better docs invalidation (#1286)
* make invalidation more granular * avoid invalidating root layout on every navigation * fix * lint
1 parent 6cc451b commit 041bdfa

File tree

11 files changed

+41
-40
lines changed

11 files changed

+41
-40
lines changed

apps/svelte.dev/src/routes/+layout.server.ts

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -51,32 +51,21 @@ const nav_links: NavigationLink[] = [
5151
}
5252
];
5353

54-
const sections: Record<string, string> = {
55-
docs: 'Docs',
56-
playground: 'Playground',
57-
blog: 'Blog',
58-
tutorial: 'Tutorial',
59-
search: 'Search'
60-
};
61-
62-
const banner: BannerData = {
63-
id: 'adventofsvelte2024',
64-
start: new Date('1 December, 2024 00:00:00 UTC'),
65-
end: new Date('25 December, 2024 23:59:59 UTC'),
66-
arrow: true,
67-
content: {
68-
lg: 'Twenty-four days, twenty-four features: Advent of Svelte 2024',
69-
sm: 'Advent of Svelte 2024'
70-
},
71-
href: '/blog/advent-of-svelte'
72-
};
73-
74-
export const load = async ({ url }) => {
75-
const nav_title = sections[url.pathname.split('/')[1]!] ?? '';
54+
// const banner: BannerData = {
55+
// id: 'adventofsvelte2024',
56+
// start: new Date('1 December, 2024 00:00:00 UTC'),
57+
// end: new Date('25 December, 2024 23:59:59 UTC'),
58+
// arrow: true,
59+
// content: {
60+
// lg: 'Twenty-four days, twenty-four features: Advent of Svelte 2024',
61+
// sm: 'Advent of Svelte 2024'
62+
// },
63+
// href: '/blog/advent-of-svelte'
64+
// };
7665

66+
export const load = async () => {
7767
return {
78-
nav_title,
7968
nav_links,
80-
banner
69+
banner: undefined
8170
};
8271
};

apps/svelte.dev/src/routes/+layout.svelte

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script lang="ts">
22
import '@sveltejs/site-kit/styles/index.css';
33
import { browser, dev } from '$app/environment';
4-
import { page } from '$app/stores';
4+
import { page } from '$app/state';
55
import { Shell, Banner } from '@sveltejs/site-kit/components';
66
import { Nav } from '@sveltejs/site-kit/nav';
77
import { SearchBox } from '@sveltejs/site-kit/search';
@@ -28,19 +28,27 @@
2828
});
2929
3030
let { data, children: layout_children } = $props();
31+
32+
const sections: Record<string, string> = {
33+
docs: 'Docs',
34+
playground: 'Playground',
35+
blog: 'Blog',
36+
tutorial: 'Tutorial',
37+
search: 'Search'
38+
};
3139
</script>
3240

3341
<svelte:head>
34-
{#if !$page.route.id?.startsWith('/blog/')}
42+
{#if !page.route.id?.startsWith('/blog/')}
3543
<meta name="twitter:card" content="summary" />
3644
<meta name="twitter:image" content="https://svelte.dev/images/twitter-thumbnail.jpg" />
3745
<meta name="og:image" content="https://svelte.dev/images/twitter-thumbnail.jpg" />
3846
{/if}
3947
</svelte:head>
4048

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

4654
{#snippet children()}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { docs } from '$lib/server/content';
2+
import { redirect } from '@sveltejs/kit';
3+
4+
export async function load({ params }) {
5+
const document = docs.topics[`docs/${params.topic}`];
6+
7+
redirect(307, `/${document.children[0].children[0].slug}`);
8+
}

apps/svelte.dev/src/routes/docs/[...path]/+layout.server.ts renamed to apps/svelte.dev/src/routes/docs/[topic]/[...path]/+layout.server.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import { redirect } from '@sveltejs/kit';
33
import { error } from '@sveltejs/kit';
44

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

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

18-
if (params.path === topic) {
19-
redirect(307, `/${document.children[0].children[0].slug}`);
20-
}
21-
2217
return {
2318
sections: document.children.map(create_summary)
2419
};
File renamed without changes.

apps/svelte.dev/src/routes/docs/[...path]/+page.server.js renamed to apps/svelte.dev/src/routes/docs/[topic]/[...path]/+page.server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { render_content } from '$lib/server/renderer';
33
import { error } from '@sveltejs/kit';
44

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

88
if (!document) {
99
error(404);
File renamed without changes.
File renamed without changes.
File renamed without changes.

apps/svelte.dev/src/routes/docs/[...path]/llms.txt/+server.ts renamed to apps/svelte.dev/src/routes/docs/[topic]/[...path]/llms.txt/+server.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ import { generate_llm_content, get_documentation_title, sections } from '$lib/se
44
export const prerender = true;
55

66
export function entries() {
7-
return sections.map((section) => ({ path: section.slug }));
7+
return sections.map((section) => {
8+
const [topic, ...rest] = section.slug.split('/');
9+
return { topic, path: rest.join('/') };
10+
});
811
}
912

1013
export function GET({ params }) {
11-
const pkg = params.path;
14+
const pkg = params.path ? `${params.topic}/${params.path}` : params.topic;
1215

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

0 commit comments

Comments
 (0)