cork

cork, werc stripped down

Mirrored from GitHub

git clone https://github.com/christc4/cork.git

Jump to: README.md cork-base.rc cork-horizontal-sidebar.rc cork.rc horizontal-sidebar.css


README.md

# cork

A retired super-small static-site generator written in RC shell, compatible on any server with the Plan9 core-utils installed

Originally a fork of [werc](http://werc.cat-v.org), Cork took its own software direction, focusing on delivering one *singular* small and tidy shell script to work with an accompanying Markdown-to-HTML generator.

## Features

- Statically generated sidebar with directory listing  
  - Can support highlighting of parent directories and current file  
- Performant  
  - Plan9 core-utils outperform GNU/BSD  
- Everything is scriptable  
  - Small codebase + compatibility with werc

## Install

Cork has only been tested with OpenBSD's native webserver, `httpd`. In theory, the [following guides](http://werc.cat-v.org/docs/web-server-setup/) should be compatible.

> If you don't want the full-blown plan9port, try **9base**.

## news

- **2025/01/02** – Support for horizontal sidebar added  
- **2024/12/28** – Rendering issue solved for TUI browsers  
  - Contrary to belief, `<!doctype>` and `<html>` tags are necessary for full compatibility  
  - HTML headers needed to specify `Content-Type`  

cork-base.rc

#!/bin/rc
path=(. /bin)
fn run {
        lpaf=home$REQUEST_URI
        rpafs='/'; wd='/'; ifs='/';
        arg = `{echo $REQUEST_URI}
        if (test -d $lpaf) {
                lpaf=$lpaf^'i'
        }
        for (i in $arg) {
                wd=$wd^$i
                rpafs=($rpafs $wd)
                wd=$wd'/'
        }
        echo;
        for (h in $bar) { $$h }
        mh $lpaf.md
}
fn sbar {
        echo -n 'ENTER HTML PREAMBLE HERE'
        ls -F home/./$rpafs | sed -e 's,/+\./+,/,g' \
        -e '/\/i\.(md)$/d' \
        -e 's/\.(md)$//' -e 's!^home!!' | sort | awk -F/ '
        function p(x, y, s) { for (i=0; i<x-y; i++) printf s }
        BEGIN { lNF = 2 }
        {
                sub("/$", "", $0)
                p(NF, lNF, "<ul>"); p(lNF, NF, "</ul><hr>")
                lNF = NF; fp = $NF
                printf "<li><a href=\%s\>%s</a>", $0, fp
        }
        END { p(lNF, 2, "</ul><hr>"); printf "</ul></nav></small><article>" }'}
fn add {
        _l = $1^_^$#$1
        $_l = $*(2-)
        $1 = ($$1 $_l)
}
add bar sbar; run
 (avsbq) | cat cork-base
#!/bin/rc
path=(. /bin)
fn run {
        lpaf=home$REQUEST_URI
        rpafs='/'; wd='/'; ifs='/';
        arg = `{echo $REQUEST_URI}
        if (test -d $lpaf) {
                lpaf=$lpaf^'i'
        }
        for (i in $arg) {
                wd=$wd^$i
                rpafs=($rpafs $wd)
                wd=$wd'/'
        }
        echo;
        for (h in $bar) { $$h }
        mh $lpaf.md
}
fn sbar {
        echo -n '<style>img{width:150px;}nav li ul{padding-left:.5em}body{display:flex;flex-wrap:wrap;margin:20 24%}article{flex:1}nav{min-width:12em}ul{list-style: none}#t{flex:2;position:fixed;right:calc(5vw + 10px);width:222px;max-height:80vh;overflow-y:auto;box-sizing:border-box;background-color:#fff;z-index:10;}</style><meta charset=utf-8><small><nav><ul>'
        ls -F home/./$rpafs | sed -e 's,/+\./+,/,g' \
        -e '/\/i\.(md)$/d' \
        -e 's/\.(md)$//' -e 's!^home!!' | sort | awk -F/ '
        function p(x, y, s) { for (i=0; i<x-y; i++) printf s }
        BEGIN { lNF = 2 }
        {
                sub("/$", "", $0)
                p(NF, lNF, "<ul>"); p(lNF, NF, "</ul><hr>")
                lNF = NF; fp = $NF
                printf "<li><a href=\%s\>%s</a>", $0, fp
        }
        END { p(lNF, 2, "</ul><hr>"); printf "</ul></nav></small><article>" }'}
fn add {
        _l = $1^_^$#$1
        $_l = $*(2-)
        $1 = ($$1 $_l)
}
add bar sbar; run

cork-horizontal-sidebar.rc

#!/bin/rc

path=(. /bin)

req_p=`{echo -n $REQUEST_URI }

fn run {
	lpaf=home$REQUEST_URI
	rpafs='/'; wd='/'; ifs='/';
	arg = `{echo -n $REQUEST_URI}
	if (test -d $lpaf) {
		lpaf=$lpaf^'i'
	}
	for (i in $arg) {
		wd=$wd^$i
		rpafs=($rpafs $wd)
		wd=$wd'/'
	}
http_content_type='text/html'
echo Content-Type: $http_content_type
	echo;
	for (h in $bar) { $$h }
	mh $lpaf.md
}


fn sbar {
	echo -n 'insert html preamble'
	ls -F home/./$rpafs | sed -e 's,/+\./+,/,g' \
	-e '/\/i\.(md)$/d' \
	-e 's/\.(md)$//' -e 's!^home!!' | sort | awk -F/ '
	 function p(x, y, s) { for(i=0; i < x-y; i+=1) printf s }
    BEGIN { lNF=2; printf "<ul>" }
    {
        d = ""
        if(match($0, "/$"))
            d = "/"
        sub("/$", "") # Strip trailing / for dirs so NF is consistent

	p(NF, lNF, "<ul>» 「"); p(lNF, NF, "」</ul>")
        lNF = NF

        bname = $NF d
        path = $0 d
        gsub(/[\-_]/, " ", bname)

        # To avoid false matches add trailing / even for plain files to act as delimiter
        pa = path
        gsub(/[^\/]$/, "&/", pa)

        if(index(ENVIRON["req_p"] "/", pa) == 1)
            printf "<li><a href="path" class=\"c\">"bname"</a>"
        else
            printf "<li><a href="path">"bname"</a>"
    }
    END { p(lNF, 2, "</ul>"); printf "</ul></nav><hr><article>" }'
}

fn add {
	_l = $1^_^$#$1
	$_l = $*(2-)
	$1 = ($$1 $_l)
}

add bar sbar; run

cork.rc

#!/bin/rc

path=(. /bin)
req_p=`{echo -n $REQUEST_URI }
fn run {
        lpaf=home$REQUEST_URI
        rpafs='/'; wd='/'; ifs='/';
        arg = `{echo -n $REQUEST_URI}
        if (test -d $lpaf) {
                lpaf=$lpaf^'i'
        }
        for (i in $arg) {
                wd=$wd^$i
                rpafs=($rpafs $wd)
                wd=$wd'/'
        }
http_content_type='text/html'
echo Content-Type: $http_content_type
        echo;
        for (h in $bar) { $$h }
        mh $lpaf.md
}
fn sbar {
        echo -n 'ENTER HTML PREAMBLE HERE'
        ls -F home/./$rpafs | sed -e 's,/+\./+,/,g' \
        -e '/\/i\.(md)$/d' \
        -e 's/\.(md)$//' -e 's!^home!!' | sort | awk -F/ '
         function p(x, y, s) { for(i=0; i < x-y; i+=1) printf s }
    BEGIN { lNF=2; printf "<ul>" }
    {
        d = ""
        if(match($0, "/$"))
        d = "/"
        sub("/$", "") # Strip trailing / for dirs so NF is consistent
        p(NF, lNF, "  ⮧<ul>")
        p(lNF, NF, "</ul><hr>")
        lNF = NF
        bname = $NF d
        path = $0 d
        gsub(/[\-_]/, " ", bname)
        # Trailing / avoids false pattern matching
        pa = path
        gsub(/[^\/]$/, "&/", pa)
        if(index(ENVIRON["req_p"] "/", pa) == 1)
            printf "<li><a href="path" class=\"c\">"bname"</a>"
        else
            printf "<li><a href="path">"bname"</a>"
    }
    END { p(lNF, 2, "</ul>"); printf "</ul></nav><article>" }'
}
fn add {
        _l = $1^_^$#$1
        $_l = $*(2-)
        $1 = ($$1 $_l)
}
add bar sbar; run

horizontal-sidebar.css

ul {
    display: inline
}
li {
    list-style-position: inside;
    display: inline
}
 ul {
  margin: 0;
  padding: 0.3em;
  list-style-type: none;
  list-style-image: none;
  border: 0
}
 li {
  display: inline;
  white-space: nowrap;
  line-height: 1.6em
}
 ul li a {
  margin: 0;
  padding: 0.1em 1ex 0.1em 1ex;
  text-decoration: none;
  font-size: 1em;
  border: 0
}
ul > ul {
    padding-left: 40px
}