changelog shortlog tags branches changeset files revisions annotate raw help

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

changeset 316: a8c8620f7ff7
parent: 73bc0b90cf58
child: dcc289b14b9f
author: uriel@engel.se.cat-v.org
date: Mon, 12 Jan 2009 02:07:31 +0100
permissions: -rw-r--r--
description: Various small cleanups: remove unused code, clarity and reliability fixes here and here, move code to more appropriate locations, improve some comments.
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  if(~ $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]/)
13  status='Use default handler'
14 
15  if not if(~ $req_path */index */) {
16  handler_body_main=blagh_body
17  u=$blagh_uri'index'
18  extraHeaders=$"extraHeaders ^ \
19  '<link rel="alternate" type="application/rss+xml" title="RSS" href="'$"u'.rss" />
20 <link rel="alternate" type="application/atom+xml" title="ATOM" href="'$"u'.atom" />'
21 
22  }
23  if not {
24  response_format=raw
25  if(~ $req_path */index.atom)
26  master_template=_apps/blagh/atom.tpl
27  if not if(~ $req_path */index.rss)
28  master_template=_apps/blagh/rss20.tpl
29  }
30  }
31 }
32 
33 fn blagh_body {
34  for(p in `{get_post_list $blagh_root^$blaghDirs}) {
35  l=`{echo -n $p|sed 's!'$sitedir^$req_path'!!'}
36  sed '1s!.*![&]('$l')!' < $p/index.md | $formatter
37  }
38 }
39 
40 fn get_post_list {
41  # the /./->/|/ are added so we can sort -t| and order only the file name
42  # NOTE: this breaks if any path element in blogDirs contain '/./' or '|'
43  ls -F $*^/./[0-9][0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9]/ >[2]/dev/null | sed -n 's,/\./,/|/,; /\/$/p' | sort -r '-t|' +1 | sed 's,/+\|/+,/,'
44 }
45 
46 
47 fn make_blog_post {
48  if(! ~ 0 $#1 $#2 $#3) {
49  bdir=$1
50  btitle=$2
51  btext=$3
52  date=`{/bin/date +%F}
53 
54  n=1
55  for(f in $bdir^$date^'-'*) {
56  i=`{echo -n $f | sed -n 's,^.*/'$date'-([0-9]+)_.*,\1,p'|tr -d $NEW_LINE}
57  if(! ~ $#i 0 && test $i -ge $n)
58  n=`{hoc -e $i'+1'}
59  }
60  btitle=`{echo -n $"btitle | sed 's/[ ]+/_/g; 1q'}
61 
62  echo $btext > $bdir^'/'^$"date^'-'^$"n^_$"btitle.md
63  }
64  if not
65  status=Missing blog post arguments $"1 $"2 $"3
66 }
67