feat: generate tex file with lektor not plugin

This commit is contained in:
relikd
2023-02-27 01:05:37 +01:00
parent 507b31e72c
commit ab0ff7b512
7 changed files with 96 additions and 3 deletions

View File

@@ -13,7 +13,7 @@ Features
- Mobile Web-Application - Mobile Web-Application
- Multi-language (DE & EN, more can be added) - Multi-language (DE & EN, more can be added)
- Blazing fast due to minimal data usage - 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) - PDF export (if LuaLaTex is installed)
- ~~static search~~ (**not yet**, but coming soon…) - ~~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. 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 ### Modify

View File

@@ -0,0 +1,5 @@
_model: all-recipes-pdf
---
_template: all-recipes-pdf.tex
---
title: recipe lekture

View File

@@ -20,6 +20,10 @@ hard = Schwer
[ingredients] [ingredients]
recipeLink = ⤳Rezept recipeLink = ⤳Rezept
[latex]
recipe = Rezept
pagePrefix = S.
[title] [title]
latest = Zuletzt hinzugefügt latest = Zuletzt hinzugefügt
all_recipes = Alle Rezepte all_recipes = Alle Rezepte

View File

@@ -20,6 +20,10 @@ hard = Hard
[ingredients] [ingredients]
recipeLink = ⤳recipe recipeLink = ⤳recipe
[latex]
recipe = recipe
pagePrefix = p.
[title] [title]
latest = Latest recipes latest = Latest recipes
all_recipes = All recipes all_recipes = All recipes

View File

@@ -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

View File

@@ -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}

View File

@@ -43,7 +43,11 @@
<table width="100%">{#--#} <table width="100%">{#--#}
<td>Build with <a href="https://www.getlektor.com/">Lektor</a>, template by <a href="https://github.com/relikd/lektor-recipes">relikd</a>.</td>{#--#} <td>Build with <a href="https://www.getlektor.com/">Lektor</a>, template by <a href="https://github.com/relikd/lektor-recipes">relikd</a>.</td>{#--#}
<td class="buttons xlarge"> <td class="buttons xlarge">
<a href="/static/pdf-{{ this.alt }}.pdf" download="recipes-{{ this.alt }}.pdf" title="{{ bag('i18n+' + this.alt, 'other.get_pdf') }}">{#--#} {#-
we could use `site.get('/recipes.tex@LatexPDF', alt=this.alt) | url`
but then this will create a dependency on all recipes
-#}
<a href="{{ '/'|url(alt=this.alt) + 'recipes.pdf' }}" download="recipes-{{ this.alt }}.pdf" title="{{ bag('i18n+' + this.alt, 'other.get_pdf') }}">{#--#}
<img class="h1em" alt="(PDF)" height="20" src="{{ '/img/icon-pdf.svg'|url }}">{#--#} <img class="h1em" alt="(PDF)" height="20" src="{{ '/img/icon-pdf.svg'|url }}">{#--#}
</a> </a>
{%- set url_without_alt = ('.'|url(absolute=True))[4:] -%} {%- set url_without_alt = ('.'|url(absolute=True))[4:] -%}