File size: 709 Bytes
65b4f03
 
 
 
fa79853
 
65b4f03
 
 
 
 
fa79853
 
 
 
 
65b4f03
fa79853
 
65b4f03
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import type { LayoutServerLoad } from './$types';
import '$lib/server/db';
import { pages } from '$lib/server/db/page';
import type { Picture } from '$lib/types/Picture';
import { filterNullish } from '$lib/utils/filterNullish';
import { pictures } from '$lib/server/db';

export const load: LayoutServerLoad = async (input) => {
	const pageId = input.url.pathname;

	if (pageId in pages) {
		const pageData = pages[pageId as keyof typeof pages];

		const pictureIds = filterNullish(Object.values(pageData.pictures));
		const pics = await pictures.find({ _id: { $in: pictureIds } }).toArray();

		return {
			pageData,
			pictures: pics
		};
	}

	return {
		pageData: null,
		pictures: [] as Picture[]
	};
};