diff --git a/src/lib/mabel-types.ts b/src/lib/mabel-types.ts index be81955..3af7b0f 100644 --- a/src/lib/mabel-types.ts +++ b/src/lib/mabel-types.ts @@ -4,12 +4,20 @@ export interface Site { owner_display_name: string; title: string; description: string | null; - collections: { slug: string; name: string }[]; + collections: Collection[]; + default_collection: string; created_at: string; modified_at: string | null; deleted_at: string | null; } +export interface Collection { + id: string; + name: string; + slug: string; + parent: string | null; +} + export interface Post { id: string; site: string; @@ -24,3 +32,8 @@ export interface Post { modified_at: string | null; deleted_at: string | null; } + +export interface PaginatedWithCursor { + items: T[]; + next_cursor: C | null; +} diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 159202e..e1e6706 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -1 +1,18 @@ -

Hello world

+ + +{#if data.pages} + {#each data.pages.items as post} +
+
+

{post.title}

+

by {post.author_display_name} on {new Date(post.created_at).toLocaleDateString()}

+
+
+ {/each} +{:else} + +{/if} diff --git a/src/routes/+page.ts b/src/routes/+page.ts new file mode 100644 index 0000000..de158a3 --- /dev/null +++ b/src/routes/+page.ts @@ -0,0 +1,15 @@ +import { PUBLIC_API_BASE } from '$env/static/public'; +import type { PaginatedWithCursor, Post } from '$lib/mabel-types'; +import type { PageLoad } from './$types'; + +export const load = (async ({ parent }) => { + const { site } = await parent(); + + const data = await fetch( + `${PUBLIC_API_BASE}/collections/${site.name}/${site.default_collection}/posts` + ); + + return { + pages: (await data.json()) as PaginatedWithCursor + }; +}) satisfies PageLoad; diff --git a/src/routes/post/[slug]/+page.svelte b/src/routes/p/[slug]/+page.svelte similarity index 100% rename from src/routes/post/[slug]/+page.svelte rename to src/routes/p/[slug]/+page.svelte diff --git a/src/routes/post/[slug]/+page.ts b/src/routes/p/[slug]/+page.ts similarity index 100% rename from src/routes/post/[slug]/+page.ts rename to src/routes/p/[slug]/+page.ts