changelog shortlog tags branches changeset files revisions annotate raw help

Mercurial > hg > werc / apps/blagh/app.rc

changeset 341: 410b2c763e82
parent: dcc289b14b9f
child: bc931d0422f4
author: uriel@soma
date: Tue, 20 Jan 2009 09:06:28 +0000
permissions: -rw-r--r--
description: Fix display of individual blog posts.
1 fn blagh_init {
2  if(~ $#blaghDirs 0 && ~ $local_path */[bB]log/index*)
3  blaghDirs=( . )
4 
5  # Should not match sub-dirs!
6  if(! ~ $#blaghDirs 0) {
7  # && test -d / `{echo '-a -d '^$req_path^$blaghDirs}
8  blagh_uri=`{echo $req_path|sed 's/index(\.(atom|rss))?$//'}
9  blagh_url=$base_uri^$blagh_root_path
10  blagh_root=$sitedir^$blagh_uri
11 
12  # XXX This is a hideous hack, blogs in dirs that match the number patern wont work, and dirs inside posts (eg., comments) wont work either.
13  # The problem is how to find out the 'root' of this blog, blaghDirs is useless for that.
14  if(~ $req_path */ && ! ~ $req_path */[0-9][0-9][0-9][0-9]/ */[0-9][0-9][0-9][0-9]/[0-9][0-9]/ */[0-9][0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9]/*) {
15  handler_body_main=blagh_body
16  u=$blagh_uri'index'
17  extraHeaders=$"extraHeaders ^ \
18  '<link rel="alternate" type="application/rss+xml" title="RSS" href="'$"u'.rss" />
19 <link rel="alternate" type="application/atom+xml" title="ATOM" href="'$"u'.atom" />'
20 
21  }
22  if not if(~ $req_path */index.atom)
23  blagh_setup_feed_handlers atom.tpl
24  if not if(~ $req_path */index.rss)
25  blagh_setup_feed_handlers rss20.tpl
26  }
27 }
28 
29 fn blagh_setup_feed_handlers {
30  handler_body_main=NOT_USED_by_blagh_feeds
31  res_tail=()
32  master_template=_apps/blagh/$1
33 }
34 
35 fn blagh_body {
36  for(p in `{get_post_list $blagh_root^$blaghDirs}) {
37  l=`{echo -n $p|sed 's!'$sitedir^$req_path'!!'}
38  sed '1s!.*![&]('$l')!' < $p/index.md | $formatter
39  }
40 }
41 
42 fn get_post_list {
43  # the /./->/|/ are added so we can sort -t| and order only the file name
44  # NOTE: this breaks if any path element in blogDirs contain '/./' or '|'
45  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 's,/+\|/+,/,'
46 }
47 
48 
49 fn make_blog_post {
50  if(! ~ 0 $#1 $#2 $#3) {
51  bdir=$1
52  btitle=$2
53  btext=$3
54  date=`{/bin/date +%F}
55 
56  n=1
57  for(f in $bdir^$date^'-'*) {
58  i=`{echo -n $f | sed -n 's,^.*/'$date'-([0-9]+)_.*,\1,p'|tr -d $NEW_LINE}
59  if(! ~ $#i 0 && test $i -ge $n)
60  n=`{hoc -e $i'+1'}
61  }
62  btitle=`{echo -n $"btitle | sed 's/[ ]+/_/g; 1q'}
63 
64  echo $btext > $bdir^'/'^$"date^'-'^$"n^_$"btitle.md
65  }
66  if not
67  status=Missing blog post arguments $"1 $"2 $"3
68 }
69