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
+91 -41

No files matched your search

-3
View File
@@ -67,9 +67,6 @@ const MealGroupRow = ({
<FontAwesomeIcon icon={faBookOpen} /> {group.recipe.category ?? 'recept'}
</span>
)}
{group.recipe?.flavor === RecipeFlavor.SLADKE && (
<span className="tag tag-recipe">{RECIPE_FLAVOR_NAMES[RecipeFlavor.SLADKE].toLowerCase()}</span>
)}
{group.missingCaloriesCount > 0 && (
<span className="tag tag-missing">
bez kalorií {describeMissing(group.missingCaloriesCount, group.count)}
+91 -38
View File
@@ -10,7 +10,7 @@ import {
/** Recept s počtem fotek jídla — fotky se stahují jen tam, kde nějaké jsou. */
type RecipeItem = Pick<MealGroup, 'photoCount'> & { recipe: MealTemplate };
const PRIMARY_COLOR = '#15803d';
const PRIMARY_COLOR = '#156080';
const MUTED_COLOR = '#6b7280';
const BORDER_COLOR = '#e5e7eb';
/** Šíř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' }];
});
/** 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 [first, ...rest] = photoList;
if (!first) return [];
const result: Content[] = [{ image: first.image, fit: [CONTENT_WIDTH, 240], alignment: 'center', margin: [0, 0, 0, PHOTO_GAP] }];
const smallWidth = (CONTENT_WIDTH - PHOTO_GAP * (SMALL_PHOTOS_PER_ROW - 1)) / SMALL_PHOTOS_PER_ROW;
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],
});
const first = photoList[0];
if (!first) {
return [];
}
return result;
return [
{
image: first.image,
width: PHOTO_COLUMN_WIDTH,
alignment: 'center',
},
];
};
const createIngredients = (recipe: MealTemplate): Content[] => {
@@ -131,26 +127,83 @@ type RecipeContext = {
const createRecipe = (
recipe: MealTemplate, photoList: MealPhoto[], { index, withToc, recipeList, indexMap }: RecipeContext,
): Content => ({
stack: [
{
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),
...createPhotos(photoList),
...createIngredients(recipe),
...(recipe.note?.trim()
? [{ text: 'Postup', style: 'sectionHeading' }, ...convertMarkdownToPdf(recipe.note)]
: []),
],
// Každý recept začíná na nové stránce, první hned za obsahem
...(index > 0 || withToc ? { pageBreak: 'before' as const } : {}),
});
): Content => {
const hasPhotos = photoList.length > 0;
return ({
stack: [
...(hasPhotos
? [{
columns: [
{
width: '*',
stack: [
{
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),
],
},
{
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()
? [
{
text: 'Postup',
style: 'sectionHeading',
},
...convertMarkdownToPdf(recipe.note),
]
: []),
],
// Každý recept začíná na nové stránce, první hned za obsahem
...(index > 0 || withToc
? { pageBreak: 'before' as const }
: {}),
});
}
const loadPhotos = async (item: RecipeItem): Promise<MealPhoto[]> => {
if (!item.photoCount) return [];