New menu implementation, removes the recursive calls to rc/awk, also makes use of dirfilter more consistent and simplifies some code.
Other minnor cleanups.
This commit is contained in:
parent
bdf9922a24
commit
b7f33b8d07
3 changed files with 47 additions and 34 deletions
73
bin/werc.rc
73
bin/werc.rc
|
|
@ -20,8 +20,9 @@ fn gentitle {
|
||||||
echo '<h1 class="headerTitle"><a href="/">' ^ $"siteTitle ^ ' <span id="headerSubTitle">' ^ $"siteSubTitle ^ '</span></a></h1>'
|
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!
|
# Don't change var name or trailing ';', dirfilter might be changed from _werc/config!
|
||||||
dirfilter = '/\/[._]/d; /'^$forbidden_uri_chars^'/d; /\/robots.\txt$/d; /\/sitemap\.txt$/d; s,^\./,,; s,\.md$,,; s,\.html,,; s,\.txt,,; '
|
# 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
|
# To be used from config files
|
||||||
fn hide_paths {
|
fn hide_paths {
|
||||||
|
|
@ -30,38 +31,41 @@ fn hide_paths {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Sidebar
|
# 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 {
|
fn menu {
|
||||||
ls -F $1 | sed $dirfilter | awk -F/ '
|
dirs = ./
|
||||||
BEGIN { print "<ul class=\"side-bar\">" }
|
dd = .
|
||||||
END { print "</ul>" }
|
for(d in $args) {
|
||||||
# Should add \. to the list of allowed chars in file names, but need to find a way to filter out .txt and so on
|
dd=$dd^'/'^$d
|
||||||
/^([a-zA-Z0-9+_\-]+[\/*]?)+$/ && $NF != "index" {
|
dirs = ( $dd $dirs )
|
||||||
isdir = match($0, "/$")
|
}
|
||||||
sub("[*/]$", "")
|
# 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
|
d = ""
|
||||||
sub("^(.*/)?([0-9]+_)?", "", bname)
|
if(match($0, "/$"))
|
||||||
|
d = "/"
|
||||||
|
sub("/$", "") # Strip trailing / for dirs so NF is consistent
|
||||||
|
|
||||||
|
p(NF, lNF, "<ul class=\"side-bar\">")
|
||||||
|
p(lNF, NF, "</ul>")
|
||||||
|
lNF = NF
|
||||||
|
|
||||||
|
bname = $NF d
|
||||||
|
path = "/" $0 d
|
||||||
gsub("_", " ", bname)
|
gsub("_", " ", bname)
|
||||||
|
|
||||||
if(isdir) {
|
if(index(ENVIRON["REQUEST_URI"] "/", path) == 1)
|
||||||
bname = bname "/"
|
print "<li><a href=\"" path "\" class=\"thisPage\">»<i> " bname "</i></a>"
|
||||||
path = $0 "/"
|
else
|
||||||
}
|
print "<li><a href=\"" path "\">› " bname "</a></li>"
|
||||||
|
}
|
||||||
if(index(ENVIRON["REQUEST_URI"] "/", "/" path) == 1) {
|
END { p(lNF, 0, "</ul>") }
|
||||||
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>"
|
|
||||||
|
|
||||||
print "</li>"
|
|
||||||
}'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gensidebar {
|
fn gensidebar {
|
||||||
|
|
@ -116,9 +120,10 @@ fn txt_handler {
|
||||||
|
|
||||||
fn dir_listing_handler {
|
fn dir_listing_handler {
|
||||||
d = `{basename -d $1}
|
d = `{basename -d $1}
|
||||||
echo '<h1 style="text-transform: capitalize;">' `{echo $d|sed -e 's,.*//,,g' -e 's,/$,,' -e 's,/, / ,g' } '</h1>'
|
dt = `{echo $d|sed -e 's,.*//,,g' -e 's,/$,,' -e 's,/, / ,g'}
|
||||||
echo '<ul style="text-transform: capitalize;">'
|
echo '<h1 class="dir-list-head">'^$dt^'</h1> <ul class="dir-list">'
|
||||||
ls -F $d | sed -e $dirfilter' s,^'$sitedir'/.*/([^$].*),<li><a href="\1">\1</a></li>,' # XXX I'm not sure what the [^$] does there
|
# 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>'
|
echo '</ul>'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -311,6 +316,8 @@ if (test -d $body) {
|
||||||
|
|
||||||
select_handler
|
select_handler
|
||||||
|
|
||||||
|
dprint $handler
|
||||||
|
|
||||||
# Template/body selection
|
# Template/body selection
|
||||||
master_template= `{get_lib_file $master_template}
|
master_template= `{get_lib_file $master_template}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ fn listDir {
|
||||||
if(! ~ $#redirectPermanent 1)
|
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 = ''
|
desc = ''
|
||||||
if (test -f $i.md) {
|
if (test -f $i.md) {
|
||||||
desc = `{ getMdDesc $i.md }
|
desc = `{ getMdDesc $i.md }
|
||||||
|
|
|
||||||
|
|
@ -363,3 +363,9 @@ blockquote {
|
||||||
border-left: 1px solid blue;
|
border-left: 1px solid blue;
|
||||||
font-style: italic;
|
font-style: italic;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* PAGE/HANDLER SPECIFIC */
|
||||||
|
h1.dir-list-head, ul.dir-list {
|
||||||
|
text-transform: capitalize;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue