From 0b3fd9c04c45856a2fa0886bd21b7d0aea7084b2 Mon Sep 17 00:00:00 2001 From: jolheiser Date: Sun, 9 May 2021 05:02:27 +0000 Subject: [PATCH] Add sakura for CSS (#12) Resolves #7 Reviewed-on: https://git.jojodev.com/jolheiser/vanity/pulls/12 Co-authored-by: jolheiser Co-committed-by: jolheiser --- .drone.yml | 43 ++++++ README.md | 3 + go.mod | 6 +- go.sum | 11 +- router/router.go | 7 +- router/templates.go | 29 ++++- router/templates/base.tmpl | 2 + router/templates/static/sakura.css | 202 +++++++++++++++++++++++++++++ 8 files changed, 283 insertions(+), 20 deletions(-) create mode 100644 .drone.yml create mode 100644 router/templates/static/sakura.css diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..6182b87 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,43 @@ +--- +kind: pipeline +name: compliance +trigger: + event: + - pull_request +steps: + - name: build + pull: always + image: golang:1.16 + commands: + - make test + - make build + - name: check + pull: always + image: golang:1.16 + commands: + - make vet + + +--- +kind: pipeline +name: release +trigger: + event: + - push + branch: + - main +steps: + - name: build + pull: always + image: golang:1.16 + commands: + - make build + - name: gitea-release + pull: always + image: jolheiser/drone-gitea-main:latest + settings: + token: + from_secret: gitea_token + base: https://git.jojodev.com + files: + - "vanity" \ No newline at end of file diff --git a/README.md b/README.md index edc23b8..d6d306e 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # Vanity +[![Go Reference](https://pkg.go.dev/badge/go.jolheiser.com/vanity.svg)](https://pkg.go.dev/go.jolheiser.com/vanity) +[![Build Status](https://ci.jojodev.com/api/badges/jolheiser/vanity/status.svg)](https://ci.jojodev.com/jolheiser/vanity) + A simple web service to serve [vanity Go imports](https://golang.org/cmd/go/#hdr-Remote_import_paths). Feel free to check it out using [my instance](https://go.jolheiser.com/). Vanity also supports [git-import](https://gitea.com/jolheiser/git-import). diff --git a/go.mod b/go.mod index 2da1ea9..981270b 100644 --- a/go.mod +++ b/go.mod @@ -7,13 +7,13 @@ replace go.jolheiser.com/vanity/go-vanity => ./go-vanity require ( github.com/AlecAivazis/survey/v2 v2.2.8 github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect - github.com/go-chi/chi v4.1.2+incompatible + github.com/go-chi/chi/v5 v5.0.3 github.com/urfave/cli/v2 v2.2.0 go.etcd.io/bbolt v1.3.5 go.jolheiser.com/beaver v1.0.2 - go.jolheiser.com/overlay v0.0.2 + go.jolheiser.com/overlay v0.0.3 go.jolheiser.com/vanity/go-vanity v0.0.0-00010101000000-000000000000 - golang.org/x/net v0.0.0-20200822124328-c89045814202 // indirect + golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect golang.org/x/sys v0.0.0-20200909081042-eff7692f9009 // indirect golang.org/x/text v0.3.3 // indirect ) diff --git a/go.sum b/go.sum index b1d1258..26fca36 100644 --- a/go.sum +++ b/go.sum @@ -8,8 +8,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/go-chi/chi v4.1.2+incompatible h1:fGFk2Gmi/YKXk0OmGfBh0WgmN3XB8lVnEyNz34tQRec= -github.com/go-chi/chi v4.1.2+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ= +github.com/go-chi/chi/v5 v5.0.3 h1:khYQBdPivkYG1s1TAzDQG1f6eX4kD2TItYVZexL5rS4= +github.com/go-chi/chi/v5 v5.0.3/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174 h1:WlZsjVhE8Af9IcZDGgJGQpNflI3+MJSBhsgT5PCtzBQ= github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174/go.mod h1:DqJ97dSdRW1W22yXSB90986pcOyQ7r45iio1KN2ez1A= github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs= @@ -36,22 +36,19 @@ go.etcd.io/bbolt v1.3.5 h1:XAzx9gjCb0Rxj7EoqcClPD1d5ZBxZJk0jbuoPHenBt0= go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ= go.jolheiser.com/beaver v1.0.2 h1:KA2D6iO8MQhZi1nZYi/Chak/f1Cxfrs6b1XO623+Khk= go.jolheiser.com/beaver v1.0.2/go.mod h1:7X4F5+XOGSC3LejTShoBdqtRCnPWcnRgmYGmG3EKW8g= -go.jolheiser.com/overlay v0.0.2 h1:cwEHLbWqdH7lEOG87WUwgUGVqfOWBsWe03FiHHmuTWE= -go.jolheiser.com/overlay v0.0.2/go.mod h1:xNbssakJ3HjK4RnjuP38q9yQNS4wxXKsyprYIWWr2bg= +go.jolheiser.com/overlay v0.0.3 h1:5WoXtnRi1w5KkU9xq+si/wV0GINOMJphfSOvgG2l53I= +go.jolheiser.com/overlay v0.0.3/go.mod h1:xNbssakJ3HjK4RnjuP38q9yQNS4wxXKsyprYIWWr2bg= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20200822124328-c89045814202 h1:VvcQYSHwXgi7W+TpUR6A9g6Up98WAHf3f/ulnJ62IyA= -golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190530182044-ad28b68e88f1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200909081042-eff7692f9009 h1:W0lCpv29Hv0UaM1LXb9QlBHLNP8UFfcKjblhVCWftOM= golang.org/x/sys v0.0.0-20200909081042-eff7692f9009/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/router/router.go b/router/router.go index 8720345..0d38e24 100644 --- a/router/router.go +++ b/router/router.go @@ -12,17 +12,18 @@ import ( "go.jolheiser.com/vanity/database" "go.jolheiser.com/vanity/go-vanity" - "github.com/go-chi/chi" - "github.com/go-chi/chi/middleware" + "github.com/go-chi/chi/v5" + "github.com/go-chi/chi/v5/middleware" "go.jolheiser.com/beaver" ) func New(token string, db *database.Database) *chi.Mux { r := chi.NewRouter() - r.Use(middleware.RedirectSlashes) r.Use(middleware.Recoverer) r.Use(middleware.Timeout(60 * time.Second)) + r.Mount("/_/", http.StripPrefix("/_/", static())) + r.Get("/", indexGET(db)) r.Options("/", infoPackages(db)) r.Post("/", addUpdatePackage(db, token)) diff --git a/router/templates.go b/router/templates.go index 8442df7..0191c20 100644 --- a/router/templates.go +++ b/router/templates.go @@ -3,37 +3,49 @@ package router import ( "embed" "html/template" + "io/fs" + "net/http" "os" "path/filepath" "runtime" + "strings" "go.jolheiser.com/overlay" + + "go.jolheiser.com/vanity/cmd/flags" ) var ( //go:embed templates templateFS embed.FS + ofs = overlay.MustNew(customRoot(), templateFS) Version string ) -func tmpl(name string) (*template.Template, error) { +func customRoot() string { bin, err := os.Executable() if err != nil { - return nil, err + bin = "" } customPath := os.Getenv("VANITY_CUSTOM") if customPath == "" { customPath = filepath.Join(bin, "custom") } + return customPath +} - ofs, err := overlay.New(customPath, templateFS) - if err != nil { - return nil, err - } - +func tmpl(name string) (*template.Template, error) { return template.New(name).Funcs(funcMap).ParseFS(ofs, "templates/base.tmpl", "templates/"+name) } +func static() http.Handler { + sub, err := fs.Sub(ofs, "templates/static") + if err != nil { + return nil + } + return http.FileServer(http.FS(sub)) +} + var funcMap = template.FuncMap{ "AppVer": func() string { return Version @@ -41,4 +53,7 @@ var funcMap = template.FuncMap{ "GoVer": func() string { return runtime.Version() }, + "Domain": func() string { + return strings.TrimSuffix(flags.Domain, "/") + }, } diff --git a/router/templates/base.tmpl b/router/templates/base.tmpl index b6a03a2..85a37fd 100644 --- a/router/templates/base.tmpl +++ b/router/templates/base.tmpl @@ -16,6 +16,8 @@ {{end}} Vanity - {{if .Package}}{{.Package.Name}}{{else}}Index{{end}} + +

Index

diff --git a/router/templates/static/sakura.css b/router/templates/static/sakura.css new file mode 100644 index 0000000..d73d1d8 --- /dev/null +++ b/router/templates/static/sakura.css @@ -0,0 +1,202 @@ +/* Sakura.css v1.3.1 + * ================ + * Minimal css theme. + * Project: https://github.com/oxalorg/sakura/ + */ +/* Body */ +:root { + --color-blossom: #1d7484; + --color-fade: #982c61; + --color-bg: #f9f9f9; + --color-bg-alt: #f1f1f1; + --color-text: #4a4a4a; +} + +@media (prefers-color-scheme: dark) { + :root { + --color-blossom: #ffffff; + --color-fade: #c9c9c9; + --color-bg: #222222; + --color-bg-alt: #4a4a4a; + --color-text: #c9c9c9; + } +} + +html { + font-size: 62.5%; + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif; } + +body { + font-size: 1.8rem; + line-height: 1.618; + max-width: 38em; + margin: auto; + color: var(--color-text); + background-color: var(--color-bg); + padding: 13px; } + +@media (max-width: 684px) { + body { + font-size: 1.53rem; } } + +@media (max-width: 382px) { + body { + font-size: 1.35rem; } } + +h1, h2, h3, h4, h5, h6 { + line-height: 1.1; + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif; + font-weight: 700; + margin-top: 3rem; + margin-bottom: 1.5rem; + overflow-wrap: break-word; + word-wrap: break-word; + -ms-word-break: break-all; + word-break: break-word; } + +h1 { + font-size: 2.35em; } + +h2 { + font-size: 2.00em; } + +h3 { + font-size: 1.75em; } + +h4 { + font-size: 1.5em; } + +h5 { + font-size: 1.25em; } + +h6 { + font-size: 1em; } + +p { + margin-top: 0px; + margin-bottom: 2.5rem; } + +small, sub, sup { + font-size: 75%; } + +hr { + border-color: var(--color-blossom); } + +a { + text-decoration: none; + color: var(--color-blossom); } +a:hover { + color: var(--color-fade); + border-bottom: 2px solid var(--color-text); } +a:visited { + color: var(--color-blossom); } + +ul { + padding-left: 1.4em; + margin-top: 0px; + margin-bottom: 2.5rem; } + +li { + margin-bottom: 0.4em; } + +blockquote { + margin-left: 0px; + margin-right: 0px; + padding-left: 1em; + padding-top: 0.8em; + padding-bottom: 0.8em; + padding-right: 0.8em; + border-left: 5px solid var(--color-blossom); + margin-bottom: 2.5rem; + background-color: var(--color-bg-alt); } + +blockquote p { + margin-bottom: 0; } + +img, video { + height: auto; + max-width: 100%; + margin-top: 0px; + margin-bottom: 2.5rem; } + +/* Pre and Code */ +pre { + background-color: var(--color-bg-alt); + display: block; + padding: 1em; + overflow-x: auto; + margin-top: 0px; + margin-bottom: 2.5rem; } + +code { + font-size: 0.9em; + padding: 0 0.5em; + background-color: var(--color-bg-alt); + white-space: pre-wrap; } + +pre > code { + padding: 0; + background-color: transparent; + white-space: pre; } + +/* Tables */ +table { + text-align: justify; + width: 100%; + border-collapse: collapse; } + +td, th { + padding: 0.5em; + border-bottom: 1px solid var(--color-bg-alt); } + +/* Buttons, forms and input */ +input, textarea { + border: 1px solid var(--color-text); } +input:focus, textarea:focus { + border: 1px solid var(--color-blossom); } + +textarea { + width: 100%; } + +.button, button, input[type="submit"], input[type="reset"], input[type="button"] { + display: inline-block; + padding: 5px 10px; + text-align: center; + text-decoration: none; + white-space: nowrap; + background-color: var(--color-blossom); + color: var(--color-bg); + border-radius: 1px; + border: 1px solid var(--color-blossom); + cursor: pointer; + box-sizing: border-box; } +.button[disabled], button[disabled], input[type="submit"][disabled], input[type="reset"][disabled], input[type="button"][disabled] { + cursor: default; + opacity: .5; } +.button:focus:enabled, .button:hover:enabled, button:focus:enabled, button:hover:enabled, input[type="submit"]:focus:enabled, input[type="submit"]:hover:enabled, input[type="reset"]:focus:enabled, input[type="reset"]:hover:enabled, input[type="button"]:focus:enabled, input[type="button"]:hover:enabled { + background-color: var(--color-fade); + border-color: var(--color-fade); + color: var(--color-bg); + outline: 0; } + +textarea, select, input { + color: var(--color-text); + padding: 6px 10px; + /* The 6px vertically centers text on FF, ignored by Webkit */ + margin-bottom: 10px; + background-color: var(--color-bg-alt); + border: 1px solid var(--color-bg-alt ); + border-radius: 4px; + box-shadow: none; + box-sizing: border-box; } +textarea:focus, select:focus, input:focus { + border: 1px solid var(--color-blossom); + outline: 0; } + +input[type="checkbox"]:focus { + outline: 1px dotted var(--color-blossom); } + +label, legend, fieldset { + display: block; + margin-bottom: .5rem; + font-weight: 600; } \ No newline at end of file