Generate plain text versions of wiki articles, with links in footnotes

This commit is contained in:
Travis Briggs 2020-04-25 12:40:40 -07:00
parent 6ae86fb2a6
commit 8036feee67
3 changed files with 32 additions and 2 deletions

1
wiki/.gitignore vendored
View File

@ -1 +1,2 @@
*.html
*.txt

View File

@ -1,10 +1,10 @@
SRC_MD_FILES != find source -name '*.md'
DST_HTML_FILES := $(SRC_MD_FILES:source/%.md=%.html)
DST_TXT_FILES := $(SRC_MD_FILES:source/%.md=%.txt)
PANDOC != command -v pandoc 2> /dev/null
PHP != command -v php 2> /dev/null
all: dep-pandoc $(DST_HTML_FILES) index
all: dep-pandoc $(DST_HTML_FILES) $(DST_TXT_FILES) index
index: dep-php index.html
%.html: %.php
@ -24,9 +24,20 @@ index: dep-php index.html
--output $@ \
$<
%.txt: source/%.md link_footnote.lua
$(info building $@)
@$(PANDOC) \
--from markdown+backtick_code_blocks \
--to plain \
--lua-filter ./link_footnote.lua \
--standalone \
--output $@ \
$<
clean:
$(info removing generated files)
-rm $(DST_HTML_FILES)
-rm $(DST_TXT_FILES)
dep-pandoc::
ifndef PANDOC

18
wiki/link_footnote.lua Normal file
View File

@ -0,0 +1,18 @@
links = {}
function Link (el)
table.insert(links,
pandoc.Para({
pandoc.Str("[" .. (#links + 1) .. "]"),
pandoc.Space(),
pandoc.Str(el.target),
})
)
table.insert(el.content, pandoc.Str("[" .. #links .. "]"))
return el.content
end
function Pandoc (doc)
table.insert(doc.blocks, pandoc.Div(links))
return pandoc.Pandoc(doc.blocks, doc.meta)
end