From 9f3c80d1072b2445edcc72073506a4e37caa262a Mon Sep 17 00:00:00 2001 From: eug-vs Date: Thu, 21 Apr 2022 14:07:09 +0300 Subject: feat: use page template --- Makefile | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 2352b12..42219a6 100644 --- a/Makefile +++ b/Makefile @@ -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 '//{' \ + -e 'a ' -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$(BASE_URL)TODO" >> $@ - @echo "$$(date --rfc-email)" >> $@ - cat $^ >> $@ - @echo '' >> $@ - -tmp/%.xml: tmp/%.content.html - @echo '' > $@ - @echo " $(BASE_URL)/$*.html" >> $@ - @echo " TODO" >> $@ - @echo " TODO" >> $@ - @echo " > $@ - cat $< >> $@ - @echo " ]]>" >> $@ - @echo '' >> $@ + sed "/CDATA/r $<" $(RSS_ITEM_TEMPLATE) > $@ + sed -i \ + -e '//{' \ + -e 'a ' -e "r tmp/$*.meta.title" -e 'a <\/title>' \ + -e "a <link>$(BASE_URL)/$*.html<\/link>" \ + -e '}' $@ $(OPENRING_FOOTER): $(OPENRING_TEMPLATE) @mkdir -p $(@D) -- cgit v1.2.3