From 4a462d4123aab248288a252b4da9369d1b4e067a Mon Sep 17 00:00:00 2001 From: gamerdonkey Date: Sat, 13 Sep 2025 03:16:07 +0000 Subject: [PATCH] Adding script to generate full recipe site --- recipes2html.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 recipes2html.py diff --git a/recipes2html.py b/recipes2html.py new file mode 100644 index 0000000..69770cd --- /dev/null +++ b/recipes2html.py @@ -0,0 +1,51 @@ +from os import path, walk +from recipe import Recipe +from sys import argv + +if len(argv) < 2: + print(f"Usage: {argv[0]} ") + exit(1) + +recipe_dir = argv[1] + +recipe_names = {} +for dirpath, dirnames, filenames in walk(recipe_dir): + for filename in filenames: + if filename.endswith("json"): + recipe = Recipe(path.join(dirpath, filename)) + + html = recipe.to_html() + html_filepath = path.join(dirpath, f"{filename.rsplit('.', maxsplit=1)[0]}.html") + + with open(html_filepath, 'w') as html_file: + html_file.write(html) + + recipe_names[recipe.name] = path.relpath(html_filepath, start=recipe_dir) + +index_html = f""" + + +Recipes + + + + + +
+

Recipes

+

These are recipes that I'd like to share.

+
+ +
+
    +{"\n".join([f"
  • {name}
  • " for name, filepath in recipe_names.items()])} +
+
+ + + +""" + +with open(path.join(recipe_dir, "index.html"), 'w') as index_file: + index_file.write(index_html) +