Tested now.
>From 309ffdb318e67014b8565335cc1d95e4ff5d506c Mon Sep 17 00:00:00 2001 From: Strake <strake...@gmail.com> Date: Wed, 3 Jul 2013 07:26:16 -0500 Subject: [PATCH 1/2] bin/handlers: roll up repeated code --- bin/handlers.rc | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/bin/handlers.rc b/bin/handlers.rc index cca6495..2055ed4 100644 --- a/bin/handlers.rc +++ b/bin/handlers.rc @@ -54,6 +54,10 @@ fn man_handler { echo '</pre>' } +fn 1_handler { + man_handler $* +} + fn dir_listing_handler { d=`{basename -d $1} if(~ $#d 0) @@ -65,19 +69,12 @@ fn dir_listing_handler { } fn setup_handlers { - if(test -f $local_path.md) { - local_file=$local_path.md - handler_body_main=(md_handler $local_file) - } - if not if(test -f $local_path.1) { - local_file=$local_path.1 - handler_body_main=(man_handler $local_file) - } - if not if(test -f $local_path.tpl) { - local_file=$local_path.tpl - handler_body_main=(tpl_handler $local_file) + local_file=() + for(suffix in md 1 tpl) if(test -f $local_path.$suffix) { + local_file=$local_path.$suffix + handler_body_main=($suffix^_handler $local_file) } - if not if(test -f tpl^$req_path^.tpl) + if(~ $#local_file 0 && test -f tpl^$req_path^.tpl) handler_body_main=(tpl_handler tpl^$req_path^.tpl) if(! ~ $#handler_body_main 0) { } # We are done -- 1.7.11.1 >From e932acfd42a5b8f0d7e7d467916cc00a8ccf962b Mon Sep 17 00:00:00 2001 From: Strake <strake...@gmail.com> Date: Sun, 18 May 2003 15:11:04 -0500 Subject: [PATCH 2/2] factorize out suffixes --- bin/handlers.rc | 6 ++++-- bin/werc.rc | 12 +++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/bin/handlers.rc b/bin/handlers.rc index 2055ed4..e1e246d 100644 --- a/bin/handlers.rc +++ b/bin/handlers.rc @@ -1,5 +1,7 @@ # Werc builtin handlers +suffixes=(md 1 tpl) + fn nav_tree { echo '<ul>' if(! ~ $#menuTitle 0) { @@ -12,7 +14,7 @@ fn nav_tree { # /./ to deal with p9p's ls failure to follow dir symlinks otherwise ls -F $sitedir/./$req_paths_list >[2]/dev/null \ | { - sed $dirfilter'/\/[^_.\/][^\/]*(\.(md|1)|\/)$/!d; s!^'$sitedir'!!; '$dirclean + sed $dirfilter'/\/[^_.\/][^\/]*(\.'^$suffix_alternation^'|\/)$/!d; s!^'$sitedir'!!; '$dirclean if(! ~ $#synth_paths 0) echo $synth_paths | tr ' ' $NEW_LINE } | sort -u | awk -F/ ' function p(x, y, s) { for(i=0; i < x-y; i+=1) print s } @@ -70,7 +72,7 @@ fn dir_listing_handler { fn setup_handlers { local_file=() - for(suffix in md 1 tpl) if(test -f $local_path.$suffix) { + for(suffix in $suffixes) if(test -f $local_path.$suffix) { local_file=$local_path.$suffix handler_body_main=($suffix^_handler $local_file) } diff --git a/bin/werc.rc b/bin/werc.rc index 01f4714..5fa22c3 100755 --- a/bin/werc.rc +++ b/bin/werc.rc @@ -7,14 +7,16 @@ cd .. forbidden_uri_chars='[^a-zA-Z0-9_+\-\/\.,:]' difs=$ifs # Used to restore default ifs when needed -# Expected input: ls -F style, $sitedir/path/to/files/ -# <ls -F+x><symlink hack><Useless?><hiden files > -dirfilter='s/\*$//; s,/+\./+,/,g; s,^\./,,; /\/[._][^\/]/d; /'$forbidden_uri_chars'/d; /\/sitemap\.xml$/d; /\/index\.(md|tpl)$/d; /\/(robots|sitemap)\.txt$/d; /_werc\/?$/d; ' -dirclean=' s/\.(md|1)$//; ' - # Careful, the proper p9p path might not be set until initrc.local is sourced path=(. $PLAN9/bin ./bin /bin /usr/bin) +suffix_alternation='('^`{echo $"suffixes | tr ' ' '|'}^')' + +# Expected input: ls -F style, $sitedir/path/to/files/ +# <ls -F+x><symlink hack><Useless?><hiden files > +dirfilter='s/\*$//; s,/+\./+,/,g; s,^\./,,; /\/[._][^\/]/d; /'$forbidden_uri_chars'/d; /\/sitemap\.xml$/d; /\/index(\.'^$suffix_alternation^')+$/d; /\/(robots|sitemap)\.txt$/d; /_werc\/?$/d; ' +dirclean=' s/\.'^$suffix_alternation^'$//; ' + http_content_type='text/html' ll_add handlers_bar_left nav_tree werc_root=`{pwd} -- 1.7.11.1