summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2022-04-20 19:14:37 +0300
committereug-vs <eugene@eug-vs.xyz>2022-04-20 19:14:37 +0300
commit1664a85b1e6a62262ac4c49269e17d1949495de5 (patch)
tree5fac5d84747cd8dc4d557905130a3e13b1a010e5
parentb8c43baedc8e30d03aa356f03af9eb3b68b90675 (diff)
downloadeug-vs-xyz-1664a85b1e6a62262ac4c49269e17d1949495de5.tar.gz
feat: add RSS feed generation
-rw-r--r--.gitignore1
-rw-r--r--Makefile38
2 files changed, 31 insertions, 8 deletions
diff --git a/.gitignore b/.gitignore
index 07c47a0..55d21d3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
*.html
+*.xml
blog/preview.md
diff --git a/Makefile b/Makefile
index 3d48ace..575cb6e 100644
--- a/Makefile
+++ b/Makefile
@@ -5,8 +5,10 @@ MARKDOWN=gfm+emoji
STYLESHEET=/style.css
HEAD=head.html
HEADER=header.html
+RSS_FEED=blog/index.xml
OPENRING_FOOTER=footer.html
-PANDOC_ARGS=-s --from=$(MARKDOWN) --to=html -c $(STYLESHEET) -B $(HEADER) -H $(HEAD) -M lang="en" --shift-heading-level-by=1 --highlight-style=gruvbox.theme
+PANDOC_ARGS= --from=$(MARKDOWN) --to=html
+PANDOC_HTML_ARGS=-s $(PANDOC_ARGS) -c $(STYLESHEET) -B $(HEADER) -H $(HEAD) -M lang="en" --shift-heading-level-by=1 --highlight-style=gruvbox.theme
LINK_SEDSTRING=s/.md)/.html)/g;
EMOJI_SEDSTRING=$(shell ./compile_emoji_sedstring.sh)
@@ -18,26 +20,46 @@ OPENRING_ARGS=$(shell ./compile_openring_args.sh)
SOURCES=$(wildcard *.md blog/*.md articles/*.md)
HTML=$(patsubst %.md, %.html, $(SOURCES))
+XML=$(patsubst %.md, %.xml, $(filter-out blog/preview.md, $(filter-out blog/index.md, $(wildcard blog/*.md))))
-all: $(HTML)
+all: $(HTML) $(RSS_FEED)
%.html: %.md $(OPENRING_FOOTER)
@echo $@
@DESCRIPTION=$$(sed '2,/^$$/!d' $< | tr '\n' ' '); \
PAGETITLE=$$(sed '/^#/q' $< | sed 's/:[a-z]*://; s/#* //'); \
sed "$(LINK_SEDSTRING) $(EMOJI_SEDSTRING)" $< \
- | pandoc $(PANDOC_ARGS) -M pagetitle="$$PAGETITLE | $(TITLE)" -A $(OPENRING_FOOTER) -M description="$$DESCRIPTION" > $@
+ | pandoc $(PANDOC_HTML_ARGS) -M pagetitle="$$PAGETITLE | $(TITLE)" -A $(OPENRING_FOOTER) -M description="$$DESCRIPTION" > $@
+
+%.xml: %.md
+ @echo $@
+ @echo '<item>' > $@
+ @echo " <link>https://eug-vs.xyz/$*.html</link>" >> $@
+ @echo " <pubDate>$*</pubDate>" >> $@
+ @echo " <title>$$(sed '/^#/q' $< | sed 's/:[a-z]*://; s/#* //')</title>" >> $@
+ @echo " <description><![CDATA[" >> $@
+ @sed "$(LINK_SEDSTRING) $(EMOJI_SEDSTRING)" $< | pandoc $(PANDOC_ARGS) $< >> $@
+ @echo " ]]></description>" >> $@
+ @echo '</item>' >> $@
+
+$(RSS_FEED): $(XML)
+ @echo $@
+ @echo '<rss version="2.0"><channel>' > $@
+ @echo "<title>Eugene's Space</title><link>https://eug-vs.xyz</link><description>Eugene's blog</description>" >> $@
+ @cat $$(echo $^ | tr " " "\n" | sort -r | tr "\n" " ") >> $@
+ @echo '</channel></rss>' >> $@
index.html: index.md blog/preview.md
@echo $@
@DESCRIPTION=$$(sed '2,/^$$/!d' $< | tr '\n' ' '); \
sed "/Recent blog posts/r blog/preview.md" $< \
| sed "$(LINK_SEDSTRING) $(EMOJI_SEDSTRING)" \
- | pandoc $(PANDOC_ARGS) -M pagetitle="$(TITLE)" -M description="$$DESCRIPTION"> $@
+ | pandoc $(PANDOC_HTML_ARGS) -M pagetitle="$(TITLE)" -M description="$$DESCRIPTION"> $@
$(OPENRING_FOOTER): openring-template.html
- openring $(OPENRING_ARGS) < $< > $@
+ @echo $@
+ @openring $(OPENRING_ARGS) < $< > $@
blog/preview.md: blog/index.md
@echo $@
@@ -46,9 +68,9 @@ blog/preview.md: blog/index.md
open: $(HTML)
xdg-open index.html
-deploy: $(HTML)
+deploy: all
$(MAKE) unlocalize
- rsync -rtvzP --exclude=".git" --exclude="*.md" . $(RSYNC_DESTINATION)
+ rsync -rtvzP --include="$(RSS_FEED)" --exclude=".git" --exclude="*.md" --exclude="*.xml" . $(RSYNC_DESTINATION)
localize: $(HTML)
@for file in $^; do sed -i "$(UNLOCALIZE_SEDSTRING) $(LOCALIZE_SEDSTRING)" $$file; done
@@ -57,5 +79,5 @@ unlocalize: $(HTML)
@for file in $^; do sed -i "$(UNLOCALIZE_SEDSTRING)" $$file; done
clean:
- rm -f $(HTML) $(OPENRING_FOOTER) blog/preview.md
+ rm -f $(HTML) $(XML) $(OPENRING_FOOTER) $(RSS_FEED) blog/preview.md