cleanup - swerc - anselm's simpler werc fork
 (HTM) git clone git://git.suckless.org/swerc
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
       ---
 (DIR) commit 67a0f0a4d9d708b9087f162c183abce7bad45d15
 (DIR) parent a848399c4f4346f7cfca3a7d61b015e51bd56c32
 (HTM) Author: anselm@garbe.us <unknown>
       Date:   Sat, 11 Feb 2012 18:34:28 +0100
       
       cleanup
       Diffstat:
         D apps/wman/app.rc                    |      89 -------------------------------
         D apps/wman/man_page.tpl              |       7 -------
         D apps/wman/page_list.tpl             |      11 -----------
         M apps/wman/search.tpl                |      20 --------------------
         D apps/wman/section_list.tpl          |      11 -----------
         M bin/corehandlers.rc                 |      35 +++++++++++--------------------
         M bin/werc.rc                         |       6 +-----
         M etc/initrc                          |       6 +-----
         M etc/initrc.local                    |       1 +
         M lib/default_master.tpl              |      34 ++++++++++++++++----------------
         M lib/headers.tpl                     |      10 ++++++++--
         M pub/style.css                       |      23 ++++++++++++++---------
       
       12 files changed, 54 insertions(+), 199 deletions(-)
       ---
 (DIR) diff --git a/apps/wman/app.rc b/apps/wman/app.rc
       @@ -1,89 +0,0 @@
       -fn conf_enable_wman {
       -    wman_tmac=an
       -    wman_base_uri=$conf_wd
       -    wman_man_path=$*
       -    if(~ $#wman_man_path 0)
       -        wman_man_path=$wman_base_uri
       -    conf_enable_app wman
       -}
       -
       -wman_junk_filter='/(\/(INDEX|\.cvsignore|_.*)|\.9p|\.html)$/d; s!/man([0-9]+/[^/]+)$!/\1!; '
       -fn wman_ls_pages {
       -    ls $* \
       -        | sed $dirfilter^$wman_junk_filter^' s/\.([0-9]|9p)$//; s!/0intro$!/intro!' \
       -        | sort -u
       -}
       -fn wman_init {
       -    ifs=$ifs^'/' { p=`{echo $req_path | sed 's!^'^$wman_base_uri^'!!'} }
       -    wman_cat=$p(1)
       -    wman_page=$p(2)
       -    if(~ $#wman_unix_mode 1) {
       -        wman_cp='man'
       -        wman_pe=.^$"wman_cat
       -    }
       -
       -    if(! ~ $"wman_cat '') {
       -        wman_cat_path=$wman_man_path^/^$"wman_cp^$p(1)
       -        if(! ~ $"wman_page '') {
       -            wman_page_file=$wman_page^$"wman_pe
       -            # Hack to handle 0intro files.
       -            if(~ $wman_page intro && test -f $wman_cat_path^/0^$"wman_page_file)
       -                 wman_page_file=0^$"wman_page_file
       -            wman_page_file=$wman_cat_path^/^$"wman_page_file
       -            x=`{echo $"req_path|sed 's%.*/([^/]+)/'$"wman_cat'/'^$"wman_page^'%\1%; s%_% %g'}
       -            pageTitle=$wman_page' page from Section '$wman_cat' of the '^$"x' manual'
       -        }
       -    }
       -
       -    wman_cat_list=`{ls -F $wman_man_path/*/  \
       -        | sed -e $wman_junk_filter -e 's!.*/([^/]+)/[^/]+$!\1!; /[0-9]+/!d' \
       -        | sort -un}
       -
       -    synth_paths=($wman_base_uri$wman_cat_list'/')
       -
       -    if(~ $req_path $wman_base_uri && ~ $"handler_body_main '')
       -       handler_body_main=(tpl_handler apps/wman/section_list.tpl)
       -    if not if(~ $req_path $wman_base_uri^*) {
       -        #^*/[a-z0-9]*[a-z]* $wman_base_uri^*/*[a-z]*[a-z0-9] $wman_base_uri^*/[a-z])
       -        if(echo $req_path | grep -s '^'^$wman_base_uri^'/*[0-9]+/[0-9a-z\-\+\.]+$')
       -           if(test -f $wman_page_file) # Check for 404
       -               handler_body_main=(tpl_handler apps/wman/man_page.tpl)
       -        if not if(~ $req_path $wman_base_uri^*/)
       -           handler_body_main=(tpl_handler apps/wman/page_list.tpl)
       -        if not if(~ $p(2) [A-Z]* [0-9][A-Z]*) # Correct badly capitalized links
       -            perm_redirect $wman_base_uri^$p(1)^/^`{echo $p(2) |tr 'A-Z' 'a-z'}
       -    }
       -
       -    # Search
       -    ll_add handlers_body_head tpl_handler apps/wman/search.tpl
       -    if(! ~ $"post_arg_wman_search '') {
       -        s=`{echo $post_arg_wman_search | sed 's/[^a-zA-Z0-9\-\.]+//g; s/\.+/./g; 1q'}
       -        ifs='' { wman_search_results=`{wman_ls_pages $wman_man_path/*/*^$"s^*} }
       -        if(! ~ $"post_arg_go '' && ~ `{echo -n $wman_search_results|wc -l} 1)
       -            post_redirect $wman_base_uri^`{echo $wman_search_results|awk -F/ '{print $(NF-1)"/"$NF}'}
       -    }
       -
       -}
       -
       -fn wman_get_section_desc { 
       -    cat $wman_man_path/^$"wman_cp^$1/0intro* >[2]/dev/null| sed '1,2d; s!intro \\- [Ii]ntroduction to !!; 3q;' 
       -}
       -
       -fn wman_page_gen {
       -    #troff -manhtml $1| troff2html -t 'Plan 9 from User Space'
       -    # Using GNU col here to remove nroffs garbage (eg., from .ft B); p9p has no col(1) :(
       -    troff -N -m$wman_tmac $1 | wman_out_filter
       -}
       -
       -fn wman_out_filter {
       -    wman_default_out_filter
       -}
       -
       -fn wman_default_out_filter {
       -    escape_html \
       -    | sed 's!([\.\-a-zA-Z0-9]+)\(('^`{echo $wman_cat_list|tr ' ' '|'}^')\)!<a href="../\2/\1">&</a>!g' \
       -    | awk '/^$/ {if(n != 1) print; n=1; next} /./ {n=0; print}'
       -
       -}
       -
       -
 (DIR) diff --git a/apps/wman/man_page.tpl b/apps/wman/man_page.tpl
       @@ -1,7 +0,0 @@
       -<pre>
       -%{
       -
       -wman_page_gen $wman_page_file
       -
       -%}
       -</pre>
 (DIR) diff --git a/apps/wman/page_list.tpl b/apps/wman/page_list.tpl
       @@ -1,11 +0,0 @@
       -% d=`{wman_get_section_desc $wman_cat} 
       -<h1>Manual pages - Section %($wman_cat%): %($"d%)</h1>
       -
       -<ul style="float:left">
       -%{
       -wman_ls_pages $wman_cat_path \
       -    | awk -F/ '{ print "<li><a href=\""$(NF)"\">"$(NF)"</a></li>" }
       -    NR%20 == 0 { print "</ul><ul style=\"float: left\">" }'
       -%}
       -</ul>
       -
 (DIR) diff --git a/apps/wman/search.tpl b/apps/wman/search.tpl
       @@ -1,20 +0,0 @@
       -<form action="" method="POST">
       -<fieldset>
       -    <input type="text" name="wman_search" value="%($"s%)" />
       -    <input type="submit" name="go" value="Feel Lucky" />
       -    <input type="submit" value="Search" />
       -
       -% if(! ~ $"post_arg_wman_search '') {
       -%   if(~ $"wman_search_results '') {
       -        No matches found for <i>'%($post_arg_wman_search%)'</i>.
       -%   }
       -%   if not {
       -        <ul>
       -%       echo $wman_search_results|awk -F/ '$(NF-1) ~ "^[0-9]+$" {printf "<li><a href=\"'$wman_base_uri'%s/%s\" />%s(%s)</a></li>", $(NF-1),$NF, $NF, $(NF-1)}'
       -        </ul>
       -%   }
       -% }
       -
       -</fieldset>
       -</form>
       -
 (DIR) diff --git a/apps/wman/section_list.tpl b/apps/wman/section_list.tpl
       @@ -1,11 +0,0 @@
       -<h1>Manual Sections</h1>
       -
       -<ul style="text-transform: capitalize;">
       -% for(c in $wman_cat_list) {
       -    <li><a href="%($c%)/"><b>Section: %($c%)</b></a>
       -%   wman_get_section_desc $c 
       -%   if(~ $status '' '|')
       -%       echo '(<a href="'$c'/intro">intro</a>)'
       -    </li>
       -% }
       -</ul>
 (DIR) diff --git a/bin/corehandlers.rc b/bin/corehandlers.rc
       @@ -12,7 +12,7 @@ fn nav_tree {
            # /./ to deal with p9p's ls failure to follow dir symlinks otherwise
            ls -F $sitedir/./$req_paths_list >[2]/dev/null \
                | { 
       -            sed $dirfilter'/\/[^_.\/][^\/]*(\.(md|txt|html)|\/)$/!d; s!^'$sitedir'!!; '$dirclean 
       +            sed $dirfilter'/\/[^_.\/][^\/]*(\.(md|txt|html|1)|\/)$/!d; s!^'$sitedir'!!; '$dirclean 
                    if(! ~ $#synth_paths 0) echo $synth_paths | tr ' ' $NEW_LINE 
                } | sort -u | awk -F/ ' 
            function p(x, y, s) { for(i=0; i < x-y; i+=1) print s }
       @@ -41,10 +41,6 @@ fn nav_tree {
                    print "<li><a href=\"" path "\">" bname "</a></li>"
            }
            END { p(lNF, 2, "</ul></li>"); }'
       -    if(~ $"req_paths_list '/ /sitemap')
       -        echo '<li><a href="/sitemap" class="thisPage">Site map</a></li>'
       -    if not
       -        echo '<li><a href="/sitemap">Site map</a></li>'
            echo '</ul>'
        }
        
       @@ -74,6 +70,12 @@ fn html_handler {
                END {if(body<=0) {print buf}}' < $1
        }
        
       +fn man_handler {
       +    echo '<pre>'
       +    $man_formatter $1
       +    echo '</pre>'
       +}
       +
        fn txt_handler {
            # Note: Words are not broken, even if they are way beyond 82 chars long
            echo '<pre>'
       @@ -103,6 +105,10 @@ fn setup_handlers {
                local_file=$local_path.md
                handler_body_main=(md_handler $local_file)
            }
       +    if not if(test -f $local_path.1) {
       +        local_file=$local_path.1
       +        handler_body_main=(man_handler $local_file)
       +    }
            if not if(test -f $local_path.tpl) {
                local_file=$local_path.tpl
                handler_body_main=(tpl_handler $local_file)
       @@ -119,28 +125,11 @@ fn setup_handlers {
                local_file=$local_path.txt
                handler_body_main=(txt_handler $local_file)
            }
       -
       -    # XXX Should check that $enabled_apps exist in $werc_apps?
       -    # XXX Should split init of apps that provide main handler (eg., blog) and apps that don't (eg., comments)?
       -    if(! ~ $#enabled_apps 0)
       -        for(a in $enabled_apps)
       -            $a^'_init'
       -
            if(! ~ $#handler_body_main 0)
                { } # We are done
            # Dir listing
       -    if not if(~ $local_path */index) {
       +    if not if(~ $local_path */index)
                handler_body_main=(dir_listing_handler $req_path)
       -        if(test -f $sitedir$req_path'_header.md') {
       -            t=`{get_file_title $sitedir$req_path'_header.md'}
       -            if(! ~ $"t '')
       -                pageTitle=$t
       -
       -            ll_add handlers_body_head md_handler $sitedir$req_path'_header.md' 
       -        }
       -        if(test -f $sitedir$req_path'_footer.md')
       -            ll_add handlers_body_foot md_handler $sitedir$req_path'_footer.md'            
       -    }
            # Canonize explicit .html urls, the web server might handle this first!
            if not if(~ $local_path *.html && test -f $local_path)
                perm_redirect `{ echo $req_path|sed 's/.html$//' }
 (DIR) diff --git a/bin/werc.rc b/bin/werc.rc
       @@ -12,7 +12,7 @@ difs=$ifs # Used to restore default ifs when needed
        # Expected input: ls -F style, $sitedir/path/to/files/
        #          <ls -F+x><symlink hack><Useless?><hiden files  >
        dirfilter='s/\*$//; s,/+\./+,/,g; s,^\./,,; /\/[._][^\/]/d; /'$forbidden_uri_chars'/d; /\/sitemap\.xml$/d; /\/index\.(md|html|txt|tpl)$/d; /\/(robots|sitemap)\.txt$/d; /_werc\/?$/d; '
       -dirclean=' s/\.(md|html|txt)$//; '
       +dirclean=' s/\.(md|html|txt|1)$//; '
        
        # Careful, the proper p9p path might not be set until initrc.local is sourced
        path=(. $PLAN9/bin ./bin /bin /usr/bin) 
       @@ -21,7 +21,6 @@ headers=lib/headers.tpl
        res_tail='</body></html>'
        http_content_type='text/html'
        ll_add handlers_bar_left nav_tree
       -werc_apps=( apps/* )
        werc_root=`{pwd}
        sitesdir=sites
        
       @@ -30,9 +29,6 @@ sitesdir=sites
        if(test -f etc/initrc.local)
            . ./etc/initrc.local
        
       -for(a in $werc_apps)
       -    . ./$a/app.rc
       -
        fn werc_exec_request {
            site=$SERVER_NAME
            base_url=http://$site
 (DIR) diff --git a/etc/initrc b/etc/initrc
       @@ -27,14 +27,10 @@ path=($plan9port/bin . ./bin ./bin/contrib /bin /usr/bin)
        # formatter, but all major functionality should should be formatter agnostic.
        #formatter=(md2html.awk)
        formatter=(fltr_cache markdown.pl)
       +man_formatter=(troff -N -man)
        
        # Enable debugging, to disable set to ()
        debug=true
        
        # Globally enabled apps
        enabled_apps=( )
       -
       -# Default site variables, must be set in initrc.local or _werc/config, only siteTitle is required.
       -#masterSite=cat-v.org # Not required!
       -#siteTitle='cat-v'
       -#siteSubTitle='Considered harmful'
 (DIR) diff --git a/etc/initrc.local b/etc/initrc.local
       @@ -1,3 +1,4 @@
        sitesdir='/var/www/sites'
        formatter=(fltr_cache markdown)
       +man_formatter=(troff -N -man)
        debug=()
 (DIR) diff --git a/lib/default_master.tpl b/lib/default_master.tpl
       @@ -1,12 +1,23 @@
                <div id="menu">
       -                <a href="http://garbe.us">home</a> |
       -                <a href="http://dl.garbe.us">download</a> |
       -                <a href="http://suckless.org">suckless.org</a> |
       +                <a href="http://suckless.org">home</a> |
                        <a href="http://hg.suckless.org">code</a> |
       -                <a href="http://dl.suckless.org">software</a>
       +                <a href="http://dl.suckless.org">download</a> |
       +                <a href="http://man.suckless.org">man</a> |
       +                <a href="http://dwm.suckless.org">dwm</a> |
       +                <a href="http://libs.suckless.org">libs</a> |
       +                <a href="http://st.suckless.org">st</a> |
       +                <a href="http://sta.li">stali</a> |
       +                <a href="http://surf.suckless.org">surf</a> |
       +                <a href="http://tools.suckless.org">tools</a> |
       +                <a href="http://wmi.suckless.org">wmi</a>
                </div>
                <div id="header">
       -                <a href="/">%($"siteTitle%) <span id="headerSubTitle">%($"siteSubTitle%)</span></a>
       +% if(! ~ $#siteImage 0) {
       +        <a href="/"><img src="%($"siteImage%)" alt="%($"siteTitle%)"/> <span id="headerSubTitle">%($"siteSubTitle%)</span></a>
       +% }
       +% if not {
       +        <a href="/">%($"siteTitle%) <span id="headerSubTitle">%($"siteSubTitle%)</span></a>
       +% }
                </div>
        
                <div id="content">
       @@ -19,17 +30,6 @@
        % }
        
                <div id="ads">
       -        <script type="text/javascript"><!--
       -        google_ad_client = "ca-pub-9029609350780515";
       -        /* garbeus */
       -        google_ad_slot = "4837453445";
       -        google_ad_width = 160;
       -        google_ad_height = 600;
       -        //-->
       -        </script>
       -        <script type="text/javascript"
       -        src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
       -        </script>
                </div>
                <div id="main">
        
       @@ -48,6 +48,6 @@
                <a href="http://werc.cat-v.org/">Powered by werc</a>
                </div>
                <div class="right">
       -        &copy; 2012 Anselm R Garbe
       +        &copy; 2006-2012 suckless.org community
                </div>
                </div>
 (DIR) diff --git a/lib/headers.tpl b/lib/headers.tpl
       @@ -2,7 +2,13 @@
        <html>
        <head> 
                <title>%($pageTitle%)</title>
       -        <link href='http://fonts.googleapis.com/css?family=Cantarell' rel='stylesheet' type='text/css'>
       -        <link rel="stylesheet" href="/pub/style.css" type="text/css"> 
       +% env > /tmp/x.txt
       +% style = `{get_cookie style}
       +% if(~ $"style 1) {
       +        <link rel="stylesheet" type="text/css" href="/pub/style1.css">
       +% }
       +% if not {
       +        <link rel="stylesheet" type="text/css" href="/pub/style.css">
       +% }
                <meta charset="utf-8"> 
        </head> 
 (DIR) diff --git a/pub/style.css b/pub/style.css
       @@ -1,14 +1,13 @@
        body {
                background-color: #eee;
                color: #333;
       -        font-family: 'Cantarell', Helvetica, Verdana, Arial, 'Liberation Sans', FreeSans, sans-serif;
       -        text-align: justify;
       +        font-family: Helvetica, Verdana, Arial, 'Liberation Sans', FreeSans, sans-serif;
                padding: 0;
                margin: 0;
        }
        
        a {
       -        color: #36c;
       +        color: #057;
                text-decoration: none;
        } 
        
       @@ -19,7 +18,7 @@ a:hover {
        #menu {
                clear: both;
                color: #ccc;
       -        background-color: #666;
       +        background-color: #057;
                padding: 0.7ex;
                font-size: 84%;
        }
       @@ -30,7 +29,7 @@ a:hover {
        }
        
        #menu a:hover {
       -        color: #eee;
       +        color: #ccc;
        }
        
        #header {
       @@ -38,7 +37,7 @@ a:hover {
                color: #666;
                text-shadow: 1px 1px #fff;
                font-size: 1.7em;
       -        padding: 0.7ex;
       +        padding: 0.7ex 0.7ex 0.7ex 0.7em;
                border-top: 1px solid #ccc;
        }
        
       @@ -66,6 +65,12 @@ h4 {
                font-size: 1.1em;
        }
        
       +#headerSubTitle {
       +        font-size: 0.8em;
       +        font-style: italic;
       +        margin-left: 1em;
       +}
       +
        #content {
                clear: both;
                margin: 0;
       @@ -81,7 +86,7 @@ h4 {
                float: left;
                margin: 0 1px 0 0;
                padding: 1em 0;
       -        border-right: 1px solid #ccc;
       +        border-right: 1px dotted #ccc;
                width: 200px;
        }
        
       @@ -101,7 +106,7 @@ h4 {
        }
        
        #nav li a {
       -        color: #36c;
       +        color: #057;
                display: block;
                margin: 0;
                padding: 0.8ex 2em 0.8ex 1em;
       @@ -118,10 +123,10 @@ h4 {
        }
        
        #main {
       +        text-align: justify;
                margin: 0 0 0 200px; 
                padding: 1.5em;
                max-width: 50em;
       -        border-left: 1px solid #ccc;
        }
        
        #ads {