From adca4d518eea9533e6054666ce6e5681c5a6f196 Mon Sep 17 00:00:00 2001 From: Feuerfuchs Date: Tue, 4 Jun 2019 19:58:44 +0200 Subject: Add custom styles --- Dockerfile | 8 +++--- Makefile | 1 + README.md | 6 ++-- assets/IBMPlexMono-Regular.woff | Bin 0 -> 50664 bytes assets/IBMPlexMono-Regular.woff2 | Bin 0 -> 35536 bytes assets/style.css | 1 + css/main.scss | 58 +++++++++++++++++++++++++++++++++++++++ go.mod | 2 +- gopherproxy.go | 18 ++++++++++-- template.go | 13 +++++---- 10 files changed, 92 insertions(+), 15 deletions(-) create mode 100644 assets/IBMPlexMono-Regular.woff create mode 100644 assets/IBMPlexMono-Regular.woff2 create mode 100644 assets/style.css create mode 100644 css/main.scss diff --git a/Dockerfile b/Dockerfile index e173197..8072728 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,10 +8,10 @@ RUN \ apk add --update git && \ rm -rf /var/cache/apk/* -RUN mkdir -p /go/src/github.com/prologic/gopherproxy -WORKDIR /go/src/github.com/prologic/gopherproxy +RUN mkdir -p /go/src/git.feuerfuchs.dev/Feuerfuchs/gopherproxy +WORKDIR /go/src/git.feuerfuchs.dev/Feuerfuchs/gopherproxy -COPY . /go/src/github.com/prologic/gopherproxy +COPY . /go/src/git.feuerfuchs.dev/Feuerfuchs/gopherproxy RUN go get -v -d -RUN go install -v github.com/prologic/gopherproxy/... +RUN go install -v git.feuerfuchs.dev/Feuerfuchs/gopherproxy/... diff --git a/Makefile b/Makefile index 12850e1..c2151ad 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,7 @@ dev: build ./gopherproxy -bind 127.0.0.1:8000 build: clean + sassc -t compressed css/main.scss assets/style.css go build -o ./gopherproxy ./cmd/gopherproxy/main.go profile: diff --git a/README.md b/README.md index 7215e2b..4b89136 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,8 @@ [![Build Status](https://cloud.drone.io/api/badges/prologic/gopherproxy/status.svg)](https://cloud.drone.io/prologic/gopherproxy) [![CodeCov](https://codecov.io/gh/prologic/gopherproxy/branch/master/graph/badge.svg)](https://codecov.io/gh/prologic/gopherproxy) [![Go Report Card](https://goreportcard.com/badge/prologic/gopherproxy)](https://goreportcard.com/report/prologic/gopherproxy) -[![GoDoc](https://godoc.org/github.com/prologic/gopherproxy?status.svg)](https://godoc.org/github.com/prologic/gopherproxy) -[![Sourcegraph](https://sourcegraph.com/github.com/prologic/gopherproxy/-/badge.svg)](https://sourcegraph.com/github.com/prologic/gopherproxy?badge) +[![GoDoc](https://godoc.org/git.feuerfuchs.dev/Feuerfuchs/gopherproxy?status.svg)](https://godoc.org/git.feuerfuchs.dev/Feuerfuchs/gopherproxy) +[![Sourcegraph](https://sourcegraph.com/git.feuerfuchs.dev/Feuerfuchs/gopherproxy/-/badge.svg)](https://sourcegraph.com/git.feuerfuchs.dev/Feuerfuchs/gopherproxy?badge) gopherproxy is a Gopher (RFC 1436) Web Proxy that acts as a gateway into Gopherspace by proxying standard Web HTTP requests to Gopher requests of the target server. @@ -16,7 +16,7 @@ Demo: https://gopher.mills.io/ ## Installation - $ go install github.com/prologic/gopherproxy/... + $ go install git.feuerfuchs.dev/Feuerfuchs/gopherproxy/... ### Docker diff --git a/assets/IBMPlexMono-Regular.woff b/assets/IBMPlexMono-Regular.woff new file mode 100644 index 0000000..7d63d89 Binary files /dev/null and b/assets/IBMPlexMono-Regular.woff differ diff --git a/assets/IBMPlexMono-Regular.woff2 b/assets/IBMPlexMono-Regular.woff2 new file mode 100644 index 0000000..d0d7ded Binary files /dev/null and b/assets/IBMPlexMono-Regular.woff2 differ diff --git a/assets/style.css b/assets/style.css new file mode 100644 index 0000000..70b1998 --- /dev/null +++ b/assets/style.css @@ -0,0 +1 @@ +@font-face{font-family:'IBM Plex Mono';font-style:normal;font-weight:normal;src:url("/assets/IBMPlexMono-Regular.woff2") format("woff2"),url("/assets/IBMPlexMono-Regular.woff") format("woff")}body{background-color:#14171a;color:#cad1d8}.wrap{text-align:center}.content{display:inline-block;min-width:50em;margin:0;padding:2em 1em;text-align:left;font-family:'IBM Plex Mono', 'Fira Code', 'Fira Mono', 'Roboto Mono', 'Droid Sans Mono', Monaco, Consolas, Courier, monospace;font-size:1em;line-height:1.5}::selection{color:#000;background-color:#cad1d8}:link{color:#fff}:visited{color:#cad1d8}:link:hover,:visited:hover{color:#fff}.link-type{color:#929ba3} diff --git a/css/main.scss b/css/main.scss new file mode 100644 index 0000000..dfda503 --- /dev/null +++ b/css/main.scss @@ -0,0 +1,58 @@ +$background: hsl(210, 14%, 9%); +$text: mix(hsl(210, 60%, 95%), $background, 85%); +$text-minus: mix(hsl(210, 100%, 95%), $background, 60%); +$text-faint: mix(hsl(210, 100%, 95%), $background, 40%); +$text-plus: #fff; +$sel-background: $text; +$sel-text: #000; + +@font-face { + font-family: 'IBM Plex Mono'; + font-style: normal; + font-weight: normal; + src: url('/assets/IBMPlexMono-Regular.woff2') format('woff2'), + url('/assets/IBMPlexMono-Regular.woff') format('woff'); +} + +body { + background-color: $background; + color: $text; +} + +.wrap { + text-align: center; +} + +.content { + display: inline-block; + min-width: 50em; + margin: 0; + padding: 2em 1em; + text-align: left; + font-family: 'IBM Plex Mono', 'Fira Code', 'Fira Mono', 'Roboto Mono', 'Droid Sans Mono', Monaco, Consolas, Courier, monospace; + font-size: 1em; + line-height: 1.5; +} + +::selection { + color: $sel-text; + background-color: $sel-background; +} + +:link { + color: $text-plus; +} + +:visited { + color: $text; +} + +:link, :visited { + &:hover { + color: $text-plus; + } +} + +.link-type { + color: $text-minus; +} diff --git a/go.mod b/go.mod index fa60472..7c178d3 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/prologic/gopherproxy +module git.feuerfuchs.dev/Feuerfuchs/gopherproxy require ( github.com/prologic/go-gopher v0.0.0-20181230133552-0c68ed5f58b0 diff --git a/gopherproxy.go b/gopherproxy.go index 42f67cf..6f1e8ec 100644 --- a/gopherproxy.go +++ b/gopherproxy.go @@ -1,6 +1,7 @@ package gopherproxy import ( + "bytes" "fmt" "html/template" "io" @@ -73,7 +74,8 @@ func renderDirectory(w http.ResponseWriter, tpl *template.Template, hostport str return tpl.Execute(w, struct { Title string Lines []Item - }{title, out}) + RawText string + }{title, out, ""}) } // GopherHandler returns a Handler that proxies requests @@ -125,7 +127,18 @@ func GopherHandler(tpl *template.Template, robotsdata *robotstxt.RobotsData, uri } if res.Body != nil { - io.Copy(w, res.Body) + if strings.HasSuffix(uri, ".txt") { + // handle .txt files + buf := new(bytes.Buffer) + buf.ReadFrom(res.Body) + tpl.Execute(w, struct { + Title string + RawText string + Lines []Item + }{uri, buf.String(), nil}) + } else { + io.Copy(w, res.Body) + } } else { if err := renderDirectory(w, tpl, hostport, res.Dir); err != nil { io.WriteString(w, fmt.Sprintf("Error:
%s
", err)) @@ -186,6 +199,7 @@ func ListenAndServe(bind, robotsfile, uri string) error { http.HandleFunc("/", GopherHandler(tpl, robotsdata, uri)) http.HandleFunc("/robots.txt", RobotsTxtHandler(robotstxtdata)) + http.Handle("/assets/", http.StripPrefix("/assets/", http.FileServer(http.Dir("assets/")))) return http.ListenAndServe(bind, nil) } diff --git a/template.go b/template.go index 40b9c31..b42f811 100644 --- a/template.go +++ b/template.go @@ -6,13 +6,16 @@ var tpltext = ` {{.Title}} + + + -
-
-{{range .Lines}} {{if .Link}}({{.Type}}) {{.Text}}{{else}}      {{.Text}}{{end}}
-{{end}}
-
+
+
+{{if .Lines}}{{range .Lines}} {{if .Link}}({{.Type}}) {{.Text}}{{else}}      {{.Text}}{{end}}
+{{end}}{{else}}{{.RawText}}{{end}}
+