feat: Better sitemap

Now lists are collapsed when they only have a single element.
This makes them much more efficient/less annoying to read.
This commit is contained in:
Nuno Sempere 2022-07-26 03:05:25 +00:00
parent 73cb339bc7
commit 44dc5989c4

View File

@ -15,6 +15,7 @@ fn get_mdate {
} }
fn get_children { fn get_children {
d=$1
children = `{ls -dF $d^*/ $d^*.md $d^*.html $d^*.txt >[2]/dev/null | sed $dirfilter} children = `{ls -dF $d^*/ $d^*.md $d^*.html $d^*.txt >[2]/dev/null | sed $dirfilter}
echo $children echo $children
} }
@ -27,31 +28,53 @@ fn listDir {
. $d/_werc/config . $d/_werc/config
if(~ $#perm_redir_to 0) { if(~ $#perm_redir_to 0) {
echo '<ul class="sitemap-list">' siblings=`{get_children $d}
siblings=`{ls -dF $d^*/ $d^*.md $d^*.html $d^*.txt >[2]/dev/null | sed $dirfilter}
numsiblings = $#siblings numsiblings = $#siblings
if(! ~ $numsiblings 0 && ! ~ $numsiblings 1){
echo '<ul class="sitemap-list">'
}
for(i in $siblings) { for(i in $siblings) {
ownchildren= `{get_children $i}
numownchildren=$#ownchildren
filename=`{get_file_title $i} filename=`{get_file_title $i}
url=`{echo $i|sed 's!'$sitedir'!!; '$dirclean's!/index$!/!; '} url=`{echo $i|sed 's!'$sitedir'!!; '$dirclean's!/index$!/!; '}
dirname=`{echo /$url|sed 's/[\-_]/ /g; s,.*/([^/]+)/?$,\1,'} dirname=`{echo /$url|sed 's/[\-_]/ /g; s,.*/([^/]+)/?$,\1,'}
## Open list?
if(! ~ $numsiblings 1){
echo '<li>'
}
if(! ~ $#filename 0 && ! ~ $filename '') { if(! ~ $#filename 0 && ! ~ $filename '') {
# filename=' — '$"filename # filename=' — '$"filename
echo '<li><a href="'$url'">'^$"filename^'</a></li>' echo '<a href="'$url'">'^$"filename^'</a>'
echo $numsiblings
} }
if not { if not {
if(! ~ $"dirname $filtereddirs) if(! ~ $"dirname $filtereddirs)
echo '<li><a href="'$url'">'^$"dirname^'</a></li>' echo '<a href="'$url'">'^$"dirname^'</a>'
echo $numsiblings
} }
## echo $numsiblings' '$numownchildren
## ^ Useful for debugging purposes.
## Close list?
if(! ~ $numownchildren 1){
echo '</li>'
}
if not {
echo '/'
}
echo $base_url^$url >> $tmpfile echo $base_url^$url >> $tmpfile
echo '<url><loc>'$base_url^$url'</loc><lastmod>'^`{get_mdate $i}^'</lastmod></url>' >> $tmpfilex echo '<url><loc>'$base_url^$url'</loc><lastmod>'^`{get_mdate $i}^'</lastmod></url>' >> $tmpfilex
if(test -d $i) if(test -d $i)
@{ listDir $i } @{ listDir $i }
} }
if(! ~ $numsiblings 0 && ! ~ $numsiblings 1){
echo '</ul>' echo '</ul>'
} }
} }
}
fltr_cache listDir $sitedir/ fltr_cache listDir $sitedir/