fix(backend): rendering issue

This commit is contained in:
max_richter 2025-01-19 21:11:38 +01:00
parent 5fac6de05a
commit 463141981b
7 changed files with 635 additions and 16 deletions

600
article.html Normal file

File diff suppressed because one or more lines are too long

13
compose.yml Normal file
View File

@ -0,0 +1,13 @@
services:
app:
build:
context: .
dockerfile: Dockerfile
volumes:
- .:/app # Mount the local directory to /app in the container
working_dir: /app # Set the working directory inside the container to /app
command: run --env-file -A --watch=static/,routes/ dev.ts # Custom start command
ports:
- "8000:8000" # Expose the container port
environment:
- DATA_DIR=/app/data # Set the environment variable inside the container

View File

@ -77,7 +77,7 @@ export const menus: Record<string, Menu> = {
createNewSeries,
createNewRecipe,
addMovieInfos,
updateAllRecommendations,
// updateAllRecommendations,
],
},
};

View File

@ -46,7 +46,10 @@ export const unitsOfMeasure = {
export function parseIngredients(
text: string,
): (Ingredient | IngredientGroup)[] {
const cleanText = removeMarkdownFormatting(text);
const cleanText = removeMarkdownFormatting(text)
.split("\n")
.map((line) => line.trim().replace(/^-/, ""))
.join("\n");
const ingredients = parseIngredient(cleanText, {
normalizeUOM: true,

View File

@ -160,6 +160,11 @@ export function renderRecipe(recipe: Recipe) {
item.unit?.trim() || ""
}** ${item.name}`;
}
if (item.quantity) {
return `- **${item.quantity}** ${item.name}`;
}
return `- ${item.name}`;
})
.join("\n");

View File

@ -93,10 +93,13 @@ async function extractUsingAI(
const recipe = await openai.extractRecipe(markdown);
if (isValidRecipe(recipe)) {
if (recipe) {
if ("errorMessages" in recipe) {
throw new Error("Failed to extract recipe: " + recipe.errorMessages[0]);
} else {
return recipe;
}
return;
}
}
async function processCreateRecipeFromUrl(
@ -172,13 +175,6 @@ async function processCreateRecipeFromUrl(
}
}
if (!recipe) {
console.error("Failed to parse recipe");
streamResponse.enqueue("failed to parse recipe");
streamResponse.cancel();
return;
}
const newRecipe: Recipe = {
type: "recipe",
id,

View File

@ -51,10 +51,12 @@ export default async function Greet(
</PageHero.Subline>
</PageHero.Footer>
</PageHero>
{false && (
<Recommendations
id={movie.id}
type="movie"
/>
)}
{movie.tags.length > 0 && (
<>
<br />