Skip to content

Commit

Permalink
perf(frontend): load individual inscription metadata file
Browse files Browse the repository at this point in the history
Instead of loading the whole corpus and filtering.
  • Loading branch information
jmiguelv committed Jul 8, 2024
1 parent e0a6229 commit a7d1bc3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions frontend/src/routes/inscription/[slug]/+page.server.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { base } from '$app/paths';
import { error } from '@sveltejs/kit';
import corpus from '../../../data/corpus.json';
import fs from 'fs/promises';

/** @type {import('../$types').PageServerLoad} */
export async function load({ params, parent }) {
export async function load({ params }) {
try {
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 metadataFilePath = `src/data/metadata/${slug}.json`;
const metadataFileContent = await fs.readFile(metadataFilePath, 'utf8');
const metadata = JSON.parse(metadataFileContent);

const inscriptionFilePath = `src/data/html/${slug}.json`;
const inscriptionFileContent = await fs.readFile(inscriptionFilePath, 'utf8');
const inscription = JSON.parse(inscriptionFileContent);

const license = inscription.divs.at(-1);

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/routes/inscription/[slug]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

<article>
<hgroup>
<h1>{data.inscription.title} <small>{data.metadata.metadata.status}</small></h1>
<h1>{data.inscription.title} <small>{data.metadata.status}</small></h1>
<p>
<a href="{config.publicUrl}/inscription/{data.slug}" target="inscription"
>View in current site</a
Expand Down

0 comments on commit a7d1bc3

Please sign in to comment.