From 2970a04be8d3611c855d22edc7bee3bcfa6eb823 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois-Xavier=20Carton?= Date: Mon, 9 Nov 2020 02:10:30 +0100 Subject: add feeds support (rss, atom) --- blogit | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/blogit b/blogit index f5362c5..24e79d4 100755 --- a/blogit +++ b/blogit @@ -8,6 +8,11 @@ endif # The following can be configured in config BLOG_DATE_FORMAT_INDEX ?= %x BLOG_DATE_FORMAT ?= %x %X +BLOG_TITLE ?= blog +BLOG_DESCRIPTION ?= blog +BLOG_URL_ROOT ?= http://localhost/blog +BLOG_FEED_MAX ?= 20 +BLOG_FEEDS ?= rss atom .PHONY: help init build deploy clean @@ -38,7 +43,7 @@ init: printf '' > templates/article_footer.html printf 'blog\n' > .git/info/exclude -build: blog/index.html tagpages $(patsubst articles/%,blog/%.html,$(ARTICLES)) +build: blog/index.html tagpages $(patsubst articles/%,blog/%.html,$(ARTICLES)) $(patsubst %,blog/%.xml,$(BLOG_FEEDS)) deploy: build rsync -rLtvz $(BLOG_RSYNC_OPTS) blog/ data/ $(BLOG_REMOTE) @@ -57,7 +62,7 @@ tags/%: articles/% blog/index.html: $(ARTICLES) $(TAGFILES) $(addprefix templates/,$(addsuffix .html,header index_header tag_list_header tag_entry tag_separator tag_list_footer article_list_header article_entry article_separator article_list_footer index_footer footer)) mkdir -p blog - TITLE="index"; \ + TITLE="$(BLOG_TITLE)"; \ export TITLE; \ envsubst < templates/header.html > $@; \ envsubst < templates/index_header.html >> $@; \ @@ -158,3 +163,36 @@ blog/%.html: articles/% $(addprefix templates/,$(addsuffix .html,header article_ envsubst < templates/article_footer.html >> $@; \ envsubst < templates/footer.html >> $@; \ +blog/rss.xml: $(ARTICLES) + printf '\n\n\n%s\n%s\n%s\n' \ + "$(BLOG_TITLE)" "$(BLOG_URL_ROOT)" "$(BLOG_DESCRIPTION)" > $@ + for f in $(ARTICLES); do \ + printf '%s ' "$$f"; \ + git log --diff-filter=A --date="format:%s %a, %d %b %Y %H:%M:%S %z" --pretty=format:'%ad%n' -- "$$f"; \ + done | sort -k2nr | head -n $(BLOG_FEED_MAX) | cut -d" " -f1,3- | while IFS=" " read -r FILE DATE; do \ + printf '\n%s\n%s\n%s\n%s\n%s\n\n' \ + "`head -n 1 $$FILE`" \ + "$(BLOG_URL_ROOT)/`basename $$FILE`.html" \ + "$(BLOG_URL_ROOT)/`basename $$FILE`.html" \ + "$$DATE" \ + "`sed -n '1d;/^$$/{2{d;b};q};p' < $$FILE`"; \ + done >> $@ + printf '\n\n' >> $@ + +blog/atom.xml: $(ARTICLES) + printf '\n\n%s\n%s\n%s\n\n%s\n\n' \ + "$(BLOG_TITLE)" "$(BLOG_DESCRIPTION)" "$(shell date +%Y-%m-%dT%H:%M:%SZ)" "$(BLOG_URL_ROOT)" "$(BLOG_URL_ROOT)/atom.xml" "$(BLOG_URL_ROOT)/atom.xml" > $@ + for f in $(ARTICLES); do \ + printf '%s ' "$$f"; \ + git log --diff-filter=A --date="format:%s %Y-%m-%dT%H:%M:%SZ" --pretty=format:'%ad %aN%n' -- "$$f"; \ + done | sort -k2nr | head -n $(BLOG_FEED_MAX) | cut -d" " -f1,3- | while IFS=" " read -r FILE DATE AUTHOR; do \ + printf '\n%s\n\n%s\n%s\n%s\n%s\n%s\n\n' \ + "`head -n 1 $$FILE`" \ + "$(BLOG_URL_ROOT)/`basename $$FILE`.html" \ + "$(BLOG_URL_ROOT)/`basename $$FILE`.html" \ + "$$DATE" \ + "`git log -n 1 --date="format:%Y-%m-%dT%H:%M:%SZ" --pretty=format:'%ad' -- "$$FILE"`" \ + "$$AUTHOR" \ + "`sed -n '1d;/^$$/{2{d;b};q};p' < $$FILE`"; \ + done >> $@ + printf '\n' >> $@ -- cgit v1.2.3