From a7d1bc3e3c3c6fc2add66403ec90dd460b114d41 Mon Sep 17 00:00:00 2001 From: Miguel Vieira Date: Mon, 8 Jul 2024 11:26:33 +0100 Subject: [PATCH] perf(frontend): load individual inscription metadata file Instead of loading the whole corpus and filtering. --- .../src/routes/inscription/[slug]/+page.server.js | 14 +++++++++----- .../src/routes/inscription/[slug]/+page.svelte | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/frontend/src/routes/inscription/[slug]/+page.server.js b/frontend/src/routes/inscription/[slug]/+page.server.js index a10f1374a68..2d5590d8048 100644 --- a/frontend/src/routes/inscription/[slug]/+page.server.js +++ b/frontend/src/routes/inscription/[slug]/+page.server.js @@ -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); diff --git a/frontend/src/routes/inscription/[slug]/+page.svelte b/frontend/src/routes/inscription/[slug]/+page.svelte index 82a96110ad1..35d10a2b9d8 100644 --- a/frontend/src/routes/inscription/[slug]/+page.svelte +++ b/frontend/src/routes/inscription/[slug]/+page.svelte @@ -32,7 +32,7 @@
-

{data.inscription.title} {data.metadata.metadata.status}

+

{data.inscription.title} {data.metadata.status}

View in current site