app.rc (6684B)
1 fn conf_enable_blog { 2 blagh_uri=$conf_wd 3 blagh_dirs=$* 4 if(~ $#blagh_dirs 0) 5 blagh_dirs=( . ) 6 conf_enable_app blagh 7 8 if(~ $"conf_blog_editors '') 9 conf_blog_editors=blog-editors 10 11 if(~ $"conf_max_posts_per_page '') 12 conf_max_posts_per_page=32 13 } 14 15 fn blagh_init { 16 if(~ $#blagh_dirs 0 && ~ $req_path */[bB]log/*) { 17 blagh_uri=`{echo $req_path | sed 's,(/[bB]log/).*,\1,'} 18 blagh_dirs=( . ) 19 } 20 21 # Should not match sub-dirs! 22 if(! ~ $#blagh_dirs 0) { 23 # && test -d / `{echo '-a -d '^$blagh_root^$blagh_dirs} 24 blagh_url=$base_url^$blagh_uri 25 blagh_root=$sitedir^$blagh_uri 26 if(check_user $conf_blog_editors) { 27 editor_mode=on 28 if(~ $"post_arg_date '') 29 post_date=`{datei|sed 's,-,/,g'} 30 if not 31 post_date=$post_arg_date 32 ll_add handlers_bar_left echo '<a href="'$blagh_uri'new_post">Make a new post</a>' 33 } 34 35 if(~ $req_path $blagh_uri) { 36 handler_body_main=blagh_body 37 u=$blagh_uri'index' 38 extraHeaders=$"extraHeaders ^ \ 39 '<link rel="alternate" type="application/atom+xml" title="ATOM" href="'$"u'.atom" /> 40 <link rel="alternate" type="application/rss+xml" title="RSS" href="'$"u'.rss" /> 41 <link rel="alternate" type="application/json" title="JSON" href="'$"blagh_uri'feed.json" />' 42 } 43 if not if(~ $req_path $blagh_uri^index.atom) 44 blagh_setup_feed_handlers atom.tpl 'application/atom+xml' 45 46 if not if(~ $req_path $blagh_uri^index.rss) 47 blagh_setup_feed_handlers rss20.tpl 'text/xml; charset=utf-8' 48 49 if not if(~ $req_path $blagh_uri^feed.json) 50 blagh_setup_feed_handlers jsonfeed.tpl 'application/json; charset=utf-8' 51 52 if not if(~ $req_path $blagh_uri^new_post && ! ~ $#editor_mode 0) { 53 handler_body_main=( tpl_handler `{get_lib_file blagh/new_post.tpl apps/blagh/new_post.tpl} ) 54 if(~ $REQUEST_METHOD POST) { 55 if(mkbpost $"post_arg_body $"post_date $"post_arg_title $post_arg_id) 56 post_redirect $blagh_uri 57 if not 58 notify_errors=$status 59 } 60 } 61 62 if not if (~ $req_path $blagh_uri^*){ 63 echo 1 64 } 65 66 } 67 } 68 69 fn blagh_setup_feed_handlers { 70 handler_body_main=NOT_USED_by_blagh_feeds 71 res_tail=() 72 http_content_type=$2 73 headers=() 74 master_template=apps/blagh/$1 # Should we allow tempalte override? 75 } 76 77 fn blagh_body { 78 if (! ~ $"blogTitle '') 79 echo '<h2>'$"blogTitle'</h2>' 80 81 # Direct links to feeds are disabled because they are not very useful, add clutter and might waste pagerank. 82 # An user can add this on their own using handlers_body_head anyway. 83 if (! ~ $base_url 'https://gartzea.com') 84 # echo '<p style="font-size: 25px;"><a href="index.rss">RSS Feed</a>, <a href="../.newsletter">subscribe per email</a>, <a href="../sitemap">all content</a></p>' 85 echo '<p style="font-size: 25px;"><a href="index.rss">RSS Feed</a>, <a href="../sitemap">all content</a></p>' 86 if (~ $base_url 'https://gartzea.com') 87 echo '<p><a href="index.rss">RSS</a>, <a href="../gaceta">gaceta</a>, <a href="../sitemap">todo</a></p>' 88 # echo "$base_url" 89 # |<a href="index.atom">Atom Feed</a></div>' 90 91 # Markdown posts 92 # XXX Not sure why this fixes issues with blog setup, probably bug in fltr_cache! 93 for(p in `{get_post_list $blagh_root^$blagh_dirs}) { 94 l=`{echo -n $p|sed 's!'$sitedir^'/?(.*)([0-9][0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9])(/[^/]+/)!\2 /\1\2\3!'} 95 sed '1s!.*^') ('^$l(1)^')!' < $p/index.md | head -n 10 96 echo 97 echo '<p style="text-align: left; margin-right: 10%; font-size: 28px;"><a style="text-decoration: none;" href="'^$l(2)^'"><b>→</b> Ꙭ ...</a></p>' 98 # ⇒ 99 # ➡ 100 # https://www.smashingmagazine.com/2009/07/designing-read-more-and-continue-reading-links/ 101 # cat $p/index.md | sed '1s!.*^') ('^$l(1)^')!' | sed -n '/^.\{15\}/p' | echo 102 echo # Needed extra \n so markdown doesn't mess up the formatting, probably can be done in sed. 103 echo # 104 } | head -n 12 | $formatter | sed 's/h[2-9]/i/g'| sed 's/h1/h3/g' 105 # HTML posts 106 for(p in `{get_post_list $blagh_root^$blagh_dirs}) { 107 cat < $p/index.html 108 echo # Needed extra \n so markdown doesn't mess up the formatting, probably can be done in sed. 109 } | sed 's/h[2-9]/i/g' | sed 's/h1/h3/g' | head -n 5 110 # XXX BUG! Markdown [references] break because multiple markdown documents are merged. Should format each blog post independently. 111 # TODO: use fltr_cache directly, that can fix the previous bug plus provide a perf boost by caching title generation. 112 echo '<p><a href="../sitemap">More content</a></p>' 113 } 114 115 fn get_post_list { 116 # /./->/|/ done to sort -t| and order by date 117 # Note: $paths in blagh_dirs should not contain '/./' or '|' 118 ls -F $*^/./[0-9][0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9]/ >[2]/dev/null | sed -n '/'^$forbidden_uri_chars^'/d; s,/\./,/|/,; /\/$/p' | sort -r '-t|' +1 | sed -e 's,/+\|/+,/,' -e $conf_max_posts_per_page^'q' 119 } 120 121 fn mkbpost { 122 bptext=$1 123 bpdate=$2 124 bptitle=$3 125 bpid=$4 126 _status=() 127 if(~ $"bptext '') 128 _status=($_status 'You need to provide a post body.') 129 if(! ~ $"bpdate [0-9][0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9]) 130 _status=($_status 'Invalid date: '''^$"bpdate^'''') # XXX Should make semantic check. 131 132 if(~ $#_status 0) { 133 umask 002 # Let group write 134 if(! ~ $"bpid '') 135 bpid=`{echo -n '-'^$bpid | sed 's/'$forbidden_uri_chars'+/_/g; 1q'} 136 137 ddir=$blagh_root^$bpdate^'/' 138 n=`{ls $ddir >[2]/dev/null |wc -l} 139 140 mkdir -p $ddir/$"n^$"bpid/ 141 { 142 if(! ~ $"bptitle '') { 143 echo $bptitle 144 echo '=========================================' 145 } 146 # TODO: Enable metadata 147 #echo '* Posted:' `{date} 148 #if(! ~ $#logged_user 0) 149 # echo '* Author: '$logged_user 150 echo 151 echo $bptext 152 }> $ddir/$"n^$"bpid/index.md 153 154 # Experimental support for http://pubsubhubbub.googlecode.com/ 155 if(! ~ $"conf_blog_pubsubdub_hub '') { 156 ifs='' { p=`{echo $req_url|sed 's/new_post$/index.atom/'|url_encode } } 157 dprint hget -p 'hub.mode=publish&hub.url='^$"p $conf_blog_pubsubdub_hub 158 hget -d -h -p 'hub.mode=publish&hub.url='^$"p $conf_blog_pubsubdub_hub >[1=2] & 159 } 160 } 161 status=$_status 162 } 163 164 fn strip_title_from_md_file { 165 sed '1N; /^.*\n===*$/N; /.*\n===*\n$/d' 166 }