commit 9aa693f20a928ba8a8f03f6e068ff6bd8ceed9e4
Author: Josuah Demangeon <[email protected]>
Date:   Thu Sep 6 00:45:57 2018 +0200

    ./make: add missing directory listing
    
    The previous verision did not handle directories without a index.md
    file in.  This version recurse over each directory instead of each
    markdown file so that even empty directories get an "ls page".
    
    Also, a scheme is added in front of the blue nav bar links so that
    they do not get treated as relative links but rather absolute links.

diff --git a/make b/make
index 3b2f03b3..fdba9b73 100755
--- a/make
+++ b/make
@@ -16,9 +16,8 @@ nav() {
        do
                test -d "$2/$dir" || continue
                test -z "${1##$2/$dir/*?}" && match=' class="thisPage"' || 
match=
-               printf '<li><a%s href="%s">' "$match" "$2/$dir"
-               printf %s "$dir" | tr _- '  '
-               printf '/</a>'
+               printf '<li><a%s href="%s">' "$match" "//$2/$dir/"
+               printf '%s/</a>' "$dir" | tr _- '  '
                if test "$match"
                then
                        printf '<ul>
'
@@ -29,14 +28,20 @@ nav() {
        done
 }
 
-find * -name '*.md' | while IFS='' read -r page
+find * -type d | while IFS='' read -r page
 do
+       exec >$page/index.html
+       page="$page/index.md"
        this_domain="${page%%/*}"
        printf 'Generating %s
' "$page" 1>&2
-       exec >${page%.md}.html
 
        # header
-       title=$(sed 's,^#* *,,; q' "$page")
+       if test -f "$page"
+       then
+               title=$(sed 's,^#* *,,; q' "$page")
+       else
+               title=$(basename "$(dirname "$page")")
+       fi
        awk -v title="$title" -v subtitle="$(cat "$this_domain/title")" \
                '{ gsub("%t", title); gsub("%s", subtitle); print; }' head.html
 
@@ -44,7 +49,7 @@ do
        printf '<div id="menu">
'
        while IFS='' read -r domain
        do
-               printf '<a href="%s"' "//${page%.md}.html"
+               printf '<a href="%s"' "//$domain"
                test "$this_domain" = "$domain" && printf ' class="thisSite"'
                printf '">%s</a>
' "${domain%%.*}"
        done <domains
@@ -62,7 +67,20 @@ do
 
        # main
        printf '<div id="main">
'
-       smu "$page"
+       if test -f "$page"
+       then
+               smu "$page"
+       else
+               printf '<ul>
'
+               ls "${page%/index.md}" | while IFS='' read -r dir
+               do
+                       path=${page%/index.md}/$dir/
+                       test -d "$path" || continue
+                       printf '<li><a href="%s">' "//$path"
+                       printf '%s</a></li>
' "$dir" | tr _- '  '
+               done
+               printf '</ul>
'
+       fi
        printf '</div>

'
 
        printf '</div>

' # end of id="content"


Reply via email to