bergere-enchantee / src /routes /+layout.server.ts
coyotte508's picture
coyotte508 HF staff
✨ Load pictures
fa79853
raw
history blame
709 Bytes
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[]
};
};