2023-02-12 21:15:50 +00:00
|
|
|
import type { PageServerLoad } from './$types';
|
|
|
|
|
import type { Article } from '$root/lib/types/article';
|
|
|
|
|
|
2023-02-12 21:28:40 +00:00
|
|
|
export type ArticlePageLoad = {
|
|
|
|
|
articles: Article[];
|
|
|
|
|
currentPage: number;
|
|
|
|
|
totalPages: number;
|
|
|
|
|
limit: number;
|
|
|
|
|
totalArticles: number;
|
|
|
|
|
};
|
|
|
|
|
|
2023-02-12 21:15:50 +00:00
|
|
|
export const load: PageServerLoad = async ({ fetch, params }) => {
|
|
|
|
|
const { page } = params;
|
|
|
|
|
const resp = await fetch(`/api/articles?page=${page}`);
|
2023-02-12 21:28:40 +00:00
|
|
|
const { articles, currentPage, totalPages, limit, totalArticles }: ArticlePageLoad =
|
|
|
|
|
await resp.json();
|
2023-02-12 21:15:50 +00:00
|
|
|
return {
|
|
|
|
|
articles,
|
|
|
|
|
currentPage,
|
|
|
|
|
totalPages,
|
|
|
|
|
limit,
|
|
|
|
|
totalArticles
|
|
|
|
|
};
|
|
|
|
|
};
|