diff options
Diffstat (limited to 'blogit')
-rwxr-xr-x | blogit | 42 |
1 files changed, 40 insertions, 2 deletions
@@ -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 '<?xml version="1.0" encoding="UTF-8"?>\n<rss version="2.0">\n<channel>\n<title>%s</title>\n<link>%s</link>\n<description>%s</description>\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 '<item>\n<title>%s</title>\n<link>%s</link>\n<guid>%s</guid>\n<pubDate>%s</pubDate>\n<description>%s</description>\n</item>\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 '</channel>\n</rss>\n' >> $@ + +blog/atom.xml: $(ARTICLES) + printf '<?xml version="1.0" encoding="UTF-8"?>\n<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">\n<title type="text">%s</title>\n<subtitle type="text">%s</subtitle>\n<updated>%s</updated>\n<link rel="alternate" type="text/html" href="%s"/>\n<id>%s</id>\n<link rel="self" type="application/atom+xml" href="%s"/>\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 '<entry>\n<title type="text">%s</title>\n<link rel="alternate" type="text/html" href="%s"/>\n<id>%s</id>\n<published>%s</published>\n<updated>%s</updated>\n<author><name>%s</name></author>\n<summary type="text">%s</summary>\n</entry>\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 '</feed>\n' >> $@ |