---
import ArticlesView from "../../../components/ArticlesView.astro";
import { getPublishedArticles, getCategoryNames, getCategories, pageSlice, lastPageOf } from "../../../lib/articles";

export const prerender = false;

const all = await getPublishedArticles();
const page = Number(Astro.params.page);
if (!Number.isInteger(page) || page < 2 || page > lastPageOf(all.length)) return Astro.rewrite("/404");
---
<ArticlesView items={pageSlice(all, page)} categories={getCategories(all, await getCategoryNames())} totalCount={all.length} activeSlug={null} activeName={null} currentPage={page} lastPage={lastPageOf(all.length)} basePath="/articles" />
