diff options
author | eug-vs <eugene@eug-vs.xyz> | 2022-04-21 14:07:09 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2022-04-21 14:07:09 +0300 |
commit | 9f3c80d1072b2445edcc72073506a4e37caa262a (patch) | |
tree | 06769feeb39da253f3de36d36c4e2cfdb80ddcec | |
parent | 691fa34413ebae101b6fd714158bdcb976abf87c (diff) | |
download | benzin-9f3c80d1072b2445edcc72073506a4e37caa262a.tar.gz |
feat: use page template
-rw-r--r-- | Makefile | 46 |
1 files changed, 26 insertions, 20 deletions
@@ -3,8 +3,11 @@ BASE_URL=https://example.com PANDOC_ARGS=--from=gfm+emoji --to=html --section-divs -HEADER=templates/header.html +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 @@ -19,35 +22,38 @@ HTML=$(patsubst src/%.md, out/%.html, $(SOURCES)) BLOG_XML=$(patsubst src/%.md, tmp/%.xml, $(BLOG_SOURCES)) .PHONY: clean all -.SECONDARY: $(TMP_HTML) +.SECONDARY: $(TMP_HTML) $(BLOG_XML) all: $(HTML) $(RSS) -out/%.html: $(HEADER) tmp/%.content.html $(OPENRING_FOOTER) +out/%.html: tmp/%.content.html tmp/%.meta.title $(PAGE_TEMPLATE) $(OPENRING_FOOTER) @mkdir -p $(@D) - cat $^ > $@ + 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) pandoc $(PANDOC_ARGS) $< > $@ -$(RSS): $(BLOG_XML) +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) - @echo '<rss version="2.0"><channel>' > $@ - @echo "<title>TODO</title><link>$(BASE_URL)</link><description>TODO</description>" >> $@ - @echo "<lastBuildDate>$$(date --rfc-email)</lastBuildDate>" >> $@ - cat $^ >> $@ - @echo '</channel></rss>' >> $@ - -tmp/%.xml: tmp/%.content.html - @echo '<item>' > $@ - @echo " <link>$(BASE_URL)/$*.html</link>" >> $@ - @echo " <pubDate>TODO</pubDate>" >> $@ - @echo " <title>TODO</title>" >> $@ - @echo " <description><![CDATA[" >> $@ - cat $< >> $@ - @echo " ]]></description>" >> $@ - @echo '</item>' >> $@ + 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) |