feat: generate tex file with lektor not plugin
This commit is contained in:
5
src/content/recipes.tex/contents.lr
Normal file
5
src/content/recipes.tex/contents.lr
Normal file
@@ -0,0 +1,5 @@
|
||||
_model: all-recipes-pdf
|
||||
---
|
||||
_template: all-recipes-pdf.tex
|
||||
---
|
||||
title: recipe lekture
|
||||
@@ -20,6 +20,10 @@ hard = Schwer
|
||||
[ingredients]
|
||||
recipeLink = ⤳Rezept
|
||||
|
||||
[latex]
|
||||
recipe = Rezept
|
||||
pagePrefix = S.
|
||||
|
||||
[title]
|
||||
latest = Zuletzt hinzugefügt
|
||||
all_recipes = Alle Rezepte
|
||||
|
||||
@@ -20,6 +20,10 @@ hard = Hard
|
||||
[ingredients]
|
||||
recipeLink = ⤳recipe
|
||||
|
||||
[latex]
|
||||
recipe = recipe
|
||||
pagePrefix = p.
|
||||
|
||||
[title]
|
||||
latest = Latest recipes
|
||||
all_recipes = All recipes
|
||||
|
||||
13
src/models/all-recipes-pdf.ini
Normal file
13
src/models/all-recipes-pdf.ini
Normal 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
|
||||
63
src/templates/all-recipes-pdf.tex
Normal file
63
src/templates/all-recipes-pdf.tex
Normal 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}
|
||||
@@ -43,7 +43,11 @@
|
||||
<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 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 }}">{#--#}
|
||||
</a>
|
||||
{%- set url_without_alt = ('.'|url(absolute=True))[4:] -%}
|
||||
|
||||
Reference in New Issue
Block a user