- commit
 - 35fd5a415ec88cfe60236749d8ced9698773d272
 - parent
 - 85519303403f4995a0954e3362f4bc5b6c457c73
 - Author
 - Tobias Bengfort <tobias.bengfort@posteo.de>
 - Date
 - 2024-02-12 11:05
 
add JSON feed https://www.jsonfeed.org/version/1.1/
Diffstat
| M | Makefile | 16 | +++++++++++----- | 
| M | _templates/base.html | 1 | + | 
| R | feed.sh -> feed-atom.sh | 0 | |
| A | feed-json.sh | 46 | ++++++++++++++++++++++++++++++++++++++++++++++ | 
4 files changed, 58 insertions, 5 deletions
diff --git a/Makefile b/Makefile
@@ -7,7 +7,7 @@ IMG := $(shell find _content -regex '.*\.\(png\|gif\|jpg\)$$' | sed 's/^_content 7 7 PANDOC_ARGS = -f markdown-smart --wrap=none 8 8 9 9 .PHONY: all10 -1 all: build/index.html $(PAGES) $(PAGES_MD) build/feed.xml build/feed-archive.xml $(STATIC) build/static/style.css $(IMG)-1 10 all: build/index.html $(PAGES) $(PAGES_MD) build/feed.xml build/feed-archive.xml build/feed.json build/feed-archive.json $(STATIC) build/static/style.css $(IMG) 11 11 12 12 .PHONY: push 13 13 push: all @@ -38,11 +38,17 @@ build/%.jpg: _content/%.jpg 38 38 build/%.gif: _content/%.gif 39 39 ln $< $@ 40 4041 -1 build/feed.xml: feed.sh $(PAGES_FEED)42 -1 ./feed.sh > $@-1 41 build/feed.xml: feed-atom.sh $(PAGES_FEED) -1 42 ./feed-atom.sh > $@ 43 4344 -1 build/feed-archive.xml: feed.sh $(PAGES_FEED)45 -1 ./feed.sh -a > $@-1 44 build/feed-archive.xml: feed-atom.sh $(PAGES_FEED) -1 45 ./feed-atom.sh -a > $@ -1 46 -1 47 build/feed.json: feed-json.sh $(PAGES_FEED) -1 48 ./feed-json.sh > $@ -1 49 -1 50 build/feed-archive.json: feed-json.sh $(PAGES_FEED) -1 51 ./feed-json.sh -a > $@ 46 52 47 53 build/static/%: static/% 48 54 @mkdir -p $$(dirname $@)
diff --git a/_templates/base.html b/_templates/base.html
@@ -9,6 +9,7 @@ 9 9 <title>Ξ${if(title)} - ${title}${endif}</title> 10 10 <link rel="stylesheet" type="text/css" href="/static/style.css"> 11 11 <link rel="alternate" type="application/atom+xml" href="/feed.xml"> -1 12 <link rel="alternate" type="application/feed+json" href="/feed.json"> 12 13 </head> 13 14 14 15 <body>
diff --git a/feed.sh b/feed-atom.sh
diff --git a/feed-json.sh b/feed-json.sh
@@ -0,0 +1,46 @@
   -1     1 #!/bin/sh
   -1     2 
   -1     3 base_url='https://blog.ce9e.org/'
   -1     4 
   -1     5 escape() {
   -1     6 	sed 's/\\/\\\\\\\\/g;s/"/\\"/g'
   -1     7 }
   -1     8 
   -1     9 value() {
   -1    10 	printf '%.*s"%s": "%s",\n' "$1" '		' "$2" "$3"
   -1    11 }
   -1    12 
   -1    13 echo '{'
   -1    14 value 1 'version' "https://jsonfeed.org/version/1.1"
   -1    15 echo '	"authors": [{"name": "Tobias Bengfort"}],'
   -1    16 value 1 'title' 'Ξ'
   -1    17 value 1 'home_page_url' "$base_url"
   -1    18 if [ "$1" = '-a' ]; then
   -1    19 	value 1 'feed_url' "${base_url}feed-archive.json"
   -1    20 	select='tail -n +11'
   -1    21 else
   -1    22 	value 1 'feed_url' "${base_url}feed.json"
   -1    23 	value 1 'next_url' "${base_url}feed-archive.json"
   -1    24 	select='head -n 10'
   -1    25 fi
   -1    26 
   -1    27 ls _content/posts | tac | $select | while read l; do
   -1    28 	if [ -z "$loop" ]; then
   -1    29 		echo '	"items": [{'
   -1    30 		loop=1
   -1    31 	else
   -1    32 		echo '	}, {'
   -1    33 	fi
   -1    34 
   -1    35 	yml="_content/posts/$l/index.md"
   -1    36 	html="_content/posts/$l/index.html"
   -1    37 	url="${base_url}posts/$l/"
   -1    38 	value 2 'title' "$(grep '^title:' "$yml" | head -n 1 | sed 's/title: //;s/^"\(.*\)"$/\1/' | escape)"
   -1    39 	value 2 'url' "$url"
   -1    40 	value 2 'id' "$url"
   -1    41 	value 2 'date_published' "$(grep '^date:' "$yml" | head -n 1 | sed 's/date: //' | escape)"
   -1    42 	echo "		\"content_html\": \"$(cat "$html" | escape | sed 's/$/\\\\n/' | tr -d '\n')\""
   -1    43 done
   -1    44 echo '	}]'
   -1    45 
   -1    46 echo '}'