Blog index reworked
This commit is contained in:
parent
fd719937d9
commit
eafc8b7082
@ -1,39 +1,12 @@
|
||||
<script lang="ts" context="module">
|
||||
import { parseParams } from '$lib/pagination/dropTakeParams'
|
||||
|
||||
/**
|
||||
* @type {import('@sveltejs/kit').Load}
|
||||
*/
|
||||
export async function load({ fetch, params }) {
|
||||
const { page = 1, pageSize = 7, ...filters } = parseParams(params.params)
|
||||
const articleResponse = await fetch(
|
||||
`/blog/articles/${params.params ? params.params : 'index'}.json`
|
||||
).then((r) => r.json())
|
||||
|
||||
return {
|
||||
props: {
|
||||
posts: articleResponse.posts,
|
||||
page: Number(page),
|
||||
pageSize,
|
||||
filters,
|
||||
},
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import ArticleFooter from '../../components/blog/ArticleFooter.svelte'
|
||||
import Paginator from '../../components/paginator/Paginator.svelte'
|
||||
import ArticleFooter from '../../../components/blog/ArticleFooter.svelte'
|
||||
import Paginator from '../../../components/paginator/Paginator.svelte'
|
||||
import { postListClass, seeAllClass } from './index.css'
|
||||
import type { PostContent } from './content'
|
||||
import type { PaginationResult } from '$lib/pagination/pagination'
|
||||
import type { PageData } from './$types'
|
||||
|
||||
export let posts: PaginationResult<PostContent>
|
||||
export let filters: Record<string, string>
|
||||
export let page: number
|
||||
export let pageSize: number
|
||||
|
||||
let totalPages = Math.ceil(posts.totalCount / pageSize)
|
||||
export let data: PageData
|
||||
let { posts, filters, page, pageSize } = data
|
||||
$: ({ posts, filters, page, pageSize } = data)
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
18
src/routes/blog/[...params]/+page.ts
Normal file
18
src/routes/blog/[...params]/+page.ts
Normal file
@ -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<PostContent>,
|
||||
page: Number(page),
|
||||
pageSize,
|
||||
filters,
|
||||
}
|
||||
}) satisfies PageLoad
|
Loading…
Reference in New Issue
Block a user