From 1af8dd8c8d3bd71845bb63a01ef91be02d2fc9c0 Mon Sep 17 00:00:00 2001 From: Leni Aniva Date: Fri, 18 Oct 2024 10:38:13 -0700 Subject: [PATCH] fix: Cataloging problem on /post --- src/hooks.ts | 1 - src/lib/components/PostHeader.svelte | 2 +- src/lib/components/PostList.svelte | 64 ++++++++++++++++++++++++++++ src/routes/page/[slug]/+page.svelte | 58 +++---------------------- src/routes/page/[slug]/+page.ts | 8 ++-- src/routes/post/+page.server.ts | 19 ++++++--- src/routes/post/+page.svelte | 22 +++------- svelte.config.js | 1 - 8 files changed, 93 insertions(+), 82 deletions(-) create mode 100644 src/lib/components/PostList.svelte diff --git a/src/hooks.ts b/src/hooks.ts index 7ea2285..ac5feb1 100644 --- a/src/hooks.ts +++ b/src/hooks.ts @@ -1,7 +1,6 @@ import type { Reroute } from '@sveltejs/kit'; const translated: Record = { - '/post': '/page/1', }; export const reroute: Reroute = ({ url }) => { diff --git a/src/lib/components/PostHeader.svelte b/src/lib/components/PostHeader.svelte index c11f8d6..8410440 100644 --- a/src/lib/components/PostHeader.svelte +++ b/src/lib/components/PostHeader.svelte @@ -1,6 +1,6 @@ + + + +{#if maxPageN} +
+ +{/if} + + diff --git a/src/routes/page/[slug]/+page.svelte b/src/routes/page/[slug]/+page.svelte index 09996f0..4e5e710 100644 --- a/src/routes/page/[slug]/+page.svelte +++ b/src/routes/page/[slug]/+page.svelte @@ -1,14 +1,10 @@ @@ -16,49 +12,7 @@
- -
- + diff --git a/src/routes/page/[slug]/+page.ts b/src/routes/page/[slug]/+page.ts index dd9e8c7..c4753bb 100644 --- a/src/routes/page/[slug]/+page.ts +++ b/src/routes/page/[slug]/+page.ts @@ -1,7 +1,7 @@ -import { error } from '@sveltejs/kit'; -import type { PageLoad } from './$types'; -import { getPosts } from '$lib/posts'; -import siteMetadata from '$content/metadata.json'; +import { error } from '@sveltejs/kit' +import type { PageLoad } from './$types' +import { getPosts } from '$lib/posts' +import siteMetadata from '$content/metadata.json' export const load: PageLoad = async ({ params }) => { const pageN: number = +params.slug; diff --git a/src/routes/post/+page.server.ts b/src/routes/post/+page.server.ts index fc78cd1..f4fffc8 100644 --- a/src/routes/post/+page.server.ts +++ b/src/routes/post/+page.server.ts @@ -1,7 +1,14 @@ -import type { PageLoad } from './$types'; -import { getPosts } from '$lib/posts'; +import type { PageLoad } from './$types' +import { getPosts } from '$lib/posts' +import siteMetadata from '$content/metadata.json' -export const load: PageLoad = async (_) => { - const allPosts = await getPosts(); - return { allPosts }; -}; +export const load: PageLoad = async () => { + const posts = await getPosts(); + const pageSize = siteMetadata?.pageSize || 3; + const maxPageN = Math.ceil(posts.length / pageSize); + + return { + maxPageN, + posts: posts.slice(0, pageSize), + }; +} diff --git a/src/routes/post/+page.svelte b/src/routes/post/+page.svelte index 249c48f..62a29e4 100644 --- a/src/routes/post/+page.svelte +++ b/src/routes/post/+page.svelte @@ -1,9 +1,10 @@ @@ -11,17 +12,4 @@
-
    - {#each allPosts as post} -
  • - -
  • - {/each} -
-
- - + diff --git a/svelte.config.js b/svelte.config.js index 9820d65..e5db83a 100644 --- a/svelte.config.js +++ b/svelte.config.js @@ -79,7 +79,6 @@ const config = { prerender: { crawl: true, entries: [ - "/page/1/", ], }, alias: {