Align it better with newer werc

Signed-off-by: Sam Therapy <sam@samtherapy.net>
This commit is contained in:
Sam Therapy 2022-07-26 01:05:18 +02:00
parent b1fcdfc672
commit f355da34b0
Signed by: sam
GPG key ID: 4D8B07C18F31ACBD
8 changed files with 116 additions and 391 deletions

View file

@ -1,9 +1,9 @@
P=gowerc
SRC=bitbucket.org
USER?=mischief
GO_VERSION=1.6
SRC=git.froth.zone
USER?=fishe
GO_VERSION=1.18
all: $(USER)/$(P)
docker: $(USER)/$(P)
$(USER)/$(P): bin/$(P)
docker build -t "$(USER)/$(P):latest" .

View file

@ -12,7 +12,7 @@ clone of http://werc.cat-v.org/ in go.
### with go
go install git.froth.zone/sam/go2werc
go install git.froth.zone/sam/go2werc@latest
### in docker

61
main.go
View file

@ -13,7 +13,7 @@ import (
"net"
"net/http"
"os"
"path/filepath"
"path"
"sort"
"strings"
"time"
@ -32,6 +32,7 @@ type WercConfig struct {
MasterSite string
Title string
Subtitle string
Lang string
}
type MenuEntry struct {
@ -127,7 +128,7 @@ func ptitle(s string) string {
if idx := strings.LastIndex(s, "index"); idx != -1 {
s = s[:idx-1]
}
_, file := filepath.Split(s)
_, file := path.Split(s)
for _, suf := range []string{".md", ".txt", ".html"} {
if strings.HasSuffix(file, suf) {
return strings.TrimSuffix(file, suf)
@ -142,9 +143,9 @@ func (werc *Werc) genmenu(site, dir string) MenuEntries {
base := "sites/" + site
spl := strings.Split(strings.TrimPrefix(filepath.Clean(dir), "/"), string(filepath.Separator))
spl := strings.Split(strings.TrimPrefix(path.Clean(dir), "/"), "/")
_, current := filepath.Split(dir)
_, current := path.Split(dir)
if current != "" {
spl = spl[:len(spl)-1]
@ -155,7 +156,7 @@ func (werc *Werc) genmenu(site, dir string) MenuEntries {
dirs = append(dirs, "/")
for i := range spl {
path := "/" + filepath.Join(spl[:i+1]...)
path := "/" + path.Join(spl[:i+1]...)
dirs = append(dirs, path)
}
@ -164,14 +165,14 @@ func (werc *Werc) genmenu(site, dir string) MenuEntries {
var last MenuEntries
for i := range dirs {
var sub MenuEntries
b := filepath.Join(base, dirs[i])
b := path.Join(base, dirs[i])
fi, _ := readdir(werc.fs, b)
for _, f := range fi {
newname, ok := okmenu(b, f)
if !ok {
continue
}
me := &MenuEntry{Name: newname, Path: filepath.Join(dirs[i], newname)}
me := &MenuEntry{Name: newname, Path: path.Join(dirs[i], newname)}
if f.Mode().IsDir() {
me.Path = me.Path + "/"
me.Name = me.Name + "/"
@ -194,7 +195,7 @@ func (werc *Werc) genmenu(site, dir string) MenuEntries {
} else {
// mark directories as currently being browsed
for l, v := range last {
_, file := filepath.Split(dirs[i])
_, file := path.Split(dirs[i])
if v.Name == file+"/" {
last[l].This = true
last[l].Sub = sub
@ -319,12 +320,10 @@ func (werc *Werc) WercTXT(w http.ResponseWriter, r *http.Request, site, path str
werc.WercCommon(w, r, site, &WercPage{Title: ptitle(path), Content: template.HTML(buf.String())})
}
func (werc *Werc) Pub(w http.ResponseWriter, r *http.Request, path string) {
if strings.HasPrefix(path, "/") {
path = path[1:]
}
func (werc *Werc) Pub(w http.ResponseWriter, r *http.Request, route string) {
strings.TrimPrefix(route, "/")
b, err := readfile(werc.fs, path)
b, err := readfile(werc.fs, route)
if err != nil {
log.Printf("Pub: %v", err)
http.Error(w, err.Error(), 404)
@ -332,7 +331,7 @@ func (werc *Werc) Pub(w http.ResponseWriter, r *http.Request, path string) {
}
buf := bytes.NewReader(b)
http.ServeContent(w, r, filepath.Base(path), time.Now(), buf)
http.ServeContent(w, r, path.Base(route), time.Now(), buf)
log.Printf("pub sent %d bytes", len(b))
}
@ -343,29 +342,29 @@ func (werc *Werc) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if site == "" {
site = werc.conf.MasterSite
}
path := r.URL.Path
route := r.URL.Path
// try pub first
if strings.HasPrefix(path, "/pub") {
werc.Pub(w, r, path)
if strings.HasPrefix(route, "/pub") {
werc.Pub(w, r, route)
return
}
again:
base := "sites/" + site
if strings.HasSuffix(path, "/index") {
http.Redirect(w, r, strings.TrimSuffix(path, "/index"), http.StatusMovedPermanently)
if strings.HasSuffix(route, "/index") {
http.Redirect(w, r, strings.TrimSuffix(route, "/index"), http.StatusMovedPermanently)
return
}
if !strings.HasSuffix(path, "/") {
f, err := werc.fs.Open(base + path)
if !strings.HasSuffix(route, "/") {
f, err := werc.fs.Open(base + route)
if err == nil {
defer f.Close()
fi, err := f.Stat()
if err != nil && fi.IsDir() {
http.Redirect(w, r, path+"/", http.StatusMovedPermanently)
http.Redirect(w, r, route+"/", http.StatusMovedPermanently)
return
}
}
@ -382,12 +381,12 @@ again:
for suf, handler := range sufferring {
var tryfiles []string
if strings.HasSuffix(path, "/") {
if strings.HasSuffix(route, "/") {
for _, index := range indexFiles {
tryfiles = append(tryfiles, filepath.Join(base, path, index+"."+suf))
tryfiles = append(tryfiles, path.Join(base, route, index+"."+suf))
}
} else {
tryfiles = append(tryfiles, filepath.Join(base, path+"."+suf))
tryfiles = append(tryfiles, path.Join(base, route+"."+suf))
}
for _, f := range tryfiles {
@ -404,22 +403,22 @@ again:
}
}
if f, err := werc.fs.Open(base + path); err == nil {
if f, err := werc.fs.Open(base + route); err == nil {
defer f.Close()
st, _ := f.Stat()
if st.Mode().IsDir() {
// directory handling
log.Printf("d %s", base+path)
werc.WercDir(w, r, site, base+path)
log.Printf("d %s", base+route)
werc.WercDir(w, r, site, base+route)
return
}
// plain file handling
log.Printf("f %s", base+path)
log.Printf("f %s", base+route)
// ripped from http.serveContent
ctype := mime.TypeByExtension(filepath.Ext(path))
ctype := mime.TypeByExtension(path.Ext(route))
if ctype == "" {
// read a chunk to decide between utf-8 text and binary
var buf [512]byte
@ -442,7 +441,7 @@ again:
goto again
}
log.Printf("404 %s", path)
log.Printf("404 %s", route)
http.NotFound(w, r)
}

View file

@ -1,5 +1,5 @@
<!DOCTYPE html>
<html>
<html lang={{.Config.Lang}}>
<head>
<title>{{.Title}}</title>
@ -25,28 +25,24 @@
</head>
<body>
<div id="header">
<div class="superHeader">
<header>
{{template "topbar.html"}}
</div>
<div class="midHeader">
<h1 class="headerTitle"><a href="/">{{.Config.Title}}</a><span id="headerSubTitle">{{.Config.Subtitle}}</span></h1>
</div>
<div class="subHeader">
<br>
</div>
</div>
<h1><a href="/">{{.Config.Title}}<span id="headerSubTitle">{{.Config.Subtitle}}</span></a></h1>
<div id="side-bar">
<!-- <div class="subHeader">
<br> -->
</div>
</header>
<nav id="side-bar">
<div>
{{template "menu.html" .Menu}}
</div>
</div>
<div id="main-copy">
</nav>
<article>
{{.Content}}
</div>
</article>
<!--
% run_handlers $handlers_body_head
@ -55,9 +51,9 @@
% run_handlers $handlers_body_foot
-->
<div id="footer">
<footer>
{{template "footer.html"}}
</div>
</footer>
</body>
</html>

View file

@ -1,4 +1,4 @@
<div class="left"><a href="https://git.froth.zone/sam/go2werc">Powered by gowerc</a></div>
<div class="left"><a href="https://git.froth.zone/sam/go2werc">Powered by go2werc</a></div>
<div class="right"></div>
<br class="doNotPrint">

View file

@ -1,11 +1,11 @@
<div class='left'>
<a href="/sitemap">site map</a><span> | </span>
<a href='http://9.offblast.org/'>9.offblast.org</a><span> | </span>
<a href='https://mindlock.us/'>mindlock.us</a><span> | </span>
<a href='https://github.com/mischief'>github</a><span> | </span>
<a href='https://bitbucket.org/mischief'>bitbucket</a>
<nav>
<div class='left'>
<a href="/sitemap">site map</a> |
<a href='https://9p.io/'>9p.io</a> |
<a href='https://git.froth.zone/sam'>gitea</a> |
</div>
<div class="right">
</div>
</nav>

View file

@ -1,330 +1,11 @@
/* Default werc style */
body {
color: black;
background-color: white;
font-family: Helvetica, Verdana, Arial, 'Liberation Sans', FreeSans, sans-serif;
font-size: 84%; /* Enables font size scaling in MSIE */
margin: 0;
padding: 0;
}
/* # Header # */
.superHeader {
color: white;
background-color: rgb(100,135,220);
height: 1.6em;
}
.superHeader img { vertical-align: bottom; }
.superHeader a {
color: white;
background-color: transparent;
font-size: 91%;
margin: 0;
padding: 0 0.5ex 0 0.25ex;
}
a { text-decoration: none; }
a:hover { text-decoration: underline; }
.superHeader div {
position: absolute;
top: 0.40ex;
}
.superHeader .left { left: 0.4em; }
.superHeader .right { right: 0.4em; }
.midHeader {
color: rgb(39,78,144);
background-color: rgb(140,170,230);
background-color: #ff6d06;
border: solid 0 black;
border-width: 2px 0;
}
.headerTitle {
color: black;
font-size: 233%;
font-weight: normal;
margin: 0 0 0 4mm;
padding: 0.25ex 0;
}
#headerSubTitle {
font-size: 50%;
font-style: italic;
margin-left: 1em;
}
.headerTitle a { color: black; }
.headerTitle a:hover { text-decoration: none; }
.subHeader {
display: none;
color: white;
background-color: rgb(0,51,153);
margin: 0;
padding: 1ex 1ex 1ex 1.5mm;
}
.subHeader a {
color: white;
background-color: transparent;
font-weight: bold;
margin: 0;
padding: 0 0.75ex 0 0.5ex;
}
.superHeader .highlight, .subHeader .highlight {
color: rgb(253,160,91);
background-color: transparent;
}
/* # Side # */
#side-bar {
width: 16em;
float: left;
clear: left;
border-right: 1px solid #ddd;
}
#side-bar div {
border-bottom: 1px solid #ddd;
}
.sideBarTitle {
font-weight: bold;
margin: 0 0 0.5em 2mm;
padding: 1em 0 0 0;
}
#side-bar ul {
list-style-type: none;
list-style-position: outside;
margin: 0;
padding: 0 0 0.3em 0;
}
li ul {
padding-left: 0.6em !important;
}
#side-bar li {
margin: 0;
padding: 0.1ex 0; /* Circumvents a rendering bug (?) in MSIE 6.0 XXX should move to iehacks.css, this causes an ugly gap */
}
#side-bar a {
color: rgb(0,102,204);
background-color: transparent;
margin: 0;
padding: 0.25em 1ex 0.25em 2mm;
display: block;
text-transform: capitalize;
font-weight: bold!important;
font-size: 102%;
border-left: white solid 0.2em;
}
.thisPage, .thisPage a {
color: black!important;
background-color: white;
padding-left: 5mm;
}
#side-bar a:hover {
color: white;
background-color: rgb(100,135,220);
border-left: black solid 0.2em;
text-decoration: none;
}
.sideBarText {
line-height: 1.5em;
margin: 0 0 1em 0;
padding: 0 1.5ex 0 2.5mm;
display: block;
}
#side-bar .sideBarText a {
margin: 0;
padding: 0;
display: inline;
}
#side-bar .sideBarText a:hover {
color: rgb(0,102,204);
background-color: transparent;
text-decoration: none;
}
/* # Main Copy # */
#main-copy {
max-width: 70em;
color: black;
background-color: transparent;
text-align: justify;
line-height: 1.5em;
margin: 0em 0 0 16em;
padding: 0.5mm 5mm 5mm 5mm;
border-left: 1px solid #ddd;
}
#bodyText {
margin: 0 0 0 15.5em;
padding: 2mm 5mm 2mm 5mm;
}
#main-copy p {
margin: 1em 1ex 1em 1ex !important; /* Need !important so troff-generated pages don't look totally squezed */
padding: 0;
}
#main-copy a {
color: rgb(0,102,204);
background-color: transparent;
}
#main-copy a:hover {
color: rgb(100,135,220);
}
#main-copy h1, #main-copy h2 {
color: rgb(0,102,204);
background-color: transparent;
font-size: 145.5%;
font-weight: bold;
margin: 2em 0 0 0;
padding: 0.5ex 0 0.5ex 0.6ex;
border-bottom: 2px solid rgb(0,102,204);
}
#main-copy h2 {
font-size: 115.5%;
border-bottom: 1px solid rgb(0,102,204);
}
#main-copy .topOfPage {
color: rgb(0,102,204);
background-color: transparent;
font-size: 91%;
font-weight: bold;
text-decoration: none;
margin: 3ex 1ex 0 0;
padding: 0;
float: right;
}
dl {
margin: 1em 1ex 2em 1ex;
padding: 0;
}
dt {
font-weight: bold;
margin: 0 0 0 0;
padding: 0;
}
dd {
margin: 0 0 2em 2em;
padding: 0;
}
/* # Footer # */
#footer {
color: white;
background-color: rgb(100,135,220);
padding: 1em;
clear: both;
}
#footer .left {
text-align: left;
line-height: 1.55em;
float: left;
clear: left;
}
#footer .right {
text-align: right;
line-height: 1.45em;
}
#footer a {
color: white;
background-color: transparent;
}
/* GENERAL */
table {
border: solid 1px black;
}
th {
background-color: #abc;
border: solid 1px black;
text-align: center;
}
td {
background-color: #def;
border: solid 1px black;
}
hr {
border-width: 0px 0px 0.1em 0px;
border-color: black;
}
acronym, .titleTip {
border-bottom: 1px solid #ddd;
cursor: help;
margin: 0;
padding: 0 0 0.4px 0;
}
pre {
margin-left: 2em;
font-size: 1.2em;
}
blockquote {
border-left: 1px solid blue;
font-style: italic;
}
.smallCaps {
font-size: 110%;
font-variant: small-caps;
}
.doNotDisplay { display: none; }
.notify_errors,
.notify_notes,
.notify_success { padding: .8em; margin-bottom: 1em; border: 2px solid #ddd; }
.notify_errors { background: #FBE3E4; color: #8a1f11; border-color: #FBC2C4; }
.notify_notes { background: #FFF6BF; color: #514721; border-color: #FFD324; }
.notify_success { background: #E6EFC2; color: #264409; border-color: #C6D880; }
.notify_errors a { color: #8a1f11; }
.notify_notes a { color: #514721; }
.notify_success a { color: #264409; }
/* # Page/Handler specific # */
h1.dir-list-head, ul.dir-list {
text-transform: capitalize;
font-weight: bold;
}
ul.sitemap-list a {
text-transform: capitalize;
}
body { display: flex; flex-wrap: wrap; font-family: sans; }
header { flex-basis: 100%; flex-shrink: 0; }
article { flex-basis: 60%; padding-left: 1em; }
footer { flex-basis: 100%; flex-shrink: 0; }
header nav { display: flex; justify-content: space-between; }
nav a, header a { text-decoration: none ; color: inherit; }
header h1 span { margin-left: 1em; font-size: 50%; font-style: italic; }
body > nav { flex-basis: content; padding-right: 1vw; min-width: 16em; }
nav ul { display: flex; flex-direction: column; list-style-type: none; list-style-position: outside; padding-left: 0; }
nav li ul { padding-left: 0.6em }
footer { display: flex; justify-content: space-between; }

View file

@ -0,0 +1,49 @@
body { display: flex; flex-wrap: wrap; font-family: sans; }
header { flex-basis: 100%; flex-shrink: 0; }
article { flex-basis: 60%; padding-left: 1em; }
footer { flex-basis: 100%; flex-shrink: 0; }
header nav { display: flex; justify-content: space-between; }
nav a, header a { text-decoration: none ; color: inherit; }
header h1 span { margin-left: 1em; font-size: 50%; font-style: italic; }
body > nav { flex-basis: content; padding-right: 1vw; min-width: 16em; }
nav ul { display: flex; flex-direction: column; list-style-type: none; list-style-position: outside; padding-left: 0; }
nav li ul { padding-left: 0.6em }
footer { display: flex; justify-content: space-between; }
/* cut here to leave vanity behind */
body { margin:0; padding: 0; font-size: 84%; font-family: Helvetica, Verdana, Arial, 'Liberation Sans', FreeSans, sans-serif; }
a { text-decoration: none; color: }
a:hover { text-decoration: underline; }
.thisPage { color: black; }
/* header and top bar */
header nav { background-color: rgb(100,135,220); color: white; padding: 0.3em; border-bottom: 2px solid black; font-size: 91%; }
header h1 { background-color: #ff6d06; color: black; margin: 0; border-bottom: 2px solid black; font-weight: normal; padding: 0.25ex; font-size: 233%; }
header a:hover { text-decoration: none; }
/* sidebar */
body > nav { border-right: 1px solid #ddd; padding: 0; }
body > nav > div { border-bottom: 1px solid #ddd; }
body > nav > div a { color: rgb(0, 102, 204); display: block; text-transform: capitalize; font-weight: bold; padding: 0.25em 1ex 0.25em 2mm; font-size: 102%}
body > nav > div a:hover { color: white; background-color: rgb(100,135,220); border-left: black solid 0.2em; text-decoration: none; }
body > nav > div p { font-weight: bold; margin: 0 0 0.5em 2mm; padding: 1em 0 0 0; }
/* main copy */
article { padding: 0.5ex 0 5vh 1vw; }
article h1, article h2 { color: rgb(0,102,204); font-weight: bold; margin: 2em 0 0 0; border-bottom: 2px solid rgb(0,102,204); }
article h3, article h4, article h5 { color: rgb(0,102,204); font-weight: bold; margin: 2em 0 0 0; }
article h6, article h7, article h8 { color: rgb(0,102,204); font-weight: bold; margin: 2em 0 0 0; }
article a { color: rgb(0,102,204); }
article a:hover { color: rgb(100,135,220); }
/* footer */
footer { color: white; background-color: rgb(100,135,220); }
footer a { color: inherit; }
footer div { padding: 1em; }
/* tables */
table { border: 1px solid rgba(128,128,128,0.5); padding: 0; }
th { color: white; background-color: rgb(100,135,220); }
tr:nth-child(odd) { background-color: rgba(128,128,128,0.1) }