EPUB: Populate acknowledgements.md with contributors

Use liquid-lua to generate acknowledgements_epub.md, which is used by
pandoc to build the EPUB book.  Also stop using the '{%-' / '-%}'
syntax, which liquid-lua does not support, in templates.

Also add a vertical space between the first bullet in each bulleted
list so pandoc recognizes bulleted lists as such. This has no effect on
the the website.
This commit is contained in:
Michael Reed 2020-06-19 11:21:00 -04:00
parent 80ba7fdfec
commit 99aa26401f
7 changed files with 73 additions and 26 deletions

4
.gitignore vendored
View file

@ -26,3 +26,7 @@ Gemfile.lock
## Emacs files
auto/
## Misc build files
out/
src/plfa/acknowledgements_epub.md

View file

@ -22,6 +22,7 @@ addons:
packages:
- libgmp-dev
- libicu-dev
- luarocks
# Ensure we run BASH and not SH
env:

View file

@ -49,12 +49,10 @@ out/:
# sections are displayed to users. Some readers may be slow if the chapter
# files are too large, so for large documents with few level-1 headings, one
# might want to use a chapter level of 2 or 3."
#
#TODO: embedded fonts not working (path problem?)
epub: out/plfa.epub
out/plfa.epub: out/ $(AGDA) $(LUA) epub/main.css
out/plfa.epub: out/ $(AGDA) $(LUA) epub/main.css src/plfa/acknowledgements_epub.md
pandoc --strip-comments \
--css=epub/main.css \
--epub-embed-font='assets/fonts/mononoki.woff' \
@ -62,6 +60,7 @@ out/plfa.epub: out/ $(AGDA) $(LUA) epub/main.css
--epub-embed-font='assets/fonts/DejaVuSansMono.woff' \
--lua-filter epub/include-files.lua \
--lua-filter epub/rewrite-links.lua \
--lua-filter epub/rewrite-html-ul.lua \
--lua-filter epub/default-code-class.lua -M default-code-class=agda \
--standalone \
--fail-if-warnings \
@ -70,7 +69,8 @@ out/plfa.epub: out/ $(AGDA) $(LUA) epub/main.css
-o "$@" \
epub/index.md
src/plfa/acknowledgements_epub.md: src/plfa/acknowledgements.md _config.yml
lua epub/run-liquid.lua _config.yml $< > $@
# Convert literal Agda to Markdown
@ -119,7 +119,7 @@ build-incremental: $(MARKDOWN)
# Remove all auxiliary files
clean:
rm -f .agda-stdlib.sed .links-*.sed
rm -f .agda-stdlib.sed .links-*.sed src/plfa/acknowledgements_epub.md
ifneq ($(strip $(AGDAI)),)
rm $(AGDAI)
endif
@ -158,6 +158,9 @@ travis-setup:\
$(HOME)/agda-stdlib-$(AGDA_STDLIB_VERSION)/src\
$(HOME)/.agda/defaults\
$(HOME)/.agda/libraries\
$(HOME)/.local/share/lua/5.1/tinyyaml.lua\
$(HOME)/.local/share/lua/5.1/liquid.lua\
$(HOME)/.local/share/lua/5.1/cjson\
/usr/bin/pandoc
.phony: travis-setup
@ -204,6 +207,17 @@ $(HOME)/.local/bin/agda:
cd $(HOME)/agda-$(AGDA_VERSION);\
stack install --stack-yaml=stack-8.0.2.yaml
$(HOME)/.local/share/lua/5.1/tinyyaml.lua:
luarocks install lua-tinyyaml
$(HOME)/.local/share/lua/5.1/liquid.lua:
luarocks install liquid
$(HOME)/.local/share/lua/5.1/cjson:
# Only this particular version works:
# https://github.com/mpx/lua-cjson/issues/56:
luarocks install lua-cjson 2.1.0-1
travis-uninstall-agda:
rm -rf $(HOME)/agda-$(AGDA_VERSION)/
rm -f $(HOME)/.local/bin/agda

View file

@ -65,7 +65,7 @@ src/plfa/part2/Substitution.lagda.md
# Backmatter
``` {.include shift-heading-level-by=1}
src/plfa/acknowledgements.md
src/plfa/acknowledgements_epub.md
src/plfa/Fonts.lagda.md
src/plfa/statistics.md
```

5
epub/rewrite-html-ul.lua Normal file
View file

@ -0,0 +1,5 @@
-- Transforms '<ul class={something}>' into '<ul>'.
function RawBlock (el)
el.text = el.text:gsub('%s*<%s*ul%s*class=%s*"?[%w-]+"?%s*>%s*', '<ul>')
return el
end

19
epub/run-liquid.lua Normal file
View file

@ -0,0 +1,19 @@
local yaml = require 'tinyyaml'
local liquid = require 'liquid'
if #arg ~= 2 then
print('usage: ' .. arg[0] .. ' [yaml_file] [markdown_file]')
os.exit(1)
end
-- 1. Read YAML metadata from file, which we nest under the key 'site'.
local metadata = { ['site'] = yaml.parse(io.open(arg[1]):read('a')) }
-- 2. Read markdown document from file.
local document = io.open(arg[2]):read('a')
-- 3. Render the markdown document with the YAML metadata as context.
local template = liquid.Template:parse(document)
local result = template:render(liquid.InterpreterContext:new(metadata))
print(result)

View file

@ -7,12 +7,14 @@ next : /Fonts/
---
Thank you to:
* The inventors of Agda, for a new playground.
* The authors of Software Foundations, for inspiration.
A special thank you, for inventing ideas on which
this book is based, and for hand-holding:
<ul class="list-of-contributors">
<li>Andreas Abel</li>
<li>Catarina Coquand</li>
@ -25,31 +27,33 @@ this book is based, and for hand-holding:
<li>Ulf Norell</li>
</ul>
{%- if site.contributors or site.extra_contributors -%}
{% if site.contributors or site.extra_contributors %}
For pull requests big and small, and for answering questions on the Agda mailing list:
<ul class="list-of-contributors">
{%- for contributor in site.contributors -%}
{% for contributor in site.contributors %}
<li><a href="https://github.com/{{ contributor.github_username }}">{{ contributor.name }}</a></li>
{%- endfor -%}
{%- for contributor in site.extra_contributors -%}
{%- if contributor.name and contributor.github_username -%}
{% endfor %}
{% for contributor in site.extra_contributors %}
{% if contributor.name and contributor.github_username %}
<li><a href="https://github.com/{{ contributor.github_username }}">{{ contributor.name }}</a></li>
{%- else -%}
{%- if contributor.name -%}
{% else %}
{% if contributor.name %}
<li>{{ contributor.name }}</li>
{%- endif -%}
{%- if contributor.github_username -%}
{% endif %}
{% if contributor.github_username %}
<li><a href="https://github.com/{{ contributor.github_username }}">{{ contributor.github_username }}</a></li>
{%- endif -%}
{%- endif -%}
{%- endfor -%}
{% endif %}
{% endif %}
{% endfor %}
<li>[Your name goes here]</li>
</ul>
{%- else -%}
{%- endif -%}
{% else %}
{% endif %}
For support:
* EPSRC Programme Grant EP/K034413/1
* NSF Grant No. 1814460
* Foundation Sciences Mathematiques de Paris (FSMP)