diff --git a/extras/pdf-export/.gitignore b/extras/pdf-export/.gitignore new file mode 100644 index 0000000..3e60473 --- /dev/null +++ b/extras/pdf-export/.gitignore @@ -0,0 +1,3 @@ +/pdf-de.pdf +/pdf-en.pdf +/setup-builddir.tex \ No newline at end of file diff --git a/extras/pdf-export/fonts/Crimson - SIL Open Font License.txt b/extras/pdf-export/fonts/Crimson - SIL Open Font License.txt new file mode 100755 index 0000000..e08390d --- /dev/null +++ b/extras/pdf-export/fonts/Crimson - SIL Open Font License.txt @@ -0,0 +1,43 @@ +Copyright (c) 2010, Sebastian Kosch (sebastian@aldusleaf.org), with Reserved Font Name "Crimson Text". + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide development of collaborative font projects, to support the font creation efforts of academic and linguistic communities, and to provide a free and open framework in which fonts may be shared and improved in partnership with others. + +The OFL allows the licensed fonts to be used, studied, modified and redistributed freely as long as they are not sold by themselves. The fonts, including any derivative works, can be bundled, embedded, redistributed and/or sold with any software provided that any reserved names are not used by derivative works. The fonts and derivatives, however, cannot be released under any other type of license. The requirement for fonts to remain under this license does not apply to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright Holder(s) under this license and clearly marked as such. This may include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the copyright statement(s). + +"Original Version" refers to the collection of Font Software components as distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, or substituting -- in part or in whole -- any of the components of the Original Version, by changing formats or by porting the Font Software to a new environment. + +"Author" refers to any designer, engineer, programmer, technical writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining a copy of the Font Software, to use, study, copy, merge, embed, modify, redistribute, and sell modified and unmodified copies of the Font Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, redistributed and/or sold with any software, provided that each copy contains the above copyright notice and this license. These can be included either as stand-alone text files, human-readable headers or in the appropriate machine-readable metadata fields within text or binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font Name(s) unless explicit written permission is granted by the corresponding Copyright Holder. This restriction only applies to the primary font name as presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font Software shall not be used to promote, endorse or advertise any Modified Version, except to acknowledge the contribution(s) of the Copyright Holder(s) and the Author(s) or with their explicit written permission. + +5) The Font Software, modified or unmodified, in part or in whole, must be distributed entirely under this license, and must not be distributed under any other license. The requirement for fonts to remain under this license does not apply to any document created using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE. \ No newline at end of file diff --git a/extras/pdf-export/fonts/Crimson-Bold.otf b/extras/pdf-export/fonts/Crimson-Bold.otf new file mode 100755 index 0000000..909c36a Binary files /dev/null and b/extras/pdf-export/fonts/Crimson-Bold.otf differ diff --git a/extras/pdf-export/fonts/Crimson-BoldItalic.otf b/extras/pdf-export/fonts/Crimson-BoldItalic.otf new file mode 100755 index 0000000..452526c Binary files /dev/null and b/extras/pdf-export/fonts/Crimson-BoldItalic.otf differ diff --git a/extras/pdf-export/fonts/Crimson-Italic.otf b/extras/pdf-export/fonts/Crimson-Italic.otf new file mode 100755 index 0000000..011e3dc Binary files /dev/null and b/extras/pdf-export/fonts/Crimson-Italic.otf differ diff --git a/extras/pdf-export/fonts/Crimson-Roman.otf b/extras/pdf-export/fonts/Crimson-Roman.otf new file mode 100755 index 0000000..f5e33e1 Binary files /dev/null and b/extras/pdf-export/fonts/Crimson-Roman.otf differ diff --git a/extras/pdf-export/fonts/Crimson-Semibold.otf b/extras/pdf-export/fonts/Crimson-Semibold.otf new file mode 100755 index 0000000..0a57424 Binary files /dev/null and b/extras/pdf-export/fonts/Crimson-Semibold.otf differ diff --git a/extras/pdf-export/fonts/Crimson-SemiboldItalic.otf b/extras/pdf-export/fonts/Crimson-SemiboldItalic.otf new file mode 100755 index 0000000..0dab805 Binary files /dev/null and b/extras/pdf-export/fonts/Crimson-SemiboldItalic.otf differ diff --git a/extras/pdf-export/fonts/FiraSans - SIL Open Font License.txt b/extras/pdf-export/fonts/FiraSans - SIL Open Font License.txt new file mode 100755 index 0000000..53aea66 --- /dev/null +++ b/extras/pdf-export/fonts/FiraSans - SIL Open Font License.txt @@ -0,0 +1,93 @@ +Copyright (c) 2012-2015, The Mozilla Foundation and Telefonica S.A. + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +http://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/extras/pdf-export/fonts/FiraSans-Light.ttf b/extras/pdf-export/fonts/FiraSans-Light.ttf new file mode 100755 index 0000000..fac4edf Binary files /dev/null and b/extras/pdf-export/fonts/FiraSans-Light.ttf differ diff --git a/extras/pdf-export/fonts/FiraSans-LightItalic.ttf b/extras/pdf-export/fonts/FiraSans-LightItalic.ttf new file mode 100755 index 0000000..1daa0bc Binary files /dev/null and b/extras/pdf-export/fonts/FiraSans-LightItalic.ttf differ diff --git a/extras/pdf-export/fonts/FiraSans-Medium.ttf b/extras/pdf-export/fonts/FiraSans-Medium.ttf new file mode 100755 index 0000000..eeb8f8f Binary files /dev/null and b/extras/pdf-export/fonts/FiraSans-Medium.ttf differ diff --git a/extras/pdf-export/fonts/FiraSans-MediumItalic.ttf b/extras/pdf-export/fonts/FiraSans-MediumItalic.ttf new file mode 100755 index 0000000..328b53b Binary files /dev/null and b/extras/pdf-export/fonts/FiraSans-MediumItalic.ttf differ diff --git a/extras/pdf-export/fonts/FiraSans-Regular.ttf b/extras/pdf-export/fonts/FiraSans-Regular.ttf new file mode 100755 index 0000000..c4cfa59 Binary files /dev/null and b/extras/pdf-export/fonts/FiraSans-Regular.ttf differ diff --git a/extras/pdf-export/misc/icon-time.pdf b/extras/pdf-export/misc/icon-time.pdf new file mode 100644 index 0000000..e753d52 --- /dev/null +++ b/extras/pdf-export/misc/icon-time.pdf @@ -0,0 +1,69 @@ +%PDF-1.5 +% +3 0 obj +<< /Length 4 0 R + /Filter /FlateDecode +>> +stream +xUPKRD1\@$B8Gq\^genw!woq%P"DM+1 fnO-.6`EU7,Rh{Um q& h2`)V04Ps> + >> +>> +endobj +5 0 obj +<< /Type /Page + /Parent 1 0 R + /MediaBox [ 0 0 1000 1000 ] + /Contents 3 0 R + /Group << + /Type /Group + /S /Transparency + /I true + /CS /DeviceRGB + >> + /Resources 2 0 R +>> +endobj +1 0 obj +<< /Type /Pages + /Kids [ 5 0 R ] + /Count 1 +>> +endobj +6 0 obj +<< /Creator (cairo 1.12.18 (http://cairographics.org)) + /Producer (cairo 1.12.18 (http://cairographics.org)) +>> +endobj +7 0 obj +<< /Type /Catalog + /Pages 1 0 R +>> +endobj +xref +0 8 +0000000000 65535 f +0000000675 00000 n +0000000387 00000 n +0000000015 00000 n +0000000365 00000 n +0000000459 00000 n +0000000740 00000 n +0000000869 00000 n +trailer +<< /Size 8 + /Root 7 0 R + /Info 6 0 R +>> +startxref +921 +%%EOF diff --git a/extras/pdf-export/misc/icon-yield.pdf b/extras/pdf-export/misc/icon-yield.pdf new file mode 100644 index 0000000..a555cec Binary files /dev/null and b/extras/pdf-export/misc/icon-yield.pdf differ diff --git a/extras/pdf-export/misc/logo.pdf b/extras/pdf-export/misc/logo.pdf new file mode 100644 index 0000000..e8f0c96 Binary files /dev/null and b/extras/pdf-export/misc/logo.pdf differ diff --git a/extras/pdf-export/pdf-de.tex b/extras/pdf-export/pdf-de.tex new file mode 100644 index 0000000..36173ed --- /dev/null +++ b/extras/pdf-export/pdf-de.tex @@ -0,0 +1,14 @@ +\documentclass[a4paper,12pt,twoside]{article} +\usepackage[ngerman]{babel} +\include{setup} +\include{setup-builddir} % load \def\builddir{} + +\def\tIngredients{Zutaten} +\def\tRecipe{Rezept} +\def\tPagePrefix{S.} + +\begin{document} +\makefrontmatter +\graphicspath{{\builddir/de/}} +\include{\builddir/de/pdf-export} +\end{document} \ No newline at end of file diff --git a/extras/pdf-export/pdf-en.tex b/extras/pdf-export/pdf-en.tex new file mode 100644 index 0000000..251cae7 --- /dev/null +++ b/extras/pdf-export/pdf-en.tex @@ -0,0 +1,14 @@ +\documentclass[letter,12pt,twoside]{article} +\usepackage[english]{babel} +\include{setup} +\include{setup-builddir} % load \def\builddir{} + +\def\tIngredients{Ingredients} +\def\tRecipe{recipe} +\def\tPagePrefix{p.} + +\begin{document} +\makefrontmatter +\graphicspath{{\builddir/en/}} +\include{\builddir/en/pdf-export} +\end{document} \ No newline at end of file diff --git a/extras/pdf-export/setup.tex b/extras/pdf-export/setup.tex new file mode 100644 index 0000000..6ce927f --- /dev/null +++ b/extras/pdf-export/setup.tex @@ -0,0 +1,174 @@ +\usepackage[utf8]{inputenc} +\usepackage[T1]{fontenc} +\usepackage{geometry} % margin width +\usepackage{graphicx} % includegraphics +\usepackage{xcolor} % colors +\usepackage{sidenotes} % margin figure, etc. +\usepackage{enumitem} % setlist[description] +\usepackage{titleps} % footer page number +\usepackage{tocloft} % \cftbeforesecskip +\usepackage{ragged2e} % \RaggedRight +\usepackage{fontspec} % \setmainfont, \setsansfont, \setmonofont + +\definecolor{red2}{HTML}{AA203A} +\definecolor{red3}{HTML}{EE6A84} +\usepackage{xurl} +\PassOptionsToPackage{hyphens}{url} +\usepackage{hyperref} +\renewcommand{\UrlFont}{\normalfont} + +%% Use this if the font is _not_ installed on the system +%% but it requires the download of the additional fonts package +%% \setmonofont[Path=fonts/]{FiraSans-Light} +\setmainfont[ + Path = fonts/, + BoldFont = Crimson-Bold, + ItalicFont = Crimson-Italic, + BoldItalicFont = Crimson-BoldItalic +]{Crimson-Roman} +\setsansfont[ + Path = fonts/, + Scale = 0.95, + BoldFont = FiraSans-Medium, + ItalicFont = FiraSans-LightItalic, + BoldItalicFont = FiraSans-MediumItalic +]{FiraSans-Regular} + +%% Use this if the font is installed on the system +%% this does not require additional fonts package +% \setmainfont[ +% BoldFont = {Fira Sans Medium}, +% ItalicFont = {Fira Sans Light Italic}, +% BoldItalicFont = {Fira Sans Medium Italic} +% ]{Fira Sans Regular} +% \setmainfont[ +% BoldFont = {Crimson Bold}, +% ItalicFont = {Crimson Italic}, +% BoldItalicFont = {Crimson Bold Italic} +% ]{Crimson Roman} + +% Defines & Geometry +\def\marginwidth{60mm} +\def\marginsep{8.2mm} +\def\marginwoverflow{67mm} % -1.2mm for makebox +% space before \paragraph +\setlength{\parindent}{0pt} +% space between paragraphs +\setlength{\parskip}{0.4\baselineskip} +\geometry{ + head=13.6pt, + top=2cm, + bottom=2cm, + inner=2cm, + outer=2cm, + marginparsep=\marginsep, + marginparwidth=\marginwidth, + includemp, + % showframe +} +% \renewcommand{\footnotesep}{2.5ex} +\renewcommand{\footnoterule}{ + \kern -2pt + \hrule width \textwidth height .2pt + \kern 1.8pt} +% spacing before & after +\makeatletter +% footer +\renewcommand\@makefntext[1]{\noindent\makebox[0.5em][l]{\@makefnmark}#1} +% subsubsection +\renewcommand{\subsubsection}{% + \@startsection{subsubsection}{3}% + {\z@}{-2ex \@plus -1ex \@minus -1ex}{.2ex \@plus 1ex \@minus .2ex}% + {\normalfont\large\bfseries}% +} +% paragraph +\renewcommand{\paragraph}{% + \@startsection{paragraph}{4}% + {\z@}{1.5ex \@plus 1ex \@minus .2ex}{-.75em}% + {\normalfont\normalsize\bfseries}% +} +\makeatother +% adjust description environment +\setlist[description,enumerate,itemize]{% + topsep=0.7\baselineskip, + itemsep=0pt, + % itemindent=-2em, + % listparindent=-2em, + % leftmargin=0em, + font={\sffamily} +} +\setlist[enumerate,itemize]{leftmargin=1em,topsep=0\baselineskip,parsep=0pt} +\widowpenalty10000 +\clubpenalty10000 +% disable section numbering +\setcounter{secnumdepth}{0} +\setcounter{tocdepth}{1} +% \titleformat*{\section}{\LARGE\bfseries} # titlesec +\setlength{\cftbeforesecskip}{0.2em} % spacing in TOC + +% Footer page numbering +\renewpagestyle{plain}{% +\setfoot[{\makebox[-\marginwoverflow][r]{\thepage}}][][]{}{}{{\makebox[-\marginwoverflow][l]{\thepage}}} +} +\pagestyle{plain} + +% \graphicspath{{../src/content/}} + +\newcommand{\makefrontmatter}{ + \begin{titlepage} + \newgeometry{top=2.5cm,bottom=2.5cm,left=4cm,right=4cm} + \centering + \vspace*{.06\textheight} + \includegraphics[width=54mm]{misc/logo.pdf}\par + \vspace*{.06\textheight} + {\huge\sf recipe lekture} + \vfill + \today + \end{titlepage} + + % \thispagestyle{empty} + \pagenumbering{roman} + \tableofcontents + \clearpage + \pagenumbering{arabic} + \setcounter{page}{1} +} + +% Custom commands +\newcommand{\meta}[2]{% + \vspace{-0.75em}% + ~\includegraphics[height=2ex]{misc/icon-time}\enspace\ifx\relax#1\relax—\else#1\fi% + \quad% + \includegraphics[height=2ex]{misc/icon-yield}\enspace\ifx\relax#2\relax—\else#2\fi% + \vspace{1em}% +} +\newcommand{\footer}[2]{% + \ifx\relax#1\relax\else{% + \enlargethispage{5.75ex} + \let\thefootnote\relax\footnotetext{% + \hspace{-.6em} Source: % + \ifx\relax#2\relax#1\else\href{#1}{#2}\fi% + }\fi% + } +} + +\newcommand{\newrecipe}[2]{\clearpage\section{#2}\label{#1}} +\newcommand{\ingGroup}[1]{\vspace{.2ex}\item{\bfseries\color{red2}\hspace{-1em} #1}} +\newcommand{\ingName}[1]{{\color{red3}#1}} +\newcommand{\ingDetail}[1]{\emph{\footnotesize,#1}} +\newcommand{\pagelink}[1]{\tRecipe \tPagePrefix\,{\color{red2}\pageref{#1}}} +\newcommand{\recipelink}[2]{#2 (\tPagePrefix\,\pageref{#1})} +\newcommand{\external}[2]{#2\footnote{\href{#1}{#1}}} +% \newcommand{\external}[2]{#2\footnote{\url{#1}}} + +\newenvironment{ingredients}[1]{ + \begin{marginfigure} + \small + \ifx\relax#1\relax\else\includegraphics[width=\marginwidth]{#1}\fi + % \subsection*{\sffamily\tIngredients:} + \begin{description} + \RaggedRight\sffamily +}{ + \end{description} + \end{marginfigure} +} diff --git a/src/content/pdf-export.tex/contents.lr b/src/content/pdf-export.tex/contents.lr new file mode 100644 index 0000000..8fc6658 --- /dev/null +++ b/src/content/pdf-export.tex/contents.lr @@ -0,0 +1,3 @@ +_template: makepdf.tex +--- +_model: none \ No newline at end of file diff --git a/src/content/recipes b/src/content/recipes new file mode 120000 index 0000000..4f85408 --- /dev/null +++ b/src/content/recipes @@ -0,0 +1 @@ +../../data/development/ \ No newline at end of file diff --git a/src/packages/force-update b/src/packages/force-update index 2c50ec3..9240ae5 160000 --- a/src/packages/force-update +++ b/src/packages/force-update @@ -1 +1 @@ -Subproject commit 2c50ec35c0320414f883cccd52710766a77b2e10 +Subproject commit 9240ae59c47cdfc7790e98444f00e3d7572954d6 diff --git a/src/packages/helper/lektor_helper.py b/src/packages/helper/lektor_helper.py index 6c2d0db..8845e7f 100644 --- a/src/packages/helper/lektor_helper.py +++ b/src/packages/helper/lektor_helper.py @@ -4,11 +4,23 @@ from lektor.databags import Databags from markupsafe import Markup from datetime import datetime import unicodedata +import lektor_html_to_tex as tex # ------- # Sorting +def sorted_images(obj, attr='record_label'): + return sorted(obj.attachments.images, key=lambda x: getattr(x, attr)) + + +def title_image(self, attr='record_label', small=False): + img = (sorted_images(self, attr) or [None])[0] + if img and small: + img = img.thumbnail(200, 150, mode='crop') + return img + + def sortKeyInt(x): return int(x[0]) if x[0] else 0 @@ -40,17 +52,24 @@ def noUmlaut(text): def replaceFractions(txt): - res = '' + res = ' ' + for c in u'-–—': + if c in txt: + txt = txt.replace(c, ' – ') for x in txt.split(): + if x == '': + continue try: i = ['1/2', '1/3', '2/3', '1/4', '3/4', '1/8'].index(x) res += [u'½', u'⅓', u'⅔', u'¼', u'¾', u'⅛'][i] except ValueError: - if x in u'-–—': - res += u' - ' + if x == '–': + res += '–' + elif res[-1:] == '–': + res += x else: res += ' ' + x - return res.lstrip() + return res.lstrip(' ') def numFillWithText(num, fill=u'★', empty=u'☆', total=5): @@ -186,12 +205,12 @@ class HelperPlugin(Plugin): partA, partB = partA.split('.', 1) return self.translations[alt][partA][partB] - def ingredientsForRecipe(recipe, alt='en'): + def ingredientsForRecipe(recipe, alt='en', mode='raw'): meaList = self.settings[alt]['measures'] repFrac = self.settings[alt]['replFrac'] for line in recipe['ingredients']: - line = line.strip() + line = tex.raw_text_to_tex(line).strip() if not line: continue elif line.endswith(':'): @@ -210,6 +229,8 @@ class HelperPlugin(Plugin): # groups[undefinedKey].update(groups.pop('_undefined')) return groups.items() + self.env.jinja_env.filters['sorted_images'] = sorted_images + self.env.jinja_env.filters['title_image'] = title_image self.env.jinja_env.filters['rating'] = numFillWithText self.env.jinja_env.filters['replaceFractions'] = replaceFractions self.env.jinja_env.filters['enumIngredients'] = ingredientsForRecipe diff --git a/src/packages/html-to-tex/.gitignore b/src/packages/html-to-tex/.gitignore new file mode 100644 index 0000000..463960b --- /dev/null +++ b/src/packages/html-to-tex/.gitignore @@ -0,0 +1,5 @@ +dist +build +*.pyc +*.pyo +*.egg-info diff --git a/src/packages/html-to-tex/html2latex.sed b/src/packages/html-to-tex/html2latex.sed new file mode 100644 index 0000000..d9832f0 --- /dev/null +++ b/src/packages/html-to-tex/html2latex.sed @@ -0,0 +1,62 @@ +# character set translations for LaTex special chars +s?>.?>?g +s?<.??\\par ?g +s?

??g +# Headings +s?\([^<]*\)?\\section*{\1}?g +s??\\part{?g +s??}?g +s?

?\\section*{?g +s??}?g +s?

?\\subsection*{?g +s?

?\\subsubsection*{?g +s?

?\\paragraph*{?g +s?

?\\paragraph*{?g +s?
?\\subparagraph*{?g +# UL is itemize +s??\\end{itemize}?g +s?
    ?\\begin{enumerate}?g +s?
?\\end{enumerate}?g +s?
  • ?\\item ?g +s?
  • ??g +# DL is description +s?
    ?\\begin{description}?g +s?
    ?\\end{description}?g +# closing delimiter for DT is first < or end of line which ever comes first NO +#s?
    \([^<]*\)\([^<]*\)$?\\item[\1]?g +#s?
    ??g +#s?
    ?\\item[?g +#s?
    ?]?g +s?
    \([^<]*\)
    ?\\item[\1]?g +s?
    ??g +s?
    ??g +# Italics +s?\([^<]*\)?{\\it \1}?g +s?\([^<]*\)?{\\it \1}?g +s?\([^<]*\)?{\\bf \1}?g +s?\([^<]*\)?{\\bf \1}?g +# old unused, because lektor generated internally other urls then output +# s?[^<]*?\\recipelink{\1}?g +# recipe specific +s?\([^<]*\)?\\recipelink{\1}{\2}?g +# Get rid of Anchors +s?\([^<]*\)?\\external{\1}{\2}?g +s?]*>??g +s???g +# after href replace +s?"?''?g diff --git a/src/packages/html-to-tex/lektor_html_to_tex.py b/src/packages/html-to-tex/lektor_html_to_tex.py new file mode 100644 index 0000000..df6bd12 --- /dev/null +++ b/src/packages/html-to-tex/lektor_html_to_tex.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +from lektor.pluginsystem import Plugin # , get_plugin +import os +import subprocess + +my_dir = os.path.dirname(os.path.realpath(__file__)) +f_sed_a = os.path.join(my_dir, 'html2latex.sed') + + +def sed_repl_content(f_sed, content): + with subprocess.Popen(('echo', content), stdout=subprocess.PIPE) as ps: + o = subprocess.check_output(['sed', '-f', f_sed], stdin=ps.stdout) + ps.wait() + return o.decode('utf-8') + + +def html_to_tex(html): + return sed_repl_content(f_sed_a, html) + + +def raw_text_to_tex(text): + text = text.replace('\\', '\\backslash ').replace(' ', '~') + for c in '}{%$&#_~^': + if c in text: + text = text.replace(c, '\\' + c) + return text + # return sed_repl_content(f_sed_b, text) + + +class HtmlToTex(Plugin): + name = u'HTML to TEX converter' + description = u'Will convert html formatted text to (la)tex format.' + + def on_before_build_all(self, builder, **extra): + # export current build dir + dest_file = my_dir + for x in range(3): + dest_file = os.path.dirname(dest_file) + dest_file = os.path.join(dest_file, 'extras', 'pdf-export', + 'setup-builddir.tex') + with open(dest_file, 'w') as f: + f.write('\\def\\builddir{' + builder.destination_path + '}') + + def on_setup_env(self, **extra): + self.env.jinja_env.filters['html_to_tex'] = html_to_tex + self.env.jinja_env.filters['raw_text_to_tex'] = raw_text_to_tex diff --git a/src/packages/html-to-tex/setup.py b/src/packages/html-to-tex/setup.py new file mode 100755 index 0000000..6f1c006 --- /dev/null +++ b/src/packages/html-to-tex/setup.py @@ -0,0 +1,12 @@ +from setuptools import setup + +setup( + name='lektor-html-to-tex', + py_modules=['lektor_html-to-tex'], + version='1.0', + entry_points={ + 'lektor.plugins': [ + 'html-to-tex = lektor_html_to_tex:HtmlToTex', + ] + } +) diff --git a/src/templates/cache.manifest b/src/templates/cache.manifest index 284e723..8e9b93b 100644 --- a/src/templates/cache.manifest +++ b/src/templates/cache.manifest @@ -2,8 +2,8 @@ CACHE MANIFEST # Date build: {{ DATE_NOW }} {%- macro _print_(items) -%} -{%- for item in items -%} - {{ item|replace('../', '', 1) }} +{%- for item in items if not item.endswith('tex') -%} + {{ item }} {% endfor -%} {%- endmacro -%} @@ -33,10 +33,10 @@ CACHE MANIFEST {%- endfor -%} {%- endif -%} - {% set img = x.attachments.images.order_by('record_label').first() -%} + {#{% set img = x | title_image(small=True) -%} {%- if img -%} - {{- _add_(cacheList, img.thumbnail(200, 150, 'crop')) -}} - {%- endif -%} + {{- _add_(cacheList, img) -}} + {%- endif -%}#} {%- if x.datamodel.has_own_children -%} {{- loop(x.children) -}} diff --git a/src/templates/macros/recipes.html b/src/templates/macros/recipes.html index 366ecd4..c612aff 100644 --- a/src/templates/macros/recipes.html +++ b/src/templates/macros/recipes.html @@ -2,7 +2,7 @@
    {%- for recipe in recipes -%} {%- if limit == 0 or loop.index <= limit -%} - {%- set img = recipe.attachments.images.order_by('record_label').first() -%} + {%- set img = recipe | title_image(small=True) -%} {#--#}
    @@ -17,7 +17,7 @@ {#- show image or placeholder text #} {% if img -%} - + {%- else -%}
    No Image
    {%- endif -%} diff --git a/src/templates/makepdf.tex b/src/templates/makepdf.tex new file mode 100644 index 0000000..3a752b7 --- /dev/null +++ b/src/templates/makepdf.tex @@ -0,0 +1,31 @@ +{%- set recipe_label = localize(this.alt, 'ingredients.recipeLink') %} + +{%- for recipe in site.get('/recipes', this.alt).children %} +\newrecipe{ {{- recipe._slug }}}{ {{- recipe.name | raw_text_to_tex }}} +\meta{ {{- recipe.time|duration(this.alt) if recipe.time else '' }}}{ {{- recipe.yield or '' }}} +\footer{ {{- recipe.source | string | raw_text_to_tex or '' }}}{ {{- recipe.source.host | raw_text_to_tex if recipe.source.host else '' }}} + {%- set img = recipe | title_image(small=True) %} + +\begin{ingredients}{ {%- if img %}{{ img|url }}{% else %}{% endif %}} + {%- for ing in recipe|enumIngredients(this.alt, mode='tex') %} + {%- if ing['group'] %} +\ingGroup{ {{- ing['group'] | raw_text_to_tex }}} + {%- else %} +\item + {%- if ing['value'] or ing['measure'] -%} + [{%- if ing['value'] %}{{ ing['value'] }}{% endif -%} + {%- if ing['measure'] %}~{{ ing['measure'] }}{% endif -%}] + {%- endif %} \ingName{ {{- ing['name'] -}}} + {%- if ing['note'] %}\ingDetail{ + {%- for prt in ing['note'].split() -%} + {%- if prt.startswith('@../') %} \pagelink{ {{- prt[4:-1] -}} } + {%- else %} {{ prt -}} + {%- endif -%} + {%- endfor -%}} + {%- endif -%} + {%- endif -%} + {%- endfor %} +\end{ingredients} + +{{ recipe.directions.html | html_to_tex }} +{%- endfor %} diff --git a/src/templates/recipe.html b/src/templates/recipe.html index f2383a5..b0b2a1b 100644 --- a/src/templates/recipe.html +++ b/src/templates/recipe.html @@ -4,7 +4,7 @@