diff --git a/README.md b/README.md index dd95886..2ba1169 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Features - Mobile Web-Application - Multi-language (DE & EN, more can be added) - Blazing fast due to minimal data usage -- Indexed (group by time, ingredients, or tags) +- Indexed (group by time, tags, difficulty, or ingredients) - PDF export (if LuaLaTex is installed) - ~~static search~~ (**not yet**, but coming soon…) @@ -27,7 +27,7 @@ Install 3. Run `make dev server` to run a local server and preview the page. -4. For distribution run `make build pdf deploy` and add an [official deploy](https://www.getlektor.com/docs/deployment/). +4. For distribution run `make build deploy` and add an [official deploy](https://www.getlektor.com/docs/deployment/). ### Modify diff --git a/src/content/recipes.tex/contents.lr b/src/content/recipes.tex/contents.lr new file mode 100644 index 0000000..3d5a64c --- /dev/null +++ b/src/content/recipes.tex/contents.lr @@ -0,0 +1,5 @@ +_model: all-recipes-pdf +--- +_template: all-recipes-pdf.tex +--- +title: recipe lekture diff --git a/src/databags/i18n+de.ini b/src/databags/i18n+de.ini index cf6a691..3c69d72 100644 --- a/src/databags/i18n+de.ini +++ b/src/databags/i18n+de.ini @@ -20,6 +20,10 @@ hard = Schwer [ingredients] recipeLink = ⤳Rezept +[latex] +recipe = Rezept +pagePrefix = S. + [title] latest = Zuletzt hinzugefügt all_recipes = Alle Rezepte diff --git a/src/databags/i18n+en.ini b/src/databags/i18n+en.ini index 312a25c..84c45d6 100644 --- a/src/databags/i18n+en.ini +++ b/src/databags/i18n+en.ini @@ -20,6 +20,10 @@ hard = Hard [ingredients] recipeLink = ⤳recipe +[latex] +recipe = recipe +pagePrefix = p. + [title] latest = Latest recipes all_recipes = All recipes diff --git a/src/models/all-recipes-pdf.ini b/src/models/all-recipes-pdf.ini new file mode 100644 index 0000000..639d2db --- /dev/null +++ b/src/models/all-recipes-pdf.ini @@ -0,0 +1,13 @@ +[model] +label = {{this._slug + (' (PDF)' if this.url_path.endswith('.tex') else '')}} +hidden = yes +protected = yes + +[children] +enabled = no + +[attachments] +enabled = no + +[fields.title] +type = string diff --git a/src/templates/all-recipes-pdf.tex b/src/templates/all-recipes-pdf.tex new file mode 100644 index 0000000..cbde441 --- /dev/null +++ b/src/templates/all-recipes-pdf.tex @@ -0,0 +1,63 @@ +{%- if this.alt == 'de' -%} +\documentclass[a4paper,12pt,twoside]{article} +\usepackage[ngerman]{babel} +{%- elif this.alt == 'en' -%} +\documentclass[letter,12pt,twoside]{article} +\usepackage[english]{babel} +{%- else -%} +\documentclass{article} +\UnknownAlternative{alt={{this.alt}}} +{%- endif %} +\include{setup} + +\def\tTitle{ {{- this.title -}} } +\def\tIngredients{ {{- bag('i18n+' + this.alt, 'title.ingredients') -}} } +\def\tRecipe{ {{- bag('i18n+' + this.alt, 'latex.recipe') -}} } +\def\tPagePrefix{ {{- bag('i18n+' + this.alt, 'latex.pagePrefix') -}} } + +\begin{document} +\makefrontmatter + +{%- for recipe in site.get('/recipes', alt=this.alt).children -%} +{%- set img = recipe | title_image(small=True) %} + +{# recipe title (start on new page) #} +\newrecipe{ {{- recipe._slug -}} }{ {{- recipe.name | latexStr -}} } +{# duration & yield subtitle -#} +\meta{ {{- recipe.time | asDuration(this.alt) -}} }{ {{- recipe.yield or '' -}} } +{# add source link on page footer -#} +\footer{ {{- recipe.source.url | latexStr -}} }{ {{- recipe.source.host | latexStr -}} } + +{# enumerate ingredients -#} +\begin{ingredients}{ {{- img | url(absolute=True) if img else '' -}} } + +{%- for ing in recipe.ingredients %} + {%- if ing.isGroup %} +\ingGroup{ {{- ing.name -}} } + {%- else %} +\item[ + {%- if ing.quantity %}{{ ing.quantity }}{% endif -%} + {%- if ing.quantity and ing.unit %}~{% endif -%} + {%- if ing.unit %}{{ ing.unit }}{% endif -%} +] \ingName{ {{- ing.name or '' -}} } + {%- if ing.note -%} +\ingDetail{ + {%- for word in ing.note.split() -%} + {#- detect recipe reference links -#} + {%- if word.startswith('@') %} \pagelink{ {{- word[4:].rstrip('/') -}} } + {#- or copy unchanged -#} + {%- else %} {{ word }}{%- endif -%} + {%- endfor -%} +} + {%- endif -%} + {%- endif -%} +{%- else %} +{#- if no ingredients add empty item, otherwise latex will throw error #} +\item +{%- endfor %} +\end{ingredients} + +{{ recipe.directions.html | latexHtml | trim }} +{% endfor %} + +\end{document} diff --git a/src/templates/layout.html b/src/templates/layout.html index 73e8280..160707d 100644 --- a/src/templates/layout.html +++ b/src/templates/layout.html @@ -43,7 +43,11 @@ {#--#} {#--#}
Build with Lektor, template by relikd. - {#--#} + {#- + we could use `site.get('/recipes.tex@LatexPDF', alt=this.alt) | url` + but then this will create a dependency on all recipes + -#} + {#--#} (PDF){#--#} {%- set url_without_alt = ('.'|url(absolute=True))[4:] -%}