69 lines
2.7 KiB
Makefile
69 lines
2.7 KiB
Makefile
SHELL = /bin/sh
|
|
|
|
SRCDIR := src
|
|
BUILDDIR := build
|
|
|
|
INSTALLDIR_HTML := public_html/eh/eh/eh/eh-eh/
|
|
INSTALLDIR_ANSI := public_ansi/
|
|
|
|
ARTICLEDIR := articles
|
|
PANDOCDIR := pandoc
|
|
STYLEDIR := styles
|
|
IMAGEDIR := images
|
|
|
|
# The name of the stylesheet. This needs to be copied to any directory containing html files that use it.
|
|
style := $(STYLEDIR)/style.css
|
|
|
|
# Main html template that pandoc uses to generate .html from .md files
|
|
template_html := $(PANDOCDIR)/template.html
|
|
template_ansi := $(PANDOCDIR)/template
|
|
|
|
# Template for extracting metadata of .md files in json format
|
|
list_template := $(PANDOCDIR)/meta-json-template.txt
|
|
|
|
# Location of the shark.js
|
|
shark_js := $(PANDOCDIR)/shark.js
|
|
|
|
# List of articles with their metadata to be used in the creation of the article list in index.html
|
|
article_list := $(SRCDIR)/articles.json
|
|
|
|
# article targets
|
|
articles_md := $(wildcard $(SRCDIR)/$(ARTICLEDIR)/*.md)
|
|
|
|
articles_html := $(patsubst $(SRCDIR)/%.md, $(BUILDDIR)/%.html, $(articles_md))
|
|
articles_ansi := $(patsubst $(SRCDIR)/%.md, $(BUILDDIR)/%, $(articles_md))
|
|
|
|
all: $(BUILDDIR)/index.html $(BUILDDIR)/index
|
|
|
|
install:
|
|
cp -r $(BUILDDIR)/index.html $(articles_html) $(STYLEDIR) $(IMAGEDIR) $(INSTALLDIR_HTML); \
|
|
cp -r $(BUILDDIR)/index $(articles_ansi) $(INSTALLDIR_ANSI);
|
|
|
|
clean:
|
|
echo '{"articles": []}' > $(article_list); \
|
|
rm -r $(BUILDDIR)
|
|
|
|
$(BUILDDIR):
|
|
mkdir $(BUILDDIR) $(BUILDDIR)/$(ARTICLEDIR)
|
|
|
|
$(BUILDDIR)/$(ARTICLEDIR)/%.html: $(SRCDIR)/$(ARTICLEDIR)/%.md | $(BUILDDIR)
|
|
jq 'del(.articles[] | select(.filename == "$(notdir $@)"))' $(article_list) > articles.json.tmp; \
|
|
mv ./articles.json.tmp $(article_list); \
|
|
|
|
# Build articles using pandoc
|
|
pandoc $< --template $(template_html) --css $(style) --highlight-style zenburn --mathml --toc --output $@; \
|
|
|
|
# Extract metadata from .md file, append filename field to the article object.
|
|
# This is used to link to the article from index.html. Append article object to the article list.
|
|
jq '.articles += [$(shell pandoc $< --template $(list_template) | jq '. += {"filename": "$(patsubst %.html, %, $(notdir $@))"}')]' $(article_list) > articles.json.tmp; \
|
|
mv ./articles.json.tmp $(article_list); \
|
|
|
|
$(BUILDDIR)/$(ARTICLEDIR)/%: $(SRCDIR)/$(ARTICLEDIR)/%.md | $(BUILDDIR)
|
|
pandoc $< --template $(template_ansi) --to ansi --output $@
|
|
|
|
$(BUILDDIR)/index.html: $(SRCDIR)/index.md $(articles_html) | $(BUILDDIR)
|
|
# Build index.html with metadata injected from articles_list
|
|
pandoc $< --template $(template_html) --include-after-body $(shark_js) --css $(style) --metadata-file $(article_list) --highlight-style zenburn --mathml --toc --output $@; \
|
|
|
|
$(BUILDDIR)/index: $(SRCDIR)/index.md $(articles_ansi) | $(BUILDDIR)
|
|
pandoc $< --template $(template_ansi) --metadata-file $(article_list) --to ansi --output $@
|