From eafc8b7082d44ed38598e6a65e464a6361a6bf26 Mon Sep 17 00:00:00 2001 From: Michal Vanko Date: Tue, 31 Jan 2023 19:47:19 +0100 Subject: [PATCH] Blog index reworked --- .../+page.svelte} | 39 +++---------------- src/routes/blog/[...params]/+page.ts | 18 +++++++++ .../blog/{ => [...params]}/index.css.ts | 0 3 files changed, 24 insertions(+), 33 deletions(-) rename src/routes/blog/{[...params].svelte => [...params]/+page.svelte} (51%) create mode 100644 src/routes/blog/[...params]/+page.ts rename src/routes/blog/{ => [...params]}/index.css.ts (100%) diff --git a/src/routes/blog/[...params].svelte b/src/routes/blog/[...params]/+page.svelte similarity index 51% rename from src/routes/blog/[...params].svelte rename to src/routes/blog/[...params]/+page.svelte index f70bbd2..d869d49 100644 --- a/src/routes/blog/[...params].svelte +++ b/src/routes/blog/[...params]/+page.svelte @@ -1,39 +1,12 @@ - - diff --git a/src/routes/blog/[...params]/+page.ts b/src/routes/blog/[...params]/+page.ts new file mode 100644 index 0000000..1c9a243 --- /dev/null +++ b/src/routes/blog/[...params]/+page.ts @@ -0,0 +1,18 @@ +import { parseParams } from '$lib/pagination/dropTakeParams' +import type { PageLoad } from './$types' +import type { PostContent } from './../content' +import type { PaginationResult } from '$lib/pagination/pagination' + +export const load = (async ({ fetch, params }) => { + const { page = 1, pageSize = 7, ...filters } = parseParams(params.params) + const articleResponse = await fetch( + `/blog/articles/${params.params ? params.params : 'index'}` + ).then((r) => r.json()) + + return { + posts: articleResponse.posts as PaginationResult, + page: Number(page), + pageSize, + filters, + } +}) satisfies PageLoad diff --git a/src/routes/blog/index.css.ts b/src/routes/blog/[...params]/index.css.ts similarity index 100% rename from src/routes/blog/index.css.ts rename to src/routes/blog/[...params]/index.css.ts