From 526763b795b7e486d8308eac7e26d758ebcd15c5 Mon Sep 17 00:00:00 2001 From: Hamcha Date: Fri, 14 Jul 2023 12:23:59 +0200 Subject: [PATCH] base homepage --- src/lib/mabel-types.ts | 15 ++++++++++++++- src/routes/+page.svelte | 19 ++++++++++++++++++- src/routes/+page.ts | 15 +++++++++++++++ src/routes/{post => p}/[slug]/+page.svelte | 0 src/routes/{post => p}/[slug]/+page.ts | 0 5 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 src/routes/+page.ts rename src/routes/{post => p}/[slug]/+page.svelte (100%) rename src/routes/{post => p}/[slug]/+page.ts (100%) 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