Skip to content

Commit

Permalink
Merge pull request #38 from magicalpuffin/upgrate-svelte-5
Browse files Browse the repository at this point in the history
upgrading to svelte 5
  • Loading branch information
magicalpuffin authored Oct 26, 2024
2 parents f2f08ff + 7952204 commit ee67935
Show file tree
Hide file tree
Showing 17 changed files with 411 additions and 367 deletions.
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,35 @@
"format": "prettier --write ."
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20241018.0",
"@sveltejs/adapter-auto": "^3.2.5",
"@sveltejs/adapter-cloudflare": "^4.7.3",
"@sveltejs/enhanced-img": "^0.3.9",
"@sveltejs/kit": "^2.7.2",
"@sveltejs/vite-plugin-svelte": "^3.1.2",
"@cloudflare/workers-types": "^4.20241022.0",
"@sveltejs/adapter-auto": "^3.3.1",
"@sveltejs/adapter-cloudflare": "^4.7.4",
"@sveltejs/enhanced-img": "^0.3.10",
"@sveltejs/kit": "^2.7.3",
"@sveltejs/vite-plugin-svelte": "^4.0.0",
"@tailwindcss/typography": "^0.5.15",
"@types/eslint": "^9.6.1",
"@types/hast": "^3.0.4",
"autoprefixer": "^10.4.20",
"daisyui": "^4.12.13",
"eslint": "^9.13.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-svelte": "^2.45.1",
"eslint-plugin-svelte": "^2.46.0",
"globals": "^15.11.0",
"lucide-svelte": "^0.453.0",
"mdsvex": "^0.12.3",
"prettier": "^3.3.3",
"prettier-plugin-svelte": "^3.2.7",
"prettier-plugin-tailwindcss": "^0.6.8",
"shiki": "^1.22.0",
"svelte": "^4.2.19",
"shiki": "^1.22.1",
"svelte": "^5.1.3",
"svelte-check": "^4.0.5",
"tailwindcss": "^3.4.14",
"typescript": "^5.6.3",
"typescript-eslint": "^8.10.0",
"typescript-eslint": "^8.11.0",
"unist-util-visit": "^5.0.0",
"vite": "^5.4.9",
"wrangler": "^3.81.0"
"vite": "^5.4.10",
"wrangler": "^3.83.0"
},
"type": "module",
"volta": {
Expand Down
619 changes: 300 additions & 319 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

13 changes: 11 additions & 2 deletions src/lib/components/Heading1.svelte
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
<h1 class="my-4 text-4xl font-bold" {...$$restProps}>
<slot />
<script lang="ts">
import type { HTMLAttributes } from 'svelte/elements';
interface Props extends HTMLAttributes<HTMLHeadElement> {
children?: import('svelte').Snippet;
}
let { children, ...rest }: Props = $props();
</script>

<h1 class="my-4 text-4xl font-bold" {...rest}>
{@render children?.()}
</h1>
20 changes: 15 additions & 5 deletions src/lib/components/blog/Blog.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@
import BlogHeader from './BlogHeader.svelte';
import BlogContent from './BlogContent.svelte';
export let title: string;
export let createdDate: string;
export let updatedDate: string | undefined = undefined;
interface Props {
title: string;
createdDate: string;
updatedDate?: string | undefined;
children?: import('svelte').Snippet;
}
let {
title,
createdDate,
updatedDate = undefined,
children
}: Props = $props();
</script>

<BlogHeader {title} {createdDate} {updatedDate} />
<div class="my-1 divider" />
<BlogContent><slot /></BlogContent>
<div class="my-1 divider"></div>
<BlogContent>{@render children?.()}</BlogContent>
7 changes: 6 additions & 1 deletion src/lib/components/blog/BlogContent.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
<script lang="ts">
import '$lib/styles/blog-styles.css';
interface Props {
children?: import('svelte').Snippet;
}
let { children }: Props = $props();
</script>

<article
class="prose prose-img:my-0 prose-img:rounded-lg prose-img:mx-auto prose-img:shadow-lg"
>
<slot />
{@render children?.()}
</article>
10 changes: 7 additions & 3 deletions src/lib/components/blog/BlogHeader.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
import CalendarIcon from 'lucide-svelte/icons/calendar';
import InfoIcon from 'lucide-svelte/icons/info';
export let title: string;
export let createdDate: string;
export let updatedDate: string | undefined = undefined;
interface Props {
title: string;
createdDate: string;
updatedDate?: string | undefined;
}
let { title, createdDate, updatedDate = undefined }: Props = $props();
</script>

<Heading1 id="blogTitle">
Expand Down
14 changes: 10 additions & 4 deletions src/lib/components/carousel/Carousel.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
<script lang="ts">
export let activeIndex: number = 0;
let carousel: HTMLElement;
interface Props {
activeIndex?: number;
children?: import('svelte').Snippet;
}
let { activeIndex = $bindable(0), children }: Props = $props();
let carousel: HTMLElement | undefined = $state();
function updateActiveIndex() {
if (!carousel) return 0;
const xLeft = carousel.scrollLeft;
const xWidth = carousel.clientWidth;
Expand All @@ -15,9 +21,9 @@
<div
class="w-full carousel"
bind:this={carousel}
on:scroll={() => {
onscroll={() => {
activeIndex = updateActiveIndex();
}}
>
<slot />
{@render children?.()}
</div>
21 changes: 16 additions & 5 deletions src/lib/components/carousel/CarouselCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,21 @@
import ExternalLinkIcon from 'lucide-svelte/icons/external-link';
import GitHubIcon from '$lib/components/icons/GitHubIcon.svelte';
export let title: string;
export let detailUrl: string | undefined = undefined;
export let githubUrl: string | undefined = undefined;
export let imgSrc: string;
interface Props {
title: string;
detailUrl?: string | undefined;
githubUrl?: string | undefined;
imgSrc: string;
children?: import('svelte').Snippet;
}
let {
title,
detailUrl = undefined,
githubUrl = undefined,
imgSrc,
children
}: Props = $props();
</script>

<div class="rounded-2xl border shadow-lg md:h-96">
Expand Down Expand Up @@ -44,7 +55,7 @@
alt="project screenshot"
/>
<article class="my-2 mx-2 prose">
<slot />
{@render children?.()}
</article>
</div>
</div>
Expand Down
8 changes: 6 additions & 2 deletions src/lib/components/carousel/CarouselMenu.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<script lang="ts">
export let links: string[];
export let activeIndex: number;
interface Props {
links: string[];
activeIndex: number;
}
let { links, activeIndex }: Props = $props();
</script>

<div class="flex gap-1 py-2">
Expand Down
8 changes: 6 additions & 2 deletions src/lib/components/icons/GitHubIcon.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<script lang="ts">
// https://iconoir.com/
export let color: string = 'currentColor';
interface Props {
// https://iconoir.com/
color?: string;
}
let { color = 'currentColor' }: Props = $props();
</script>

<svg
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/navbar/Navbar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</div>
<div class="navbar-end">
<div class="md:hidden dropdown dropdown-end">
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
<div tabindex="0" class="btn btn-ghost">
<MenuIcon />
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ComponentType } from "svelte";
import type { Component } from "svelte";

export type BlogMetadata = {
id: number;
Expand All @@ -11,5 +11,5 @@ export type BlogMetadata = {

export type BlogModules = Record<
string,
() => Promise<{ default: ComponentType; metadata: BlogMetadata }>
() => Promise<{ default: Component; metadata: BlogMetadata }>
>;
6 changes: 4 additions & 2 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<script>
<script lang="ts">
import '../app.css';
import Navbar from '$lib/components/navbar/Navbar.svelte';
import Footer from '$lib/components/Footer.svelte';
let { children } = $props();
</script>

<Navbar />
<main>
<div class="flex justify-center my-2 mx-2">
<div class="container max-w-3xl">
<slot></slot>
{@render children?.()}
</div>
</div>
</main>
Expand Down
4 changes: 2 additions & 2 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
} from '$lib/components/carousel';
import Heading1 from '$lib/components/Heading1.svelte';
let demoCarouselIndex = 0;
let notebookCarouselIndex = 0;
let demoCarouselIndex = $state(0);
let notebookCarouselIndex = $state(0);
</script>

<svelte:head
Expand Down
6 changes: 5 additions & 1 deletion src/routes/blog/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
//import { blogList } from '$lib/content/blogList';
import type { PageData } from './$types';
export let data: PageData;
interface Props {
data: PageData;
}
let { data }: Props = $props();
</script>

<svelte:head
Expand Down
8 changes: 6 additions & 2 deletions src/routes/blog/[slug]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
import { Blog } from '$lib/components/blog';
import type { PageData } from './$types';
export let data: PageData;
interface Props {
data: PageData;
}
let { data }: Props = $props();
</script>

<svelte:head
Expand All @@ -17,5 +21,5 @@
createdDate={data.blogPost.createdDate}
updatedDate={data.blogPost.updatedDate}
>
<svelte:component this={data.blogPost.component} />
<data.blogPost.component />
</Blog>
4 changes: 2 additions & 2 deletions src/routes/blog/[slug]/+page.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { BlogMetadata, BlogModules } from "$lib/types.js";
import { error, redirect } from "@sveltejs/kit";
import type { ComponentType } from "svelte";
import type { Component } from "svelte";
import type { EntryGenerator, PageLoad } from "./$types.js";

export const prerender = "auto";
Expand All @@ -11,7 +11,7 @@ export const load = (async ({ params, fetch }) => {
//const modules = import.meta.glob("/src/lib/content/blog/*.md");
const modules = import.meta.glob("/src/lib/content/blog/*.md") as BlogModules;

const blogMetadataList: (BlogMetadata & { component: ComponentType })[] = [];
const blogMetadataList: (BlogMetadata & { component: Component })[] = [];

for (const path of Object.keys(modules)) {
await modules[path]().then((mod) => {
Expand Down

0 comments on commit ee67935

Please sign in to comment.