werc/apps/wman/app.rc

48 lines
1.7 KiB
Plaintext

fn conf_enable_wman {
wman_base_uri=$conf_wd
wman_man_path=$*
if(~ $#wman_man_path 0)
wman_man_path=$wman_base_uri
conf_enable_app wman
}
fn wman_init {
ifs=$ifs^'/' { p=`{echo $req_path | sed 's!^'^$wman_base_uri^'!!'} }
wman_cat=$p(1)
wman_page=$p(2)
if(~ $#wman_unix_mode 1) {
wman_cp='man'
wman_pe=.^$"wman_cat
}
if(! ~ $"wman_cat '')
wman_cat_path=$wman_man_path^/^$"wman_cp^$p(1)
wman_cat_list=`{ls -F $wman_man_path/*/ \
| sed '/\/(index\.html|INDEX|\.cvsignore)$/d; s!.*/'^$"wman_cp^'([^/]+)/[^/]+$!\1!; /[0-9]+/!d' \
| sort -un}
synth_paths=($wman_base_uri$wman_cat_list'/')
if(~ $req_path $wman_base_uri)
handler_body_main=(tpl_handler apps/wman/section_list.tpl)
if not if(~ $req_path $wman_base_uri^*) {
#^*/[a-z0-9]*[a-z]* $wman_base_uri^*/*[a-z]*[a-z0-9] $wman_base_uri^*/[a-z])
if(echo $req_path | grep -s '^'^$wman_base_uri^'/*[0-9]+/[0-9a-z\-\.]+$')
handler_body_main=(tpl_handler apps/wman/man_page.tpl)
if not if(~ $req_path $wman_base_uri^*/)
handler_body_main=(tpl_handler apps/wman/page_list.tpl)
if not if(~ $p(2) [A-Z]* [0-9][A-Z]*) # Correct badly capitalized links
perm_redirect $wman_base_uri/^$p(1)^/^`{echo $p(2) |tr 'A-Z' 'a-z'}
}
}
fn wman_get_section_desc { sed '1,2d; s!intro \\- introduction to !!; 3q;' < $wman_man_path/^$"wman_cp^$1/0intro* }
fn wman_page_gen {
#troff -manhtml $1| troff2html -t 'Plan 9 from User Space'
nroff -man $1 \
| escape_html \
| sed 's!([\.\-a-zA-Z0-9]+)\(([1-9]|10)\)!<a href="../\2/\1">&</a>!g' \
| awk '/^$/ {if(n != 1) print; n=1; next} /./ {n=0; print}'
}