2026-04-07 14:58:53 +02:00
|
|
|
import { entries } from './feed';
|
|
|
|
|
|
2026-04-07 17:33:25 +02:00
|
|
|
let entriesPerPage = 2;
|
|
|
|
|
|
2026-04-07 14:58:53 +02:00
|
|
|
export async function load({ params, url }) {
|
|
|
|
|
// Get page index
|
|
|
|
|
let pageIndex = Number(url.searchParams.get('p'));
|
2026-04-07 17:33:25 +02:00
|
|
|
if (pageIndex == 0) {
|
|
|
|
|
pageIndex = 1;
|
2026-04-07 14:58:53 +02:00
|
|
|
}
|
|
|
|
|
|
2026-04-07 17:33:25 +02:00
|
|
|
// TODO check if index exceeds maximum permitted and redirect (to max page?)
|
|
|
|
|
|
2026-04-07 14:58:53 +02:00
|
|
|
let contents = [];
|
2026-04-07 17:33:25 +02:00
|
|
|
let start = (pageIndex - 1) * entriesPerPage;
|
2026-04-07 14:58:53 +02:00
|
|
|
|
2026-04-07 17:33:25 +02:00
|
|
|
for (let i = start; i < start + entriesPerPage; i += 1) {
|
|
|
|
|
// Stop iterating when end reached
|
|
|
|
|
if (i >= entries.length) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2026-04-07 14:58:53 +02:00
|
|
|
// Vite complains if I don't do this even though it's stupid
|
|
|
|
|
const path = entries[i].split("/");
|
|
|
|
|
const page = await import(`./${path[0]}/${path[1]}.md`);
|
|
|
|
|
|
|
|
|
|
contents.push(page.default);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-07 17:33:25 +02:00
|
|
|
let currentPage = pageIndex;
|
2026-04-07 14:58:53 +02:00
|
|
|
|
|
|
|
|
return {
|
2026-04-07 17:33:25 +02:00
|
|
|
currentPage,
|
2026-04-07 14:58:53 +02:00
|
|
|
contents,
|
|
|
|
|
};
|
|
|
|
|
}
|