Skip to content

Commit

Permalink
feat(frontend): load inscription metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
jmiguelv committed Jul 7, 2024
1 parent 0f40dd4 commit cf9ac53
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions frontend/src/routes/inscription/[slug]/+page.server.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { base } from '$app/paths';
import { error } from '@sveltejs/kit';
import corpus from '../../../data/corpus.json';

/** @type {import('../$types').PageServerLoad} */
export async function load({ params }) {
export async function load({ params, parent }) {
try {
const module = await import(`../../../data/html/${params.slug}.json`);
const slug = params.slug;
const metadata = corpus.find((/** @type {{ file: string; }} */ entry) => entry.file === slug);

const module = await import(`../../../data/html/${slug}.json`);
const inscription = module.default;

const license = inscription.divs.at(-1);
Expand All @@ -14,8 +18,8 @@ export async function load({ params }) {
html: div.html.replace(/(href|src)="\/(?!\/)/g, `$1="${base}/`)
}));

return { inscription, license, title: inscription.title };
return { slug, metadata, inscription, license, title: inscription.title };
} catch (e) {
error(404, `Could not find data for ${params.slug}`);
error(404, `Error loading ${params.slug}: ${e.message}`);
}
}

0 comments on commit cf9ac53

Please # to comment.