commit 21008b0c81440330af55f0de1486be8642ce1efb
parent 41184870de5a234815dc74f418468f0d60c18cdf
Author: uriel@soma <unknown>
Date: Fri, 13 Mar 2009 10:51:07 +0000
More wman updates, new search functionality and handle better corner cases.
Diffstat:
3 files changed, 23 insertions(+), 6 deletions(-)
diff --git a/apps/wman/app.rc b/apps/wman/app.rc
@@ -6,6 +6,12 @@ fn conf_enable_wman {
conf_enable_app wman
}
+wman_junk_filter='/(\/(INDEX|\.cvsignore)|\.9p|\.html)$/d; s!/man([0-9]+/[^/]+)$!/\1!; '
+fn wman_ls_pages {
+ ls $* \
+ | sed $dirfilter^$wman_junk_filter^' s/\.([0-9]|9p)$//; s!/0intro$!/intro!' \
+ | sort -u
+}
fn wman_init {
ifs=$ifs^'/' { p=`{echo $req_path | sed 's!^'^$wman_base_uri^'!!'} }
wman_cat=$p(1)
@@ -18,7 +24,7 @@ fn wman_init {
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' \
+ | sed -e $wman_junk_filter -e 's!.*/([^/]+)/[^/]+$!\1!; /[0-9]+/!d' \
| sort -un}
synth_paths=($wman_base_uri$wman_cat_list'/')
@@ -27,21 +33,31 @@ fn wman_init {
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\-\.]+$')
+ 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'}
}
+
+ # Search
+ ll_add handlers_body_head tpl_handler apps/wman/search.tpl
+ s=`{echo $post_arg_wman_search | sed 's/[^a-zA-Z0-9\-\.]+//g; s/\.+/./g; 1q'}
+ ifs='' { wman_search_results=`{wman_ls_pages $wman_man_path/*/*^$s^*} }
+ if(! ~ $"post_arg_go '' && ~ `{echo -n $wman_search_results|wc -l} 1)
+ post_redirect $wman_base_uri^`{echo $wman_search_results|awk -F/ '{print $(NF-1)"/"$NF}'}
+
}
-fn wman_get_section_desc { sed '1,2d; s!intro \\- introduction to !!; 3q;' < $wman_man_path/^$"wman_cp^$1/0intro* }
+fn wman_get_section_desc {
+ cat $wman_man_path/^$"wman_cp^$1/0intro* >[2]/dev/null| sed '1,2d; s!intro \\- introduction to !!; 3q;'
+}
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' \
+ | sed 's!([\.\-a-zA-Z0-9]+)\(('^`{echo $wman_cat_list|tr ' ' '|'}^')\)!<a href="../\2/\1">&</a>!g' \
| awk '/^$/ {if(n != 1) print; n=1; next} /./ {n=0; print}'
}
diff --git a/apps/wman/page_list.tpl b/apps/wman/page_list.tpl
@@ -3,8 +3,7 @@
<ul style="float:left">
%{
-ls -F $wman_cat_path \
- | sed $dirfilter^' /(\/INDEX|\.html)$/d; s/\.([0-9]|9p)$//; s!/0intro$!/intro!' \
+wman_ls_pages $wman_cat_path \
| awk -F/ '{ print "<li><a href=\""$(NF)"\">"$(NF)"</a></li>" }
NR%28 == 0 { print "</ul><ul style=\"float: left\">" }'
%}
diff --git a/apps/wman/section_list.tpl b/apps/wman/section_list.tpl
@@ -4,6 +4,8 @@
% for(c in $wman_cat_list) {
<li><a href="%($c%)/"><b>Section: %($c%)</b></a>
% wman_get_section_desc $c
+% if(~ $status '' '|')
+% echo '(<a href="'$c'/intro">intro</a>)'
</li>
% }
</ul>