ref: cb525c9140db3f74e1edb78eb6ee2249c97dc1ee
parent: a9c977708a758653bea09ecb976262371d891496
author: uriel <[email protected]>
date: Sun Oct 26 20:41:23 EDT 2008
New menu implementation, removes the recursive calls to rc/awk, also makes use of dirfilter more consistent and simplifies some code. Other minnor cleanups.
--- a/bin/werc.rc
+++ b/bin/werc.rc
@@ -20,8 +20,9 @@
echo '<h1 class="headerTitle"><a href="/">' ^ $"siteTitle ^ ' <span id="headerSubTitle">' ^ $"siteSubTitle ^ '</span></a></h1>'
}
-# 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 @@
}
# 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 "<ul class=\"side-bar\">" }
- END { print "</ul>" }
- # 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)
- gsub("_", " ", bname)
+ d = ""
+ if(match($0, "/$"))
+ d = "/"
+ sub("/$", "") # Strip trailing / for dirs so NF is consistent
- if(isdir) {
- bname = bname "/"
- path = $0 "/"
- }
+ p(NF, lNF, "<ul class=\"side-bar\">")
+ p(lNF, NF, "</ul>")
+ lNF = NF
- if(index(ENVIRON["REQUEST_URI"] "/", "/" path) == 1) {
- if(isdir) {
- print "<li><a href=\"/" path "\" class=\"thisPage\">»<i> " bname "</i></a>"
- system("rc -c ''menu " path "''")
- } else {
- print "<li><a href=\"/" path "\" class=\"thisPage\">»<i> " bname "</i></a>"
- }
- } else
- print "<li><a href=\"/" path "\">› " bname "</a>"
+ bname = $NF d
+ path = "/" $0 d
+ gsub("_", " ", bname)
- print "</li>"
- }'
+ if(index(ENVIRON["REQUEST_URI"] "/", path) == 1)
+ print "<li><a href=\"" path "\" class=\"thisPage\">»<i> " bname "</i></a>"
+ else
+ print "<li><a href=\"" path "\">› " bname "</a></li>"
+ }
+ END { p(lNF, 0, "</ul>") }
+ '
}
fn gensidebar {
@@ -116,9 +120,10 @@
fn dir_listing_handler {
d = `{basename -d $1}
- echo '<h1 style="text-transform: capitalize;">' `{echo $d|sed -e 's,.*//,,g' -e 's,/$,,' -e 's,/, / ,g' } '</h1>'
- echo '<ul style="text-transform: capitalize;">'
- ls -F $d | sed -e $dirfilter' s,^'$sitedir'/.*/([^$].*),<li><a href="\1">\1</a></li>,' # XXX I'm not sure what the [^$] does there
+ dt = `{echo $d|sed -e 's,.*//,,g' -e 's,/$,,' -e 's,/, / ,g'}
+ echo '<h1 class="dir-list-head">'^$dt^'</h1> <ul class="dir-list">'
+ # XXX I'm not sure what the [^$] does there
+ ls -F $d | sed -e $dirfilter' s,^'$sitedir'/.*/([^$].*),<li><a href="\1">\1</a></li>,'
echo '</ul>'
}
@@ -310,6 +315,8 @@
}
select_handler
+
+dprint $handler
# Template/body selection
master_template= `{get_lib_file $master_template}
--- a/lib/sitemap.tpl
+++ b/lib/sitemap.tpl
@@ -25,7 +25,7 @@
if(! ~ $#redirectPermanent 1)
{
- for ( i in `{ ls -d $d/*/ $d/*.md $d/*.html $d/*.txt >[2]/dev/null |sed $dirfilter^'/index$/d;' } ) {
+ for ( i in `{ ls -d $d/*/ $d/*.md $d/*.html $d/*.txt >[2]/dev/null |sed $dirfilter} ) {
desc = ''
if (test -f $i.md) {
desc = `{ getMdDesc $i.md }
--- a/pub/style/style.css
+++ b/pub/style/style.css
@@ -363,3 +363,9 @@
border-left: 1px solid blue;
font-style: italic;
}
+
+/* PAGE/HANDLER SPECIFIC */
+h1.dir-list-head, ul.dir-list {
+ text-transform: capitalize;
+ font-weight: bold;
+}