refactor: clean up recipe routes and reduce bundle size

- Eliminate duplicate API fetch in recipe page by passing item from
  server load to universal load instead of fetching twice
- Replace cheerio with simple regex in stripHtmlTags, removing ~200KB
  dependency
- Refactor multiplier buttons in IngredientsPage to use loop instead
  of 5 repeated form elements
- Move /rezepte/untranslated to /[recipeLang]/admin/untranslated and
  delete legacy /rezepte/ layout files
This commit is contained in:
2026-01-23 15:04:44 +01:00
parent ab2a6c9158
commit f3b92e8b1a
11 changed files with 58 additions and 252 deletions

View File

@@ -2,18 +2,13 @@ import { redirect, error } from '@sveltejs/kit';
import { stripHtmlTags } from '$lib/js/stripHtmlTags';
export async function load({ params, fetch }) {
// Fetch recipe data to strip HTML tags server-side
// This avoids bundling cheerio in the client bundle
const isEnglish = params.recipeLang === 'recipes';
const apiBase = isEnglish ? '/api/recipes' : '/api/rezepte';
const res = await fetch(`${apiBase}/items/${params.name}`);
if (!res.ok) {
// Let the universal load function handle the error
return {
strippedName: '',
strippedDescription: '',
};
const errorData = await res.json().catch(() => ({ message: 'Recipe not found' }));
throw error(res.status, errorData.message);
}
const item = await res.json();
@@ -21,6 +16,7 @@ export async function load({ params, fetch }) {
const strippedDescription = stripHtmlTags(item.description);
return {
item,
strippedName,
strippedDescription,
};