This repository has been archived on 2026-05-30. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
gpn24-recipes/lib.py

33 lines
747 B
Python
Raw Normal View History

2026-04-12 23:52:30 +02:00
import os
import json
from config import *
def read_recipes(keyword=None):
recipes = []
for json_file in os.listdir(OUTDIR_JSON):
with open(os.path.join(OUTDIR_JSON, json_file), "r", encoding="utf-8") as f:
data = json.load(f)
recipes.append(data)
recipes.sort(key=lambda r: r["name"])
# Filter on keyword
if keyword:
recipes = [
r for r in recipes if any(k["name"] == keyword for k in r["keywords"])
]
return recipes
def recipe_url(recipe_id: int) -> str:
return f"{TANDOOR_URL}/recipe/{recipe_id}"
def markdown_link(text: str, url: str) -> str:
return f"[{text}]({url})"
def markdown_alert(text: str) -> str:
return f"::: danger\n{text}\n:::"