blagh: jsonfeed support

This commit is contained in:
khm 2020-05-25 02:09:41 -07:00
parent 972f1ba6f1
commit d425a1b19c
2 changed files with 40 additions and 1 deletions

View File

@ -37,7 +37,8 @@ fn blagh_init {
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'
@ -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) {

35
apps/blagh/jsonfeed.tpl Normal file
View File

@ -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