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 @@
- -
- - + 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} -
+
diff --git a/svelte.config.js b/svelte.config.js index ab79a1c..deabdb8 100644 --- a/svelte.config.js +++ b/svelte.config.js @@ -91,9 +91,7 @@ const config = { }), prerender: { crawl: true, - entries: [ - "/page/1/", - ], + entries: ['*'], }, alias: { $content: contentDir, diff --git a/tests/post.spec.ts b/tests/post.spec.ts index bcd1052..fde2be8 100644 --- a/tests/post.spec.ts +++ b/tests/post.spec.ts @@ -5,3 +5,15 @@ test('Navigate to blog post', async ({ page }) => { await page.getByText('The Perfect Math Class').click(); await expect(page).toHaveURL("/post/the-perfect-math-class/"); }); + +test('Navigate to page 2', async ({ page }) => { + await page.goto('/post'); + await page.getByRole('link', { name: 'Next Page' }).click(); + await expect(page).toHaveURL("/page/2/"); + await page.getByRole('link', { name: 'Prev Page' }).click(); + await expect(page).toHaveURL("/post/"); + await page.getByRole('link', { name: 'Last Page' }).click(); + await expect(page).toHaveURL("/page/2/"); + await page.getByRole('link', { name: 'First Page' }).click(); + await expect(page).toHaveURL("/post/"); +});