shithub: werc

Download patch

ref: 6d6caadfc51f741f10fc8ffc52e4b3bd3c5fd419
parent: fe8bbc2cadc30880bca9743f0de753152b980a7e
author: uriel <[email protected]>
date: Fri Dec 19 21:57:01 EST 2008

Simplify dir listing handler, and deal better with corner cases.

--- a/bin/werc.rc
+++ b/bin/werc.rc
@@ -21,7 +21,7 @@
 
 # Don't change var name or trailing ';', dirfilter might be changed from _werc/config!
 # TODO: Specify the canonical path input format handled by dirfilter
-dirfilter = '/\/[._]/d; /'^$forbidden_uri_chars^'/d; /\/(robots\.txt|sitemap\.txt|index\.(md|html|txt|tpl))$/d; /_werc\/?$/d; s,^\./,,; s,\.(md|html|txt)$,,; '
+dirfilter = 's,/\./,/,g; /\/[._]/d; /'^$forbidden_uri_chars^'/d; /\/(robots\.txt|sitemap\.txt|index\.(md|html|txt|tpl))$/d; /_werc\/?$/d; s,^\./,,; s,\.(md|html|txt)$,,; '
 
 # To be used from config files
 fn hide_paths {
@@ -100,9 +100,9 @@
 
 fn dir_listing_handler {
     d = `{basename -d $1}
-    dt = `{echo $d|sed -e 's,.*//,,g' -e 's,/$,,' -e 's,/, / ,g'} 
-    echo '<h1 class="dir-list-head">'^$"dt^'</h1> <ul class="dir-list">'
-    ls -F $d | sed -e 's/\*$//; '^$dirfilter' s,^'$sitedir'/.*/([^/]+/?)$,<li><a href="\1">\1</a></li>,'
+    echo $d|sed 's,.*//,,g; s,/$,,; s,/, / ,g; s,.*,<h1 class="dir-list-head">&</h1> <ul class="dir-list">,'
+    # Symlinks suck: '/.' forces ls to list the linked dir if $d is a symlink.
+    ls -F $d/. | sed -e 's/\*$//; '^$dirfilter' s,.*/([^/]+/?)$,<li><a href="\1">\1</a></li>,'
     echo '</ul>'
 }