diff options
-rw-r--r--[-rwxr-xr-x] | blogit | 31 |
1 files changed, 21 insertions, 10 deletions
@@ -1,15 +1,16 @@ #!/usr/bin/make -f - +# Source: https://pedantic.software/git/blogit/ BLOG := $(MAKE) -f $(lastword $(MAKEFILE_LIST)) --no-print-directory ifneq ($(filter-out help,$(MAKECMDGOALS)),) include config endif # The following can be configured in config -BLOG_DATE_FORMAT_INDEX ?= %x -BLOG_DATE_FORMAT ?= %x %X +BLOG_DATE_FORMAT_INDEX ?= %d/%m/%Y +BLOG_DATE_FORMAT ?= %d/%m/%Y %X BLOG_TITLE ?= blog BLOG_DESCRIPTION ?= blog +BLOG_AUTHOR ?= John Doe BLOG_URL_ROOT ?= http://localhost/blog BLOG_FEED_MAX ?= 20 BLOG_FEEDS ?= rss atom @@ -65,6 +66,10 @@ blog/index.html: $(ARTICLES) $(TAGFILES) $(addprefix templates/,$(addsuffix .htm mkdir -p blog TITLE="$(BLOG_TITLE)"; \ export TITLE; \ + DESCRIPTION="$(BLOG_DESCRIPTION)"; \ + export DESCRIPTION; \ + AUTHOR="$(BLOG_AUTHOR)"; \ + export AUTHOR; \ envsubst < templates/header.html > $@; \ envsubst < templates/index_header.html >> $@; \ envsubst < templates/tag_list_header.html >> $@; \ @@ -103,8 +108,10 @@ tagpages: $(TAGFILES) blog/@%.html: $(TAGFILES) $(addprefix templates/,$(addsuffix .html,header tag_index_header tag_list_header tag_entry tag_separator tag_list_footer article_list_header article_entry article_separator article_list_footer tag_index_footer footer)) mkdir -p blog - TITLE="Articles tagged $*"; \ + TITLE="$(BLOG_TITLE) - Articles tagged $*"; \ TAGS="$*"; \ + AUTHOR=""; \ + export AUTHOR; \ export TITLE; \ export TAGS; \ envsubst < templates/header.html > $@; \ @@ -129,9 +136,9 @@ blog/@%.html: $(TAGFILES) $(addprefix templates/,$(addsuffix .html,header tag_in blog/%.html: $(BLOG_SRC)/%.md $(addprefix templates/,$(addsuffix .html,header article_header article_footer footer)) mkdir -p blog - TITLE="$(shell head -n1 $<)"; \ + TITLE=" $(BLOG_TITLE) - $(shell head -n1 $<)"; \ export TITLE; \ - AUTHOR="$(shell git log -n 1 --reverse --format="%cn" -- "$<")"; \ + AUTHOR="$(shell git log -n 1 --reverse --format="%an" -- "$<")"; \ export AUTHOR; \ DATE_POSTED="$(shell git log --diff-filter=A --date="format:$(BLOG_DATE_FORMAT)" --pretty=format:'%ad' -- "$<")"; \ export DATE_POSTED; \ @@ -139,6 +146,10 @@ blog/%.html: $(BLOG_SRC)/%.md $(addprefix templates/,$(addsuffix .html,header ar export DATE_EDITED; \ TAGS="$(shell grep -i '^; *tags:' "$<" | cut -d: -f2- | paste -sd ',')"; \ export TAGS; \ + DESCRIPTION="$(shell grep -i '^; *description:' "$<" | cut -d: -f2-)"; \ + export DESCRIPTION; \ + OG_IMAGE="$(shell grep -i '^; *og_image:' "$<" | cut -d: -f2-)"; \ + export OG_IMAGE; \ envsubst < templates/header.html > $@; \ envsubst < templates/article_header.html >> $@; \ sed -e 1d \ @@ -176,11 +187,11 @@ blog/rss.xml: $(ARTICLES) 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`" \ + "`head -n 1 $$FILE | sed 's/&/&/'`" \ "$(BLOG_URL_ROOT)/`basename $$FILE .md`.html" \ "$(BLOG_URL_ROOT)/`basename $$FILE .md`.html" \ "$$DATE" \ - "`sed -n '1d;/^$$/{2{d;b};q};p' < $$FILE`"; \ + "`cat "$$FILE" | grep ";description:" | cut -d: -f2-`"; \ done >> $@ printf '</channel>\n</rss>\n' >> $@ @@ -192,12 +203,12 @@ blog/atom.xml: $(ARTICLES) 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`" \ + "`head -n 1 $$FILE | sed 's/&/&/'`" \ "$(BLOG_URL_ROOT)/`basename $$FILE .md`.html" \ "$(BLOG_URL_ROOT)/`basename $$FILE .md`.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`"; \ + "`cat "$$FILE" | grep ";description:" | cut -d: -f2-`"; \ done >> $@ printf '</feed>\n' >> $@ |