From 1af8dd8c8d3bd71845bb63a01ef91be02d2fc9c0 Mon Sep 17 00:00:00 2001 From: Leni Aniva Date: Fri, 18 Oct 2024 10:38:13 -0700 Subject: [PATCH 1/5] 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: { -- 2.44.1 From 19519fb30e2c336e36280bc0ea491d3b55b6e34c Mon Sep 17 00:00:00 2001 From: Leni Aniva Date: Fri, 18 Oct 2024 10:46:44 -0700 Subject: [PATCH 2/5] fix: Prerender page crawling --- svelte.config.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/svelte.config.js b/svelte.config.js index e5db83a..0febb69 100644 --- a/svelte.config.js +++ b/svelte.config.js @@ -78,8 +78,7 @@ const config = { }), prerender: { crawl: true, - entries: [ - ], + entries: ['*'], }, alias: { $content: contentDir, -- 2.44.1 From 38aeb1e80d1590b319e9b5d96ea44902585cbde9 Mon Sep 17 00:00:00 2001 From: Leni Aniva Date: Fri, 18 Oct 2024 10:48:02 -0700 Subject: [PATCH 3/5] refactor: Use PostList in tag --- src/routes/tag/[slug]/+page.svelte | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/src/routes/tag/[slug]/+page.svelte b/src/routes/tag/[slug]/+page.svelte index 42ad300..ef8521c 100644 --- a/src/routes/tag/[slug]/+page.svelte +++ b/src/routes/tag/[slug]/+page.svelte @@ -1,9 +1,9 @@ @@ -11,19 +11,9 @@

{name} ({posts.length})

-
-
    - {#each posts as post} -
  • - -
  • - {/each} -
+
-- 2.44.1 From 401db3787ec61523f32af1a691de5392f428ca0c Mon Sep 17 00:00:00 2001 From: Leni Aniva Date: Fri, 18 Oct 2024 10:51:03 -0700 Subject: [PATCH 4/5] fix: Remove /page/1 link --- src/lib/components/PostList.svelte | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/lib/components/PostList.svelte b/src/lib/components/PostList.svelte index 1c4968e..d2de152 100644 --- a/src/lib/components/PostList.svelte +++ b/src/lib/components/PostList.svelte @@ -10,7 +10,8 @@ const disableLinkPrev = pageN == 1; const disableLinkNext = pageN == maxPageN; - const prevLink = pageN == 1 ? "/post" : `/page/${pageN - 1}`; + const firstPageLink = "/post"; + const prevLink = pageN <= 2 ? firstPageLink : `/page/${pageN - 1}`;