Skip to content

Commit 3701daf

Browse files
committed
Add URL support for image in recipe page
1 parent 950ecdf commit 3701daf

7 files changed

Lines changed: 17 additions & 12 deletions

File tree

src/generate_pages.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,18 @@ def main():
264264
# print(f" Image for '{recipe_name_fr}' is a URL: {image_filename_val}")
265265
pass # Keep the URL as is
266266

267-
output_html_filename_str = generate_safe_filename(
268-
recipe_name_fr, extension="html"
269-
)
270-
output_pdf_filename_str = generate_safe_filename(
271-
recipe_name_fr, extension="pdf"
272-
)
273-
# Chemin relatif depuis la page HTML (dans OUTPUT_DIR) vers le PDF (dans OUTPUT_PDF_DIR)
267+
# Détermination du chemin de l'image pour le template (URL ou chemin local)
268+
image_path = None
269+
if image_filename_val:
270+
if image_filename_val.startswith(("http://", "https://")):
271+
image_path = image_filename_val
272+
else:
273+
image_path = f"{OUTPUT_RECIPE_IMAGES_DIR.name}/{image_filename_val}"
274+
recipe_data["image_path"] = image_path
275+
276+
# Génération des noms de fichiers de sortie HTML et PDF (corrige le NameError)
277+
output_html_filename_str = generate_safe_filename(recipe_name_fr, extension="html")
278+
output_pdf_filename_str = generate_safe_filename(recipe_name_fr, extension="pdf")
274279
recipe_data["pdf_path"] = f"{OUTPUT_PDF_DIR.name}/{output_pdf_filename_str}"
275280

276281
# Context for rendering the individual recipe page

src/templates/base_recipe.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ <h2>Instructions</h2>
128128
<!-- <span class="separation-line"></span> --> {# Ligne de séparation si besoin avant le footer #}
129129
{% endif %}
130130

131-
{% if recipe.image_filename %}
132-
<img src="recipe_images/{{ recipe.image_filename }}" alt="Illustration de {{ recipe.name }}"/>
131+
{% if recipe.image_path %}
132+
<img src="{{ recipe.image_path }}" alt="Illustration de {{ recipe.name }}"/>
133133
{% else %}
134134
<!-- Optionnel: une image placeholder si aucune image n'est fournie -->
135135
<!-- <img src="placeholder.jpg" alt="Pas d'image disponible" /> -->
@@ -143,4 +143,4 @@ <h2>Instructions</h2>
143143
Recette générée avec ❤️
144144
</footer>
145145
</body>
146-
</html>
146+
</html>

website/crêpes.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ <h2>Instructions</h2>
154154

155155

156156

157-
<img src="recipe_images/https://img.cuisineaz.com/660x495/2015/01/29/i113699-photo-de-crepe-facile.webp" alt="Illustration de Crêpes"/>
157+
<img src="https://img.cuisineaz.com/660x495/2015/01/29/i113699-photo-de-crepe-facile.webp" alt="Illustration de Crêpes"/>
158158

159159
</div>
160160
</section>

website/nom_de_la_recette.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ <h2>Instructions</h2>
136136

137137

138138

139-
<img src="recipe_images/https://example.com/path/to/image.jpg" alt="Illustration de Nom de la recette"/>
139+
<img src="https://example.com/path/to/image.jpg" alt="Illustration de Nom de la recette"/>
140140

141141
</div>
142142
</section>

website/pdf_recipes/crêpes.pdf

506 KB
Binary file not shown.
-4 Bytes
Binary file not shown.
-5 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)