Compare commits

..

1 commit

9 changed files with 39 additions and 137 deletions

View file

@ -1,15 +0,0 @@
when:
- event: push
branch: main
steps:
- name: publish
image: woodpeckerci/plugin-docker-buildx
settings:
platforms: linux/amd64,linux/arm64/v8
repo: git.comfy.city/emi/comfy-recipes
registry: git.comfy.city
tags: latest
username: ${CI_REPO_OWNER}
password:
from_secret: registry_token

View file

@ -1,11 +1,12 @@
FROM python:3.13-alpine AS build
FROM alpine:3.18 AS build
COPY . /build
WORKDIR /build
RUN pip install build hatchling && \
RUN apk add --no-cache python3 py3-build py3-hatchling && \
python3 -m build .
FROM python:3.13-alpine
COPY --from=build /build/dist/ /mnt
RUN pip install /mnt/comfy_recipes-*-py3-none-any.whl && \
rm -r /mnt
ENTRYPOINT ["/usr/local/bin/recipes-cli"]
FROM alpine:3.18
COPY --from=build /build/dist/recipes-*-py3-none-any.whl /
RUN apk add --no-cache python3 py3-pip && \
pip install /recipes-*-py3-none-any.whl && \
apk del py3-pip
ENTRYPOINT ["/usr/bin/recipes-cli"]

View file

@ -1,43 +0,0 @@
# Comfy Recipes
Comfy Recipes is a simple application that renders your recipes into HTML.
Documentation is available at <https://comfy.city/comfy-recipes/docs>
## Running
```sh
docker run -v ./recipes:/recipes git.comfy.city/Emi/comfy-recipes:latest build /recipes
```
## Building
### Building the python package
Make sure you have hatchling and build modules installed.
```sh
python3 -m build
```
The package can now be installed with
```sh
pip install dist/comfy-recipes-*-py3-none-any.whl
```
### Building the docker container
```sh
docker buildx build -t git.comfy.city/Emi/comfy-recipes:local .
```
The container can now be ran
```sh
docker run -v ./recipes:/recipes git.comfy.city/Emi/comfy-recipes:local build /recipes
```
### Building the documentation
```sh
cd docs
mdbook build
```
Documentation can now be served with
```sh
mdbook serve
```

View file

@ -44,14 +44,12 @@ def main() -> None:
(args.address, args.port), http.server.SimpleHTTPRequestHandler
)
print(f"serving at http://{args.address}:{args.port}")
print("THIS WEB SERVER IS ONLY MEANT FOR LOCAL TESTING, IT IS NOT SUITABLE FOR PRODUCTION")
try:
httpd.serve_forever()
except KeyboardInterrupt:
pass
elif args.subcommand == "generate-units":
os.chdir(args.directory)
if not args.force and os.path.isfile("units.yaml"):
if not args.force and os.path.isfile(args.directory + "/units.yaml"):
print(
"units.yaml already exists, pass --force if you want to overwrite it",
file=sys.stderr,
@ -60,8 +58,7 @@ def main() -> None:
else:
builder.generate_units()
elif args.subcommand == "generate-ingredients":
os.chdir(args.directory)
if not args.force and os.path.isfile("ingredients.yaml"):
if not args.force and os.path.isfile(args.directory + "/ingredients.yaml"):
print(
"ingredients.yaml already exists, pass --force if you want to overwrite it",
file=sys.stderr,

View file

@ -197,20 +197,19 @@ class IngredientInstance(Element):
def from_dict(cls, ctx: Context, dct: str | Dict[str, Any]) -> Self:
if isinstance(dct, str):
string = dct.strip()
p = re.compile(r"^(?:([0-9\.]+) ([a-zA-Z]+) )+([\w ]+)(?: \((.*)\))?$")
p = re.compile(r"^(?:([0-9\.]+) ([a-zA-Z]+) )?([\w ]+)(?: \((.*)\))?$")
match = p.match(string)
amount = float(1)
unit = ctx.default_unit
name = string
note = None
if match is not None:
if match is None:
raise RuntimeError(
"ingredient {string} regex not matched, it should be in the format [amount(num) unit(string, one word)] name(string, any number of words) [(note(string))]"
)
amount = float(match.group(1))
unitstr = match.group(2)
unit = ctx.default_unit
if unit is not None:
unitx = ctx.units.get(unitstr)
if unitx is None:
ctx.issues.error(issues.ISSUE_UNKNOWN_UNIT, f"unknown unit {unitstr}")
ctx.issues.error(issues.ISSUE_UNKNOWN_UNIT, "unknown unit {unitstr}")
else:
unit = unitx
name = match.group(3)
@ -219,7 +218,7 @@ class IngredientInstance(Element):
note = ""
return cls(
ctx=ctx,
name=name,
name=dct,
amount=amount,
unit=unit,
alternatives=[],
@ -290,7 +289,7 @@ class Recipe(Element):
source: Optional[SafeHTML],
ingredients: List[IngredientInstance],
subrecipes: List["Recipe"],
price: Optional["MultiPriceDB"],
price: Optional["PriceDB"],
stepsections: List[StepSection],
) -> None:
super().__init__(ctx)
@ -318,7 +317,7 @@ class Recipe(Element):
rp = Recipe.from_dict(ctx, partdct)
subrecipes.append(rp)
price: Optional[MultiPriceDB] = None
price: Optional[PriceDB] = None
pricex: float = 0
ingswithprice = 0
ingswithoutprice = 0
@ -336,22 +335,16 @@ class Recipe(Element):
# we don't know how to convert currencies yet
currency = None
break
if currency is None or len(ingredients) == 0:
if currency is None or ingswithoutprice != 0 or len(ingredients) == 0:
price = None
else:
pricedb = PriceDB(
price = PriceDB(
ctx=ctx,
price=pricex,
amount=1,
unit=ctx.default_unit,
currency=currency,
)
price = MultiPriceDB(
ctx=ctx,
pricedb=pricedb,
item_count=len(ingredients),
item_prices_missing=ingswithoutprice,
)
stepsections: List[StepSection] = []
if "steps" in dct:
@ -571,7 +564,7 @@ class PriceDB(Element):
price: float,
amount: float,
unit: Unit,
currency: str,
currency: Optional[str],
) -> None:
super().__init__(ctx)
self.price = price
@ -598,19 +591,4 @@ class PriceDB(Element):
currency = ctx.settings.default_currency
if "currency" in dct:
currency = dct["currency"]
if currency is None:
raise RuntimeError("currency not specified and default_currency is also not set")
return cls(ctx=ctx, price=price, amount=amount, unit=unit, currency=currency)
class MultiPriceDB(Element):
def __init__(
self,
ctx: Context,
pricedb: PriceDB,
item_count: int,
item_prices_missing: int,
) -> None:
super().__init__(ctx)
self.pricedb = pricedb
self.item_count = item_count
self.item_prices_missing = item_prices_missing

View file

@ -1,24 +1,12 @@
{% macro price(price) -%}
{% if price != None and price is defined and price.price is defined %}{{price.price|round(1)|numprint}}{%else%}?{% endif %} {{price.currency}}
{%- endmacro %}
{% macro multiprice(multiprice, shortform) -%}
{% if multiprice != None and multiprice.pricedb != None and multiprice.pricedb is defined and multiprice.pricedb.price is defined -%}
{{multiprice.pricedb.price|round(1)|numprint}}
{%else%}
?
{%- endif %}
{{multiprice.pricedb.currency}}
{%if multiprice.item_prices_missing != 0 and not shortform%}
({{multiprice.item_prices_missing}}/{{multiprice.item_count}} prices missing)
{%endif%}
{%- endmacro %}
<!DOCTYPE html>
<html lang="en">
<head>
<title>{% block title %}{% endblock %}</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.css">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
{% block body %}{% endblock %}

View file

@ -3,6 +3,6 @@
{%block body %}
<h1>Recipes</h1>
{% for recipe in recipes %}
<li>{% if recipe.price != None %}{{multiprice(recipe.price, true)}} {%endif%}<a href="{{ recipe.outpath }}">{{ recipe.title }}</a></li>
<li>{% if recipe.price != None %}{{price(recipe.price)}} {%endif%}<a href="{{ recipe.outpath }}">{{ recipe.title }}</a></li>
{% endfor %}
{%endblock%}

View file

@ -1,6 +1,6 @@
{% extends "base.html" %}
{% macro ingredientpart(ing) -%}
{% if ing.price != None %}{{price(ing.price)}} {%endif%}
{% if recipe.price != None %}{{price(ing.price)}} {%endif%}
{% if ing.amount != None %} {{ing.amount|amountprint}}
{% if ing.unit != None %} {{ing.unit.name}}{% endif %}
{%endif%}
@ -29,10 +29,7 @@
{% for ing in rec.ingredients %}
<li>{{ingredient(ing)}}</li>
{% endfor %}
{% if rec.price != None %}
<br>
price: {{multiprice(rec.price)}}
{%endif%}
{% if rec.price != None %}price: {{price(rec.price)}}{%endif%}
{% endif %}
{% if rec.stepsections|length != 0 %}
<h3>Steps</h3>

View file

@ -3,13 +3,13 @@ requires = ["hatchling"]
build-backend = "hatchling.build"
[project]
name = "comfy-recipes"
name = "recipes"
version = "0.0.1"
description = "Smart recipe static site generator"
authors = [{ name = "Emi Vasilek", email = "emi.vasilek@gmail.com" }]
keywords = ["recipes", "recipe", "static site generator"]
requires-python = ">= 3.8"
dependencies = ["jsonschema", "jinja2", "PyYAML", "mistune", "lxml", "lxml_html_clean"]
dependencies = ["jsonschema", "jinja2", "PyYAML", "mistune", "lxml"]
classifiers = [
"Development Status :: 3 - Alpha",
"Programming Language :: Python",
@ -17,10 +17,9 @@ classifiers = [
license = { file = "LICENSE" }
[project.urls]
Homepage = "https://git.comfy.city/Emi/comfy-recipes"
Repository = "https://git.comfy.city/Emi/comfy-recipes.git"
Issues = "https://git.comfy.city/Emi/comfy-recipes/issues"
Documentation = "https://comfy.city/comfy-recipes/docs"
Homepage = "https://codeberg.org/comfy.city/recipes"
Repository = "https://codeberg.org/comfy.city/recipes.git"
Issues = "https://codeberg.org/comfy.city/recipes/issues"
[project.scripts]
recipes-cli = "comfyrecipes.cli:main"