werc-1.5.0-tweaks

Tweaks for the werc website builder created by the mad architect Uriel
Log | Files | Refs | README

app.rc (3256B)


      1 fn conf_enable_wman {
      2     wman_tmac=an
      3     wman_base_uri=$conf_wd
      4     wman_man_path=$*
      5     if(~ $#wman_man_path 0)
      6         wman_man_path=$wman_base_uri
      7     conf_enable_app wman
      8 }
      9 
     10 wman_junk_filter='/(\/(INDEX|\.cvsignore|_.*)|\.9p|\.html)$/d; s!/man([0-9]+/[^/]+)$!/\1!; '
     11 fn wman_ls_pages {
     12     ls $* \
     13         | sed $dirfilter^$wman_junk_filter^' s/\.([0-9]|9p)$//; s!/0intro$!/intro!' \
     14         | sort -u
     15 }
     16 fn wman_init {
     17     ifs=$ifs^'/' { p=`{echo $req_path | sed 's!^'^$wman_base_uri^'!!'} }
     18     wman_cat=$p(1)
     19     wman_page=$p(2)
     20     if(~ $#wman_unix_mode 1) {
     21         wman_cp='man'
     22         wman_pe=.^$"wman_cat
     23     }
     24 
     25     if(! ~ $"wman_cat '') {
     26         wman_cat_path=$wman_man_path^/^$"wman_cp^$p(1)
     27         if(! ~ $"wman_page '') {
     28             wman_page_file=$wman_page^$"wman_pe
     29             # Hack to handle 0intro files.
     30             if(~ $wman_page intro && test -f $wman_cat_path^/0^$"wman_page_file)
     31                  wman_page_file=0^$"wman_page_file
     32             wman_page_file=$wman_cat_path^/^$"wman_page_file
     33             x=`{echo $"req_path|sed 's%.*/([^/]+)/'$"wman_cat'/'^$"wman_page^'%\1%; s%_% %g'}
     34             pageTitle=$wman_page' page from Section '$wman_cat' of the '^$"x' manual'
     35         }
     36     }
     37 
     38     wman_cat_list=`{ls -F $wman_man_path/*/  \
     39         | sed -e $wman_junk_filter -e 's!.*/([^/]+)/[^/]+$!\1!; /[0-9]+/!d' \
     40         | sort -un}
     41 
     42     synth_paths=($wman_base_uri$wman_cat_list'/')
     43 
     44     if(~ $req_path $wman_base_uri && ~ $"handler_body_main '')
     45        handler_body_main=(tpl_handler apps/wman/section_list.tpl)
     46     if not if(~ $req_path $wman_base_uri^*) {
     47         #^*/[a-z0-9]*[a-z]* $wman_base_uri^*/*[a-z]*[a-z0-9] $wman_base_uri^*/[a-z])
     48         if(echo $req_path | grep -s '^'^$wman_base_uri^'/*[0-9]+/[0-9a-z\-\+\.]+$')
     49            if(test -f $wman_page_file) # Check for 404
     50                handler_body_main=(tpl_handler apps/wman/man_page.tpl)
     51         if not if(~ $req_path $wman_base_uri^*/)
     52            handler_body_main=(tpl_handler apps/wman/page_list.tpl)
     53         if not if(~ $p(2) [A-Z]* [0-9][A-Z]*) # Correct badly capitalized links
     54             perm_redirect $wman_base_uri^$p(1)^/^`{echo $p(2) |tr 'A-Z' 'a-z'}
     55     }
     56 
     57     # Search
     58     ll_add handlers_body_head tpl_handler apps/wman/search.tpl
     59     if(! ~ $"post_arg_wman_search '') {
     60         s=`{echo $post_arg_wman_search | sed 's/[^a-zA-Z0-9\-\.]+//g; s/\.+/./g; 1q'}
     61         ifs='' { wman_search_results=`{wman_ls_pages $wman_man_path/*/*^$"s^*} }
     62         if(! ~ $"post_arg_go '' && ~ `{echo -n $wman_search_results|wc -l} 1)
     63             post_redirect $wman_base_uri^`{echo $wman_search_results|awk -F/ '{print $(NF-1)"/"$NF}'}
     64     }
     65 
     66 }
     67 
     68 fn wman_get_section_desc { 
     69     cat $wman_man_path/^$"wman_cp^$1/0intro* >[2]/dev/null| sed '1,2d; s!intro \\- [Ii]ntroduction to !!; 3q;' 
     70 }
     71 
     72 fn wman_page_gen {
     73     #troff -manhtml $1| troff2html -t 'Plan 9 from User Space'
     74     troff -N -m$wman_tmac $1 | wman_out_filter
     75 }
     76 
     77 fn wman_out_filter {
     78     wman_default_out_filter
     79 }
     80 
     81 fn wman_default_out_filter {
     82 	# col -x syntax is the same for UNIX and Plan 9.
     83     escape_html \
     84     | sed 's!([\.\-a-zA-Z0-9]+)\(('^`{echo $wman_cat_list|tr ' ' '|'}^')\)!<a href="../\2/\1">&</a>!g' \
     85     | awk '/^$/ {if(n != 1) print; n=1; next} /./ {n=0; print}' \
     86     | col -x
     87 }
     88 
     89