38 lines
716 B
TypeScript
38 lines
716 B
TypeScript
import { LOCATIONS } from '$lib/locations-object.svelte';
|
|
import type { PageLoad } from './$types';
|
|
import { error } from '@sveltejs/kit';
|
|
|
|
export const load: PageLoad = async ({ url }) => {
|
|
const locId = url.searchParams.get('loc');
|
|
|
|
if (!LOCATIONS.loaded) {
|
|
await LOCATIONS.init();
|
|
}
|
|
|
|
let title: string = '';
|
|
|
|
if (!locId) {
|
|
error(400, {
|
|
message: 'Location not provided',
|
|
owlCode: 'NO_LOCATION_IN_PATH'
|
|
});
|
|
}
|
|
|
|
if (locId) {
|
|
const location = LOCATIONS.find(locId);
|
|
|
|
if (location) {
|
|
title = location.n || location.t;
|
|
} else {
|
|
error(404, {
|
|
message: `Location (${locId.toUpperCase()}) not found`,
|
|
owlCode: 'INVALID_LOCATION_CODE'
|
|
});
|
|
}
|
|
}
|
|
return {
|
|
title,
|
|
location
|
|
};
|
|
};
|