Skip to content

Commit 2d36b5b

Browse files
authored
remove nav.json (#326)
* remove nav.json * simplify * simplify * simplify * simplify * unused * simplify * begone
1 parent c80d9ba commit 2d36b5b

File tree

7 files changed

+71
-104
lines changed

7 files changed

+71
-104
lines changed

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

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { docs, index } from '$lib/server/content';
2+
import { fetchBanner } from '@sveltejs/site-kit/components';
3+
import type { NavigationLink } from '@sveltejs/site-kit';
4+
5+
const nav_links: NavigationLink[] = [
6+
{
7+
title: 'Docs',
8+
slug: 'docs',
9+
sections: Object.values(docs.topics)
10+
.map((topic) => ({
11+
title: topic.metadata.title,
12+
path: '/' + topic.slug, // this will make the UI show a flyout menu for the docs nav entry
13+
sections: topic.children.map((section) => ({
14+
title: section.metadata.title,
15+
sections: section.children.map((page) => ({
16+
title: page.metadata.title,
17+
path: '/' + page.slug
18+
}))
19+
}))
20+
}))
21+
.sort((a, b) => a.title.localeCompare(b.title)) // Svelte first
22+
},
23+
{
24+
title: 'Tutorial',
25+
slug: 'tutorial',
26+
sections: index.tutorial.children.map((topic) => ({
27+
title: topic.metadata.title,
28+
sections: topic.children.map((section) => ({
29+
title: section.metadata.title,
30+
sections: section.children.map((page) => ({
31+
title: page.metadata.title,
32+
path: '/tutorial/' + page.slug.split('/').pop()
33+
}))
34+
}))
35+
}))
36+
},
37+
{
38+
title: 'Playground',
39+
slug: 'playground'
40+
},
41+
{
42+
title: 'Blog',
43+
slug: 'blog'
44+
}
45+
];
46+
47+
const sections: Record<string, string> = {
48+
docs: 'Docs',
49+
playground: 'Playground',
50+
blog: 'Blog',
51+
tutorial: 'Tutorial',
52+
search: 'Search'
53+
};
54+
55+
export const load = async ({ url, fetch }) => {
56+
const banner = await fetchBanner('svelte.dev', fetch);
57+
const nav_title = sections[url.pathname.split('/')[1]!] ?? '';
58+
59+
return {
60+
nav_title,
61+
nav_links,
62+
banner
63+
};
64+
};

apps/svelte.dev/src/routes/nav.json/+server.ts

Lines changed: 0 additions & 61 deletions
This file was deleted.

packages/site-kit/src/lib/components/LinksDropdown.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
<Dropdown>
1010
<a
11-
href={link.pathname}
12-
aria-current={$page.url.pathname.startsWith(`/${link.prefix}`) ? 'page' : undefined}
11+
href="/{link.slug}"
12+
aria-current={$page.url.pathname.startsWith(`/${link.slug}`) ? 'page' : undefined}
1313
>
1414
{link.title}
1515

packages/site-kit/src/lib/nav/Menu.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
open_store.set(true);
1515
1616
const segment = get(page).url.pathname.split('/')[1];
17-
current_menu_view.set(get(links_store).find((link) => link.prefix === segment));
17+
current_menu_view.set(get(links_store).find((link) => link.slug === segment));
1818
1919
show_context_menu.set(!!get(current_menu_view)?.sections && !!get(current_menu_view));
2020
}
@@ -188,7 +188,7 @@
188188
<div class="contents" bind:clientHeight={universal_menu_inner_height}>
189189
{#each links as link}
190190
<div class="link-item" style:--button-width={link.sections ? '4rem' : '0'}>
191-
<a href={link.pathname}>
191+
<a href="/{link.slug}">
192192
{link.title}
193193
</a>
194194

packages/site-kit/src/lib/nav/Nav.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ Top navigation bar for the application. It provides a slot for the left side, th
8484
<LinksDropdown {link} />
8585
{:else}
8686
<a
87-
href={link.pathname}
88-
aria-current={$page.url.pathname.startsWith(`/${link.prefix}`) ? 'page' : null}
87+
href="/{link.slug}"
88+
aria-current={$page.url.pathname.startsWith(`/${link.slug}`) ? 'page' : null}
8989
>
9090
{link.title}
9191
</a>

packages/site-kit/src/lib/types.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
export interface NavigationLink {
22
title: string;
3-
prefix: string;
4-
pathname: string;
3+
slug: string;
54
sections?: {
65
title: string;
76
path?: string;

0 commit comments

Comments
 (0)