shithub: werc

Download patch

ref: 3796828c73dc502b836518b73ef6d0b9b764dfe5
parent: 6f531df8ef6eeba985acd699ba1a443b2df8b308
author: khm <[email protected]>
date: Sun May 24 22:09:41 EDT 2020

blagh: jsonfeed support

--- a/apps/blagh/app.rc
+++ b/apps/blagh/app.rc
@@ -37,7 +37,8 @@
             u=$blagh_uri'index'
             extraHeaders=$"extraHeaders ^ \
 '<link rel="alternate" type="application/atom+xml" title="ATOM" href="'$"u'.atom" />
-<link rel="alternate" type="application/rss+xml" title="RSS" href="'$"u'.rss" />'
+<link rel="alternate" type="application/rss+xml" title="RSS" href="'$"u'.rss" />
+<link rel="alternate" type="application/json" title="JSON" href="'$"blagh_uri'feed.json" />'
         }
         if not if(~ $req_path $blagh_uri^index.atom)
             blagh_setup_feed_handlers atom.tpl 'application/atom+xml'
@@ -44,6 +45,9 @@
 
         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} )
--- /dev/null
+++ b/apps/blagh/jsonfeed.tpl
@@ -1,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 
+