Skip to content

Commit d6be3ad

Browse files
committed
šŸ› ļø Upgrade main +layout, +page.ts & +layout from /directory to Svelte 5 syntax
1 parent d75490b commit d6be3ad

File tree

4 files changed

+41
-22
lines changed

4 files changed

+41
-22
lines changed

ā€Žsrc/routes/+layout.svelteā€Ž

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
11
<script lang="ts">
22
import type { LayoutServerData } from './$types';
3-
export let data: LayoutServerData;
3+
import type { Snippet } from 'svelte';
4+
import { page } from '$app/state';
45
56
// Global styles:
6-
import '../app.css';
7+
import '@/styles/globals.css';
78
import { cn } from '@/utils/cn';
89
import { ModeWatcher, mode } from 'mode-watcher';
10+
911
import { sidebarCategoryCountStyles } from '@/ui/styles';
1012
import { sidebarItemStyles } from '@/ui/styles';
1113
1214
// Get categories:
1315
import { svgs } from '@/data/svgs';
14-
const categories = getCategories();
15-
16-
// Get category counts:
17-
let categoryCounts: Record<string, number> = {};
18-
categories.forEach((category) => {
19-
categoryCounts[category] = svgs.filter((svg) => svg.category.includes(category)).length;
20-
});
2116
2217
// Toaster:
2318
import { Toaster } from 'svelte-sonner';
@@ -29,10 +24,25 @@
2924
// Layout:
3025
import Navbar from '@/components/navbar.svelte';
3126
import { getCategories } from '@/data';
27+
28+
interface Props {
29+
data: LayoutServerData;
30+
children?: Snippet;
31+
}
32+
33+
const categories = getCategories();
34+
35+
// Get category counts:
36+
let categoryCounts: Record<string, number> = $state({});
37+
categories.forEach((category) => {
38+
categoryCounts[category] = svgs.filter((svg) => svg.category.includes(category)).length;
39+
});
40+
41+
let { children }: Props = $props();
3242
</script>
3343

3444
<ModeWatcher />
35-
<Navbar currentPath={data.pathname} />
45+
<Navbar currentPath={page.url.pathname} />
3646
<main>
3747
<aside
3848
class={cn(
@@ -51,7 +61,7 @@
5161
href="/"
5262
class={cn(
5363
sidebarItemStyles,
54-
data.pathname === '/'
64+
page.url.pathname === '/'
5565
? 'bg-neutral-200 font-medium text-dark dark:bg-neutral-700/30 dark:text-white'
5666
: ''
5767
)}
@@ -64,7 +74,7 @@
6474
data-sveltekit-preload-data
6575
class={cn(
6676
sidebarItemStyles,
67-
data.pathname === `/directory/${category.toLowerCase()}`
77+
page.url.pathname === `/directory/${category.toLowerCase()}`
6878
? 'bg-neutral-200 font-medium text-dark dark:bg-neutral-700/30 dark:text-white'
6979
: ''
7080
)}
@@ -73,7 +83,7 @@
7383
<span
7484
class={cn(
7585
sidebarCategoryCountStyles,
76-
data.pathname === `/directory/${category.toLowerCase()}`
86+
page.url.pathname === `/directory/${category.toLowerCase()}`
7787
? 'border-neutral-300 dark:border-neutral-700'
7888
: '',
7989
'hidden font-mono text-xs md:inline'
@@ -86,8 +96,8 @@
8696
</aside>
8797
<div class="ml-0 pb-6 md:ml-56">
8898
<Warning />
89-
<Transition pathname={data.pathname}>
90-
<slot />
99+
<Transition pathname={page.url.pathname}>
100+
{@render children?.()}
91101
</Transition>
92102
<Toaster
93103
position="bottom-right"

ā€Žsrc/routes/api/+page.svelteā€Ž

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script>
22
import { cn } from '@/utils/cn';
3-
export let data;
3+
/** @type {{data: any}} */
4+
let { data } = $props();
45
</script>
56

67
<svelte:head>
@@ -23,7 +24,7 @@
2324
<span class="relative inline-block overflow-hidden rounded-full p-[1px] shadow-sm">
2425
<span
2526
class="absolute inset-[-1000%] animate-[spin_4s_linear_infinite] bg-[conic-gradient(from_90deg_at_50%_50%,#f4f4f5_0%,#f4f4f5_50%,#737373_100%)] dark:bg-[conic-gradient(from_90deg_at_50%_50%,#121212_0%,#121212_50%,#737373_100%)]"
26-
/>
27+
></span>
2728
<div
2829
class="inline-flex h-full w-full cursor-default items-center justify-center rounded-full border border-neutral-100 bg-neutral-100 px-3 py-1 font-mono text-xs font-medium backdrop-blur-3xl dark:border-neutral-800 dark:bg-neutral-900 dark:text-white"
2930
>
@@ -45,5 +46,5 @@
4546
'prose-pre:m-0 prose-pre:border prose-pre:border-neutral-200 dark:prose-pre:border dark:prose-pre:border-neutral-800/65'
4647
)}
4748
>
48-
<svelte:component this={data.content} />
49+
<data.content />
4950
</article>

ā€Žsrc/routes/api/+page.tsā€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ export async function load() {
99
meta: post.metadata
1010
};
1111
} catch (e) {
12-
throw error(404, `Could not find this page`);
12+
throw error(404, `āš ļø +page.ts: Could not find this page - ${e}`);
1313
}
1414
}
Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
1-
<script>
1+
<script lang="ts">
2+
import type { Snippet } from 'svelte';
3+
24
import Container from '@/components/container.svelte';
35
import { ArrowLeft } from 'lucide-svelte';
6+
7+
interface LayoutProps {
8+
children?: Snippet;
9+
}
10+
11+
let { children }: LayoutProps = $props();
412
</script>
513

614
<Container>
715
<a href="/">
816
<div
9-
class="flex items-center space-x-2 duration-100 hover:text-neutral-500 dark:text-neutral-400 dark:hover:text-white group md:mt-2"
17+
class="group flex items-center space-x-2 duration-100 hover:text-neutral-500 dark:text-neutral-400 dark:hover:text-white md:mt-2"
1018
>
1119
<ArrowLeft size={20} class="group-hover:-translate-x-[2px] group-hover:duration-200" />
1220
<span>View all</span>
1321
</div>
1422
</a>
1523
</Container>
16-
<slot />
24+
{@render children?.()}

0 commit comments

Comments
Ā (0)