From e11dc366400a54e57b437a81333c4a74248b29f9 Mon Sep 17 00:00:00 2001 From: Kurt H Maier Date: Mon, 25 May 2020 02:09:41 -0700 Subject: [PATCH] blagh: jsonfeed support --- apps/blagh/app.rc | 6 +++++- apps/blagh/jsonfeed.tpl | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 apps/blagh/jsonfeed.tpl diff --git a/apps/blagh/app.rc b/apps/blagh/app.rc index 52fd449..c63689d 100644 --- a/apps/blagh/app.rc +++ b/apps/blagh/app.rc @@ -37,7 +37,8 @@ fn blagh_init { u=$blagh_uri'index' extraHeaders=$"extraHeaders ^ \ ' -' + +' } if not if(~ $req_path $blagh_uri^index.atom) blagh_setup_feed_handlers atom.tpl 'application/atom+xml' @@ -45,6 +46,9 @@ fn blagh_init { if not if(~ $req_path $blagh_uri^index.rss) blagh_setup_feed_handlers rss20.tpl 'text/xml; charset=utf-8' + if not if(~ $req_path $blagh_uri^feed.json) + blagh_setup_feed_handlers jsonfeed.tpl 'application/json; charset=utf-8' + if not if(~ $req_path $blagh_uri^new_post && ! ~ $#editor_mode 0) { handler_body_main=( tpl_handler `{get_lib_file blagh/new_post.tpl apps/blagh/new_post.tpl} ) if(~ $REQUEST_METHOD POST) { diff --git a/apps/blagh/jsonfeed.tpl b/apps/blagh/jsonfeed.tpl new file mode 100644 index 0000000..fd97ed4 --- /dev/null +++ b/apps/blagh/jsonfeed.tpl @@ -0,0 +1,35 @@ +{ +"version": "https://jsonfeed.org/version/1", +"title": "%($siteTitle%)", +"home_page_url": "%($"base_url%)", +"feed_url": "%($"base_url^$"req_path%)", +"items": [ +%{ +fn statpost { + f = $1 + post_uri=$base_url^`{cleanname `{echo $f | sed -e 's!^'$sitedir'!!'}}^'/' + title=`{read $f/index.md} + #ifs=() { summary=`{cat $f/index.md | crop_text 1024 ... | $formatter } } + ifs=() { summary=`{cat $f/index.md | strip_title_from_md_file | ifs=$difs {$formatter| sed 's/"/\\"/g' | tr -d '\012' } } } +} +%} +% #for(f in `{get_post_list $blagh_root$blagh_dirs}) { +% +% postlist=`{get_post_list $blagh_root$blagh_dirs} +% postcount=0 +% for(f in $postlist) { +% statpost $f + { + "id": "%($post_uri%)", + "url": "%($post_uri%)", + "title": "%($title%)", + "content_html": "%($summary%)" + } +% postcount = `{echo $postcount 1+p | dc} +% if (! ~ $#postlist $postcount) { echo , } +% } +] +} + +% exit +