diff --git a/recipes.py b/recipes.py index 6b07350..2d6f0a5 100644 --- a/recipes.py +++ b/recipes.py @@ -278,6 +278,13 @@ class Builder: loader=jinja2.FileSystemLoader("templates"), autoescape=jinja2.select_autoescape(), ) + def numprint(input: int) -> str: + out = str(input) + if out.endswith(".0"): + return out.split(".")[0] + return out + + self.jinjaenv.filters['numprint'] = numprint self.ctx = Context() # list of output files that will be built self.outfiles: Set[str] = set() diff --git a/templates/recipe.html b/templates/recipe.html index 8a97614..501eb74 100644 --- a/templates/recipe.html +++ b/templates/recipe.html @@ -1,6 +1,6 @@ {% extends "base.html" %} {% macro ingredientpart(ing) -%} - {{ing.amount}} {{ing.unit.name}} {{ ing.name }} + {{ing.amount|numprint}} {{ing.unit.name}} {{ ing.name }} {%- endmacro %} {% macro ingredient(ing) -%} {{ingredientpart(ing)}}