Add JSON-LD structured data for recipes
Some checks failed
CI / update (push) Failing after 59s

- Create recipeJsonLd.ts function with Schema.org compliant Recipe markup
- Add API endpoint at /api/rezepte/json-ld/[name] for on-demand generation
- Include proper ISO 8601 time parsing for German formats
- Add rel="alternate" link in recipe pages for discoverability
- Set author to Alexander Bocken with proper Person type
- Include caching headers for performance optimization

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-09-04 18:57:36 +02:00
parent 6a8478f8a6
commit e01ff9eb59
3 changed files with 160 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
import { json, type RequestHandler } from '@sveltejs/kit';
import { Recipe } from '../../../../../models/Recipe';
import { dbConnect, dbDisconnect } from '../../../../../utils/db';
import { generateRecipeJsonLd } from '$lib/js/recipeJsonLd';
import type { RecipeModelType } from '../../../../../types/types';
import { error } from '@sveltejs/kit';
export const GET: RequestHandler = async ({ params, setHeaders }) => {
await dbConnect();
let recipe = (await Recipe.findOne({ short_name: params.name }).lean()) as RecipeModelType;
await dbDisconnect();
recipe = JSON.parse(JSON.stringify(recipe));
if (recipe == null) {
throw error(404, "Recipe not found");
}
const jsonLd = generateRecipeJsonLd(recipe);
// Set appropriate headers for JSON-LD
setHeaders({
'Content-Type': 'application/ld+json',
'Cache-Control': 'public, max-age=3600' // Cache for 1 hour
});
return new Response(JSON.stringify(jsonLd, null, 2), {
headers: {
'Content-Type': 'application/ld+json',
'Cache-Control': 'public, max-age=3600'
}
});
};