website - Bash file redirection instead of string interpretation in Pandoc makefile -
introduction
i started using pandoc markdown generate static xhtml personal website. managed automatically insert couple of links refer $(name)
of .md
file using pandoc -b
argument (see below makefile
). pandoc -b
argument designed contain file name, had use output redirection of echo
command in addition shell interpretation.
the problem
the pandoc -b
argument has grown long maintained within makefile
. want move xhtml string separate file whilst keeping bash string interpretation. cat
command not because not part of bash.
shell := /bin/bash name = $(basename $(wildcard *.md)) all: index.html html: index.html index.html: $(name).md pandoc $< -s -o $@ \ -b <(echo "<div id=\"pdf\"><ul><li><a href=\"$(name).a4.pdf\">a4 pdf</a></li><li><a href=\"$(name).letter.pdf\">letter pdf</a></li></ul></div><div id=\"source\"><ul><li><a href=\"../$(name).bib\">bibtex references</a></li><li><a href=\"$(name).md\">pandoc markdown</a></li><li><a href=\"makefile\">makefile</a></li></ul></div>")
how bout using sed template? example, file , word templates {__name__}
:
<div id="pdf"><ul><li><a href="{__name__}.a4.pdf">a4 pdf</a></li><li><a href="{__name__}.letter.pdf">letter pdf</a></li></ul></div><div id="source"><ul><li><a href="../{__name__}.bib">bibtex references</a></li><li><a href="{__name__}.md">pandoc markdown</a></li><li><a href="makefile">makefile</a></li></ul></div>
you use sed replace them:
pandoc $< -s -o $@ \ -b <(sed -e "s|{__name__}|$(name)|g" file.txt)
Comments
Post a Comment