blob: 8712bf6b987eb0c795e1c9a123e2ab90c29342b0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# BENZIN Makefile
BASE_URL=https://example.com
CONVERT=pandoc --from=gfm+emoji --to=html --section-divs
PAGE_TEMPLATE=templates/page.html
OPENRING_TEMPLATE=templates/openring.html
RSS_TEMPLATE=templates/rss.xml
RSS_ITEM_TEMPLATE=templates/rss_item.xml
RSS=out/blog/index.xml
OPENRING_FOOTER=tmp/openring.html
OPENRING_ARGS=-s https://eug-vs.xyz/blog/index.xml -s https://drewdevault.com/blog/index.xml
BLOG_SOURCES=$(wildcard src/blog/*.md)
SOURCES=$(wildcard src/*.md) $(BLOG_SOURCES)
TMP_HTML=$(patsubst src/%.md, tmp/%.content.html, $(SOURCES))
HTML=$(patsubst src/%.md, out/%.html, $(SOURCES))
BLOG_XML=$(patsubst src/%.md, tmp/%.xml, $(BLOG_SOURCES))
.PHONY: clean all
.SECONDARY: $(TMP_HTML) $(BLOG_XML)
all: $(HTML) $(RSS)
out/%.html: tmp/%.content.html tmp/%.meta.title $(PAGE_TEMPLATE) $(OPENRING_FOOTER)
@mkdir -p $(@D)
sed "/<\/main>/e cat $< $(OPENRING_FOOTER)" $(PAGE_TEMPLATE) > $@
sed -i \
-e '/<head>/{' \
-e 'a <title>' -e "r tmp/$*.meta.title" -e 'a <\/title>' \
-e '}' $@
tmp/%.content.html: src/%.md
@mkdir -p $(@D)
$(CONVERT) $< > $@
tmp/%.meta.title: src/%.md
@mkdir -p $(@D)
sed '/^#/q' $< | sed 's/#* //' > $@
$(RSS): $(BLOG_XML) $(RSS_TEMPLATE)
@mkdir -p $(@D)
sed "/<\/channel>/e cat $(BLOG_XML)" $(RSS_TEMPLATE) > $@
tmp/%.xml: tmp/%.content.html tmp/%.meta.title $(RSS_ITEM_TEMPLATE)
@mkdir -p $(@D)
sed "/CDATA/r $<" $(RSS_ITEM_TEMPLATE) > $@
sed -i \
-e '/<item>/{' \
-e 'a <title>' -e "r tmp/$*.meta.title" -e 'a <\/title>' \
-e "a <link>$(BASE_URL)/$*.html<\/link>" \
-e '}' $@
$(OPENRING_FOOTER): $(OPENRING_TEMPLATE)
@mkdir -p $(@D)
openring $(OPENRING_ARGS) < $< > $@
clean:
rm -rf tmp out
|