Blog index reworked

This commit is contained in:
Michal Vanko 2023-01-31 19:47:19 +01:00
parent fd719937d9
commit eafc8b7082
3 changed files with 24 additions and 33 deletions

View File

@ -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"> <script lang="ts">
import ArticleFooter from '../../components/blog/ArticleFooter.svelte' import ArticleFooter from '../../../components/blog/ArticleFooter.svelte'
import Paginator from '../../components/paginator/Paginator.svelte' import Paginator from '../../../components/paginator/Paginator.svelte'
import { postListClass, seeAllClass } from './index.css' import { postListClass, seeAllClass } from './index.css'
import type { PostContent } from './content' import type { PageData } from './$types'
import type { PaginationResult } from '$lib/pagination/pagination'
export let posts: PaginationResult<PostContent> export let data: PageData
export let filters: Record<string, string> let { posts, filters, page, pageSize } = data
export let page: number $: ({ posts, filters, page, pageSize } = data)
export let pageSize: number
let totalPages = Math.ceil(posts.totalCount / pageSize)
</script> </script>
<svelte:head> <svelte:head>

View 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