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
1 # cork 2 3 A retired super-small static-site generator written in RC shell, compatible on any server with the Plan9 core-utils installed 4 5 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. 6 7 ## Features 8 9 - Statically generated sidebar with directory listing 10 - Can support highlighting of parent directories and current file 11 - Performant 12 - Plan9 core-utils outperform GNU/BSD 13 - Everything is scriptable 14 - Small codebase + compatibility with werc 15 16 ## Install 17 18 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. 19 20 > If you don't want the full-blown plan9port, try **9base**. 21 22 ## news 23 24 - **2025/01/02** – Support for horizontal sidebar added 25 - **2024/12/28** – Rendering issue solved for TUI browsers 26 - Contrary to belief, `<!doctype>` and `<html>` tags are necessary for full compatibility 27 - HTML headers needed to specify `Content-Type`
cork-base.rc
1 #!/bin/rc 2 path=(. /bin) 3 fn run { 4 lpaf=home$REQUEST_URI 5 rpafs='/'; wd='/'; ifs='/'; 6 arg = `{echo $REQUEST_URI} 7 if (test -d $lpaf) { 8 lpaf=$lpaf^'i' 9 } 10 for (i in $arg) { 11 wd=$wd^$i 12 rpafs=($rpafs $wd) 13 wd=$wd'/' 14 } 15 echo; 16 for (h in $bar) { $$h } 17 mh $lpaf.md 18 } 19 fn sbar { 20 echo -n 'ENTER HTML PREAMBLE HERE' 21 ls -F home/./$rpafs | sed -e 's,/+\./+,/,g' \ 22 -e '/\/i\.(md)$/d' \ 23 -e 's/\.(md)$//' -e 's!^home!!' | sort | awk -F/ ' 24 function p(x, y, s) { for (i=0; i<x-y; i++) printf s } 25 BEGIN { lNF = 2 } 26 { 27 sub("/$", "", $0) 28 p(NF, lNF, "<ul>"); p(lNF, NF, "</ul><hr>") 29 lNF = NF; fp = $NF 30 printf "<li><a href=\%s\>%s</a>", $0, fp 31 } 32 END { p(lNF, 2, "</ul><hr>"); printf "</ul></nav></small><article>" }'} 33 fn add { 34 _l = $1^_^$#$1 35 $_l = $*(2-) 36 $1 = ($$1 $_l) 37 } 38 add bar sbar; run 39 (avsbq) | cat cork-base 40 #!/bin/rc 41 path=(. /bin) 42 fn run { 43 lpaf=home$REQUEST_URI 44 rpafs='/'; wd='/'; ifs='/'; 45 arg = `{echo $REQUEST_URI} 46 if (test -d $lpaf) { 47 lpaf=$lpaf^'i' 48 } 49 for (i in $arg) { 50 wd=$wd^$i 51 rpafs=($rpafs $wd) 52 wd=$wd'/' 53 } 54 echo; 55 for (h in $bar) { $$h } 56 mh $lpaf.md 57 } 58 fn sbar { 59 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>' 60 ls -F home/./$rpafs | sed -e 's,/+\./+,/,g' \ 61 -e '/\/i\.(md)$/d' \ 62 -e 's/\.(md)$//' -e 's!^home!!' | sort | awk -F/ ' 63 function p(x, y, s) { for (i=0; i<x-y; i++) printf s } 64 BEGIN { lNF = 2 } 65 { 66 sub("/$", "", $0) 67 p(NF, lNF, "<ul>"); p(lNF, NF, "</ul><hr>") 68 lNF = NF; fp = $NF 69 printf "<li><a href=\%s\>%s</a>", $0, fp 70 } 71 END { p(lNF, 2, "</ul><hr>"); printf "</ul></nav></small><article>" }'} 72 fn add { 73 _l = $1^_^$#$1 74 $_l = $*(2-) 75 $1 = ($$1 $_l) 76 } 77 add bar sbar; run
cork-horizontal-sidebar.rc
1 #!/bin/rc 2 3 path=(. /bin) 4 5 req_p=`{echo -n $REQUEST_URI } 6 7 fn run { 8 lpaf=home$REQUEST_URI 9 rpafs='/'; wd='/'; ifs='/'; 10 arg = `{echo -n $REQUEST_URI} 11 if (test -d $lpaf) { 12 lpaf=$lpaf^'i' 13 } 14 for (i in $arg) { 15 wd=$wd^$i 16 rpafs=($rpafs $wd) 17 wd=$wd'/' 18 } 19 http_content_type='text/html' 20 echo Content-Type: $http_content_type 21 echo; 22 for (h in $bar) { $$h } 23 mh $lpaf.md 24 } 25 26 27 fn sbar { 28 echo -n 'insert html preamble' 29 ls -F home/./$rpafs | sed -e 's,/+\./+,/,g' \ 30 -e '/\/i\.(md)$/d' \ 31 -e 's/\.(md)$//' -e 's!^home!!' | sort | awk -F/ ' 32 function p(x, y, s) { for(i=0; i < x-y; i+=1) printf s } 33 BEGIN { lNF=2; printf "<ul>" } 34 { 35 d = "" 36 if(match($0, "/$")) 37 d = "/" 38 sub("/$", "") # Strip trailing / for dirs so NF is consistent 39 40 p(NF, lNF, "<ul>» 「"); p(lNF, NF, "」</ul>") 41 lNF = NF 42 43 bname = $NF d 44 path = $0 d 45 gsub(/[\-_]/, " ", bname) 46 47 # To avoid false matches add trailing / even for plain files to act as delimiter 48 pa = path 49 gsub(/[^\/]$/, "&/", pa) 50 51 if(index(ENVIRON["req_p"] "/", pa) == 1) 52 printf "<li><a href="path" class=\"c\">"bname"</a>" 53 else 54 printf "<li><a href="path">"bname"</a>" 55 } 56 END { p(lNF, 2, "</ul>"); printf "</ul></nav><hr><article>" }' 57 } 58 59 fn add { 60 _l = $1^_^$#$1 61 $_l = $*(2-) 62 $1 = ($$1 $_l) 63 } 64 65 add bar sbar; run
cork.rc
1 #!/bin/rc 2 3 path=(. /bin) 4 req_p=`{echo -n $REQUEST_URI } 5 fn run { 6 lpaf=home$REQUEST_URI 7 rpafs='/'; wd='/'; ifs='/'; 8 arg = `{echo -n $REQUEST_URI} 9 if (test -d $lpaf) { 10 lpaf=$lpaf^'i' 11 } 12 for (i in $arg) { 13 wd=$wd^$i 14 rpafs=($rpafs $wd) 15 wd=$wd'/' 16 } 17 http_content_type='text/html' 18 echo Content-Type: $http_content_type 19 echo; 20 for (h in $bar) { $$h } 21 mh $lpaf.md 22 } 23 fn sbar { 24 echo -n 'ENTER HTML PREAMBLE HERE' 25 ls -F home/./$rpafs | sed -e 's,/+\./+,/,g' \ 26 -e '/\/i\.(md)$/d' \ 27 -e 's/\.(md)$//' -e 's!^home!!' | sort | awk -F/ ' 28 function p(x, y, s) { for(i=0; i < x-y; i+=1) printf s } 29 BEGIN { lNF=2; printf "<ul>" } 30 { 31 d = "" 32 if(match($0, "/$")) 33 d = "/" 34 sub("/$", "") # Strip trailing / for dirs so NF is consistent 35 p(NF, lNF, " ⮧<ul>") 36 p(lNF, NF, "</ul><hr>") 37 lNF = NF 38 bname = $NF d 39 path = $0 d 40 gsub(/[\-_]/, " ", bname) 41 # Trailing / avoids false pattern matching 42 pa = path 43 gsub(/[^\/]$/, "&/", pa) 44 if(index(ENVIRON["req_p"] "/", pa) == 1) 45 printf "<li><a href="path" class=\"c\">"bname"</a>" 46 else 47 printf "<li><a href="path">"bname"</a>" 48 } 49 END { p(lNF, 2, "</ul>"); printf "</ul></nav><article>" }' 50 } 51 fn add { 52 _l = $1^_^$#$1 53 $_l = $*(2-) 54 $1 = ($$1 $_l) 55 } 56 add bar sbar; run
horizontal-sidebar.css
1 ul { 2 display: inline 3 } 4 li { 5 list-style-position: inside; 6 display: inline 7 } 8 ul { 9 margin: 0; 10 padding: 0.3em; 11 list-style-type: none; 12 list-style-image: none; 13 border: 0 14 } 15 li { 16 display: inline; 17 white-space: nowrap; 18 line-height: 1.6em 19 } 20 ul li a { 21 margin: 0; 22 padding: 0.1em 1ex 0.1em 1ex; 23 text-decoration: none; 24 font-size: 1em; 25 border: 0 26 } 27 ul > ul { 28 padding-left: 40px 29 }