fix: skryté tagu "chutě"

fix: změna formátu pdf receptů
This commit is contained in:
Ondřej Anděl committed 2026-11-05 12:11:45 +01:00
1 parent 7641e26c9f
commit 5e76c404fb
2 files changed
+77 -27

No files matched your search

-3
View File
@@ -67,9 +67,6 @@ const MealGroupRow = ({
<FontAwesomeIcon icon={faBookOpen} /> {group.recipe.category ?? 'recept'} <FontAwesomeIcon icon={faBookOpen} /> {group.recipe.category ?? 'recept'}
</span> </span>
)} )}
{group.recipe?.flavor === RecipeFlavor.SLADKE && (
<span className="tag tag-recipe">{RECIPE_FLAVOR_NAMES[RecipeFlavor.SLADKE].toLowerCase()}</span>
)}
{group.missingCaloriesCount > 0 && ( {group.missingCaloriesCount > 0 && (
<span className="tag tag-missing"> <span className="tag tag-missing">
bez kalorií {describeMissing(group.missingCaloriesCount, group.count)} bez kalorií {describeMissing(group.missingCaloriesCount, group.count)}
+77 -24
View File
@@ -10,7 +10,7 @@ import {
/** Recept s počtem fotek jídla — fotky se stahují jen tam, kde nějaké jsou. */ /** Recept s počtem fotek jídla — fotky se stahují jen tam, kde nějaké jsou. */
type RecipeItem = Pick<MealGroup, 'photoCount'> & { recipe: MealTemplate }; type RecipeItem = Pick<MealGroup, 'photoCount'> & { recipe: MealTemplate };
const PRIMARY_COLOR = '#15803d'; const PRIMARY_COLOR = '#156080';
const MUTED_COLOR = '#6b7280'; const MUTED_COLOR = '#6b7280';
const BORDER_COLOR = '#e5e7eb'; const BORDER_COLOR = '#e5e7eb';
/** Šířka tisknutelné plochy A4 při okrajích 40 pt. */ /** Šířka tisknutelné plochy A4 při okrajích 40 pt. */
@@ -63,25 +63,21 @@ const createLinks = (recipe: MealTemplate, recipeList: MealTemplate[], indexMap:
return [{ text: [{ text: `${RECIPE_LINK_NAMES[kind]}: `, bold: true }, ...nameList], style: 'recipeLinks' }]; return [{ text: [{ text: `${RECIPE_LINK_NAMES[kind]}: `, bold: true }, ...nameList], style: 'recipeLinks' }];
}); });
/** První fotka přes celou šířku, ostatní menší v řadách po třech. */ const PHOTO_COLUMN_WIDTH = 220;
const createPhotos = (photoList: MealPhoto[]): Content[] => { const createPhotos = (photoList: MealPhoto[]): Content[] => {
const [first, ...rest] = photoList; const first = photoList[0];
if (!first) return [];
const result: Content[] = [{ image: first.image, fit: [CONTENT_WIDTH, 240], alignment: 'center', margin: [0, 0, 0, PHOTO_GAP] }]; if (!first) {
const smallWidth = (CONTENT_WIDTH - PHOTO_GAP * (SMALL_PHOTOS_PER_ROW - 1)) / SMALL_PHOTOS_PER_ROW; return [];
for (let start = 0; start < rest.length; start += SMALL_PHOTOS_PER_ROW) {
const rowList = rest.slice(start, start + SMALL_PHOTOS_PER_ROW);
result.push({
columns: [
...rowList.map(photo => ({ image: photo.image, fit: [smallWidth, 130] as [number, number], width: smallWidth })),
// Nedoplněná řada si drží šířku sloupců
...Array.from({ length: SMALL_PHOTOS_PER_ROW - rowList.length }, () => ({ text: '', width: smallWidth })),
],
columnGap: PHOTO_GAP,
margin: [0, 0, 0, PHOTO_GAP],
});
} }
return result;
return [
{
image: first.image,
width: PHOTO_COLUMN_WIDTH,
alignment: 'center',
},
];
}; };
const createIngredients = (recipe: MealTemplate): Content[] => { const createIngredients = (recipe: MealTemplate): Content[] => {
@@ -131,7 +127,15 @@ type RecipeContext = {
const createRecipe = ( const createRecipe = (
recipe: MealTemplate, photoList: MealPhoto[], { index, withToc, recipeList, indexMap }: RecipeContext, recipe: MealTemplate, photoList: MealPhoto[], { index, withToc, recipeList, indexMap }: RecipeContext,
): Content => ({ ): Content => {
const hasPhotos = photoList.length > 0;
return ({
stack: [
...(hasPhotos
? [{
columns: [
{
width: '*',
stack: [ stack: [
{ {
text: recipe.name, text: recipe.name,
@@ -139,18 +143,67 @@ const createRecipe = (
id: getRecipeAnchor(index), id: getRecipeAnchor(index),
tocItem: withToc, tocItem: withToc,
}, },
...(recipe.source ? [{ text: recipe.source, style: 'recipeSource' }] : []),
{ text: getRecipeMeta(recipe), style: 'recipeMeta' }, ...(recipe.source
? [{ text: recipe.source, style: 'recipeSource' }]
: []),
{
text: getRecipeMeta(recipe),
style: 'recipeMeta',
},
...createLinks(recipe, recipeList, indexMap), ...createLinks(recipe, recipeList, indexMap),
...createPhotos(photoList),
...createIngredients(recipe), ...createIngredients(recipe),
],
},
{
width: 220,
stack: createPhotos(photoList),
},
],
columnGap: 20,
}]
: [
{
text: recipe.name,
style: 'recipeTitle',
id: getRecipeAnchor(index),
tocItem: withToc,
},
...(recipe.source
? [{ text: recipe.source, style: 'recipeSource' }]
: []),
{
text: getRecipeMeta(recipe),
style: 'recipeMeta',
},
...createLinks(recipe, recipeList, indexMap),
...createIngredients(recipe),
]),
...(recipe.note?.trim() ...(recipe.note?.trim()
? [{ text: 'Postup', style: 'sectionHeading' }, ...convertMarkdownToPdf(recipe.note)] ? [
{
text: 'Postup',
style: 'sectionHeading',
},
...convertMarkdownToPdf(recipe.note),
]
: []), : []),
], ],
// Každý recept začíná na nové stránce, první hned za obsahem // Každý recept začíná na nové stránce, první hned za obsahem
...(index > 0 || withToc ? { pageBreak: 'before' as const } : {}),
...(index > 0 || withToc
? { pageBreak: 'before' as const }
: {}),
}); });
}
const loadPhotos = async (item: RecipeItem): Promise<MealPhoto[]> => { const loadPhotos = async (item: RecipeItem): Promise<MealPhoto[]> => {
if (!item.photoCount) return []; if (!item.photoCount) return [];