Skip to content

Commit 0a93d4a

Browse files
committed
make it work with tutorials, dedupe logic
1 parent 5f4f07d commit 0a93d4a

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import MobileSubMenu from './MobileSubMenu.svelte';
1111
import type { NavigationLink } from '../types';
1212
import ModalOverlay from '../components/ModalOverlay.svelte';
13+
import { github_link } from './Nav.svelte';
1314
1415
interface Props {
1516
links: NavigationLink[];
@@ -150,11 +151,7 @@
150151
<li><a href="https://bsky.app/profile/svelte.dev">Bluesky</a></li>
151152
<li>
152153
<a
153-
href="https://github.com/sveltejs/{page.url.pathname.startsWith('/docs/kit')
154-
? 'kit'
155-
: page.url.pathname.startsWith('/docs/cli')
156-
? 'cli'
157-
: 'svelte'}">GitHub</a
154+
href={github_link(page)}>GitHub</a
158155
>
159156
</li>
160157
</ul>

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22
Top navigation bar for the application. It provides a slot for the left side, the right side, and the center.
33
-->
44

5+
<script lang="ts" module>
6+
import type { Page } from '@sveltejs/kit';
7+
export function github_link(page: Page) {
8+
if (page.url.pathname.startsWith('/tutorial')) {
9+
return `https://github.com/sveltejs/${page.params.slug.split('/')[0]}`;
10+
}
11+
if (page.url.pathname.startsWith('/docs')) {
12+
return `https://github.com/sveltejs/${page.params.topic}`;
13+
}
14+
return 'https://github.com/sveltejs/svelte';
15+
}
16+
</script>
17+
518
<script lang="ts">
619
import { overlay_open, on_this_page_open } from '../stores';
720
import { search } from '../state/search.svelte';
@@ -133,14 +146,7 @@ Top navigation bar for the application. It provides a slot for the left side, th
133146
<span data-icon="bluesky"></span>
134147
</a>
135148

136-
<a
137-
href="https://github.com/sveltejs/{page.url.pathname.startsWith('/docs/kit')
138-
? 'kit'
139-
: page.url.pathname.startsWith('/docs/cli')
140-
? 'cli'
141-
: 'svelte'}"
142-
aria-label="GitHub Repo"
143-
>
149+
<a href={github_link(page)} aria-label="GitHub Repo">
144150
<span data-icon="github"></span>
145151
</a>
146152
</div>

0 commit comments

Comments
 (0)