From b7f33b8d0762df144be77ef24230c5a11e27ac93 Mon Sep 17 00:00:00 2001 From: Uriel Date: Mon, 27 Oct 2008 00:41:23 +0100 Subject: [PATCH] New menu implementation, removes the recursive calls to rc/awk, also makes use of dirfilter more consistent and simplifies some code. Other minnor cleanups. --- bin/werc.rc | 73 +++++++++++++++++++++++++-------------------- lib/sitemap.tpl | 2 +- pub/style/style.css | 6 ++++ 3 files changed, 47 insertions(+), 34 deletions(-) diff --git a/bin/werc.rc b/bin/werc.rc index 34179bf..c164218 100755 --- a/bin/werc.rc +++ b/bin/werc.rc @@ -20,8 +20,9 @@ fn gentitle { echo '

' ^ $"siteTitle ^ ' ' ^ $"siteSubTitle ^ '

' } -# Don't change var name or trailing ';', some dirs change the filter! -dirfilter = '/\/[._]/d; /'^$forbidden_uri_chars^'/d; /\/robots.\txt$/d; /\/sitemap\.txt$/d; s,^\./,,; s,\.md$,,; s,\.html,,; s,\.txt,,; ' +# 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)$/d; /_werc$/d; s,^\./,,; s,\.md$,,; s,\.html,,; s,\.txt,,; ' # To be used from config files fn hide_paths { @@ -30,38 +31,41 @@ fn hide_paths { } # Sidebar -# PERF: menu takes ~30% of werc's runtime, even for top level pages. -# Maybe a combination of du -a/find|sort could let us avoid the recursive awk calls... fn menu { - ls -F $1 | sed $dirfilter | awk -F/ ' - BEGIN { print "" } - # Should add \. to the list of allowed chars in file names, but need to find a way to filter out .txt and so on - /^([a-zA-Z0-9+_\-]+[\/*]?)+$/ && $NF != "index" { - isdir = match($0, "/$") - sub("[*/]$", "") + dirs = ./ + dd = . + for(d in $args) { + dd=$dd^'/'^$d + dirs = ( $dd $dirs ) + } + # Ignore stderr, last item in path might be a file that doesn't exist (eg., foo for foo.md) + ls -F $dirs >[2]/dev/null | sed 's/[@*]$//; '^$dirfilter|sort -u | awk -F/ ' + function p(x, y, s) { + for( i=0; i < x-y; i+=1) + print s + } + /^([a-zA-Z0-9+_\-]+[*\/]?)+$/ { - path = bname = $0 - sub("^(.*/)?([0-9]+_)?", "", bname) + d = "" + if(match($0, "/$")) + d = "/" + sub("/$", "") # Strip trailing / for dirs so NF is consistent + + p(NF, lNF, "") + lNF = NF + + bname = $NF d + path = "/" $0 d gsub("_", " ", bname) - if(isdir) { - bname = bname "/" - path = $0 "/" - } - - if(index(ENVIRON["REQUEST_URI"] "/", "/" path) == 1) { - if(isdir) { - print "
  • » " bname "" - system("rc -c ''menu " path "''") - } else { - print "
  • » " bname "" - } - } else - print "
  • › " bname "" - - print "
  • " - }' + if(index(ENVIRON["REQUEST_URI"] "/", path) == 1) + print "
  • » " bname "" + else + print "
  • › " bname "
  • " + } + END { p(lNF, 0, "") } + ' } fn gensidebar { @@ -116,9 +120,10 @@ fn txt_handler { fn dir_listing_handler { d = `{basename -d $1} - echo '

    ' `{echo $d|sed -e 's,.*//,,g' -e 's,/$,,' -e 's,/, / ,g' } '

    ' - echo '