aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFeuerfuchs <git@feuerfuchs.dev>2019-06-20 18:16:12 +0200
committerFeuerfuchs <git@feuerfuchs.dev>2019-06-20 18:16:12 +0200
commit6f07c75f2ae1c3b164b66c2d7ed5fde242f8a744 (patch)
tree1fab37a8902d9fb0746db6144f1a43d091cd70be
parentMake output about ignored robots.txt optional (diff)
downloadgopherproxy-6f07c75f2ae1c3b164b66c2d7ed5fde242f8a744.tar.gz
gopherproxy-6f07c75f2ae1c3b164b66c2d7ed5fde242f8a744.tar.bz2
gopherproxy-6f07c75f2ae1c3b164b66c2d7ed5fde242f8a744.zip
Add navigation header
-rw-r--r--assets/style.css2
-rw-r--r--css/main.scss50
-rw-r--r--go.sum3
-rw-r--r--gopherproxy.go17
-rw-r--r--template.go22
5 files changed, 73 insertions, 21 deletions
diff --git a/assets/style.css b/assets/style.css
index 665be39..8841dae 100644
--- a/assets/style.css
+++ b/assets/style.css
@@ -1 +1 @@
@font-face{font-family:'Iosevka Term SS03';font-style:normal;font-weight:normal;src:url("/iosevka-term-ss03-regular.woff2") format("woff2"),url("/iosevka-term-ss03-regular.woff") format("woff")}body{margin:0;padding:0;background-color:#14171a;color:#cad1d8}.wrap{text-align:center}.content{display:inline-block;min-width:50em;min-width:85ch;margin:0;padding:2em 1em;text-align:left;font-family:'Iosevka Term SS03', 'IBM Plex Mono', 'Fira Code', 'Fira Mono', 'Roboto Mono', 'Droid Sans Mono', Monaco, Consolas, Courier, monospace;font-size:1.0625em;line-height:1.5}::selection{color:#000;background-color:rgba(239,198,138,0.996)}:link{color:#fff}:visited{color:#cad1d8}.link-type{color:#929ba3} @font-face{font-family:'Iosevka Term SS03';font-style:normal;font-weight:normal;src:url("/iosevka-term-ss03-regular.woff2") format("woff2"),url("/iosevka-term-ss03-regular.woff") format("woff")}body{margin:0;padding:0;background-color:#14171a;color:#cad1d8}::selection{color:#000;background-color:rgba(239,198,138,0.996)}:link{color:#fff}:visited{color:#cad1d8}.header{padding:1em;border-bottom:1px solid #353a3f;font-family:'Iosevka Term SS03', 'IBM Plex Mono', 'Fira Code', 'Fira Mono', 'Roboto Mono', 'Droid Sans Mono', Monaco, Consolas, Courier, monospace;font-size:1.0625em;line-height:1.1;color:#686f76}.header__uripart{color:#929ba3}.header__uripart--last{color:#fff}.wrap{text-align:center}.content{display:inline-block;min-width:50em;min-width:85ch;margin:0;padding:2em 1em;text-align:left;font-family:'Iosevka Term SS03', 'IBM Plex Mono', 'Fira Code', 'Fira Mono', 'Roboto Mono', 'Droid Sans Mono', Monaco, Consolas, Courier, monospace;font-size:1.0625em;line-height:1.5}.link-type{color:#929ba3}
diff --git a/css/main.scss b/css/main.scss
index 367f2d7..61787b5 100644
--- a/css/main.scss
+++ b/css/main.scss
@@ -6,6 +6,7 @@ $text-faint: mix(hsl(210, 100%, 95%), $background, 40%);
6$text-plus: #fff; 6$text-plus: #fff;
7$link-idle: $text-plus; 7$link-idle: $text-plus;
8$link-visited: $text; 8$link-visited: $text;
9$border: mix(hsl(210, 100%, 95%), $background, 16%);
9$sel-background: rgba($accent, .996); 10$sel-background: rgba($accent, .996);
10$sel-text: #000; 11$sel-text: #000;
11 12
@@ -30,22 +31,6 @@ body {
30 color: $text; 31 color: $text;
31} 32}
32 33
33.wrap {
34 text-align: center;
35}
36
37.content {
38 display: inline-block;
39 min-width: 50em;
40 min-width: 5ch + 80;
41 margin: 0;
42 padding: 2em 1em;
43 text-align: left;
44 font-family: 'Iosevka Term SS03', 'IBM Plex Mono', 'Fira Code', 'Fira Mono', 'Roboto Mono', 'Droid Sans Mono', Monaco, Consolas, Courier, monospace;
45 font-size: 1 / 16 * 17em;
46 line-height: 1.5;
47}
48
49::selection { 34::selection {
50 color: $sel-text; 35 color: $sel-text;
51 background-color: $sel-background; 36 background-color: $sel-background;
@@ -65,6 +50,39 @@ body {
65// } 50// }
66// } 51// }
67 52
53.header {
54 padding: 1em;
55 border-bottom: 1px solid $border;
56 font-family: 'Iosevka Term SS03', 'IBM Plex Mono', 'Fira Code', 'Fira Mono', 'Roboto Mono', 'Droid Sans Mono', Monaco, Consolas, Courier, monospace;
57 font-size: 1 / 16 * 17em;
58 line-height: 1.1;
59 color: $text-faint;
60}
61
62.header__uripart {
63 color: $text-minus;
64}
65
66.header__uripart--last {
67 color: $text-plus;
68}
69
70.wrap {
71 text-align: center;
72}
73
74.content {
75 display: inline-block;
76 min-width: 50em;
77 min-width: 5ch + 80;
78 margin: 0;
79 padding: 2em 1em;
80 text-align: left;
81 font-family: 'Iosevka Term SS03', 'IBM Plex Mono', 'Fira Code', 'Fira Mono', 'Roboto Mono', 'Droid Sans Mono', Monaco, Consolas, Courier, monospace;
82 font-size: 1 / 16 * 17em;
83 line-height: 1.5;
84}
85
68.link-type { 86.link-type {
69 color: $text-minus; 87 color: $text-minus;
70} 88}
diff --git a/go.sum b/go.sum
index 7eb5a57..89aa345 100644
--- a/go.sum
+++ b/go.sum
@@ -1,4 +1,5 @@
1github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 1github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 3github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3github.com/gobuffalo/attrs v0.0.0-20190224210810-a9411de4debd/go.mod h1:4duuawTqi2wkkpB4ePgWMaai6/Kc6WEz83bhFwpHzj0= 4github.com/gobuffalo/attrs v0.0.0-20190224210810-a9411de4debd/go.mod h1:4duuawTqi2wkkpB4ePgWMaai6/Kc6WEz83bhFwpHzj0=
4github.com/gobuffalo/depgen v0.0.0-20190329151759-d478694a28d3/go.mod h1:3STtPUQYuzV0gBVOY3vy6CfMm/ljR4pABfrTeHNLHUY= 5github.com/gobuffalo/depgen v0.0.0-20190329151759-d478694a28d3/go.mod h1:3STtPUQYuzV0gBVOY3vy6CfMm/ljR4pABfrTeHNLHUY=
@@ -35,6 +36,7 @@ github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kN
35github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 36github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
36github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= 37github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
37github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 38github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
39github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
38github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 40github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
39github.com/prologic/go-gopher v0.0.0-20181230133552-0c68ed5f58b0 h1:10LO/S8HVjIuEHsHea//Cena1Ztgy23f/e8HFC0w5ow= 41github.com/prologic/go-gopher v0.0.0-20181230133552-0c68ed5f58b0 h1:10LO/S8HVjIuEHsHea//Cena1Ztgy23f/e8HFC0w5ow=
40github.com/prologic/go-gopher v0.0.0-20181230133552-0c68ed5f58b0/go.mod h1:LiuwIXz4es4YIUOD6yRv8mES9n9dFbe4z0+TcrLkhXg= 42github.com/prologic/go-gopher v0.0.0-20181230133552-0c68ed5f58b0/go.mod h1:LiuwIXz4es4YIUOD6yRv8mES9n9dFbe4z0+TcrLkhXg=
@@ -49,6 +51,7 @@ github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnIn
49github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 51github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
50github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 52github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
51github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 53github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
54github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
52github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 55github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
53github.com/temoto/robotstxt v0.0.0-20180810133444-97ee4a9ee6ea h1:hH8P1IiDpzRU6ZDbDh/RDnVuezi2oOXJpApa06M0zyI= 56github.com/temoto/robotstxt v0.0.0-20180810133444-97ee4a9ee6ea h1:hH8P1IiDpzRU6ZDbDh/RDnVuezi2oOXJpApa06M0zyI=
54github.com/temoto/robotstxt v0.0.0-20180810133444-97ee4a9ee6ea/go.mod h1:aOux3gHPCftJ3KHq6Pz/AlDjYJ7Y+yKfm1gU/3B0u04= 57github.com/temoto/robotstxt v0.0.0-20180810133444-97ee4a9ee6ea/go.mod h1:aOux3gHPCftJ3KHq6Pz/AlDjYJ7Y+yKfm1gU/3B0u04=
diff --git a/gopherproxy.go b/gopherproxy.go
index 961806a..8ba515e 100644
--- a/gopherproxy.go
+++ b/gopherproxy.go
@@ -25,7 +25,7 @@ type Item struct {
25 Text string 25 Text string
26} 26}
27 27
28func renderDirectory(w http.ResponseWriter, tpl *template.Template, styletext string, hostport string, d gopher.Directory) error { 28func renderDirectory(w http.ResponseWriter, tpl *template.Template, styletext string, uri string, hostport string, d gopher.Directory) error {
29 var title string 29 var title string
30 30
31 out := make([]Item, len(d.Items)) 31 out := make([]Item, len(d.Items))
@@ -76,10 +76,11 @@ func renderDirectory(w http.ResponseWriter, tpl *template.Template, styletext st
76 76
77 return tpl.Execute(w, struct { 77 return tpl.Execute(w, struct {
78 Title string 78 Title string
79 URI string
79 Style string 80 Style string
80 Lines []Item 81 Lines []Item
81 RawText string 82 RawText string
82 }{title, styletext, out, ""}) 83 }{title, fmt.Sprintf("%s/%s", hostport, uri), styletext, out, ""})
83} 84}
84 85
85// GopherHandler returns a Handler that proxies requests 86// GopherHandler returns a Handler that proxies requests
@@ -137,15 +138,16 @@ func GopherHandler(tpl *template.Template, robotsdata *robotstxt.RobotsData, rob
137 buf.ReadFrom(res.Body) 138 buf.ReadFrom(res.Body)
138 tpl.Execute(w, struct { 139 tpl.Execute(w, struct {
139 Title string 140 Title string
141 URI string
140 Style string 142 Style string
141 RawText string 143 RawText string
142 Lines []Item 144 Lines []Item
143 }{uri, styletext, buf.String(), nil}) 145 }{uri, fmt.Sprintf("%s/%s", hostport, uri), styletext, buf.String(), nil})
144 } else { 146 } else {
145 io.Copy(w, res.Body) 147 io.Copy(w, res.Body)
146 } 148 }
147 } else { 149 } else {
148 if err := renderDirectory(w, tpl, styletext, hostport, res.Dir); err != nil { 150 if err := renderDirectory(w, tpl, styletext, uri, hostport, res.Dir); err != nil {
149 io.WriteString(w, fmt.Sprintf("<b>Error:</b><pre>%s</pre>", err)) 151 io.WriteString(w, fmt.Sprintf("<b>Error:</b><pre>%s</pre>", err))
150 return 152 return
151 } 153 }
@@ -258,6 +260,13 @@ func ListenAndServe(bind, robotsfile string, robotsdebug bool, uri string) error
258 "HTMLEscape": func(s string) string { 260 "HTMLEscape": func(s string) string {
259 return html.EscapeString(s) 261 return html.EscapeString(s)
260 }, 262 },
263 "split": strings.Split,
264 "last": func(s []string) string {
265 return s[len(s)-1]
266 },
267 "pop": func(s []string) []string {
268 return s[:len(s)-1]
269 },
261 } 270 }
262 271
263 tpl, err = template.New("gophermenu").Funcs(funcMap).Parse(tpltext) 272 tpl, err = template.New("gophermenu").Funcs(funcMap).Parse(tpltext)
diff --git a/template.go b/template.go
index 781d2bb..b1dbaf1 100644
--- a/template.go
+++ b/template.go
@@ -12,6 +12,28 @@ var tpltext = `<!doctype html>
12 </style> 12 </style>
13 </head> 13 </head>
14 <body> 14 <body>
15 <header class="header">
16 {{- $href := "" -}}
17 {{- $uriParts := split .URI "/" -}}
18 {{- $uriLast := $uriParts | last -}}
19 {{- $uriParts = $uriParts | pop -}}
20 {{- if eq $uriLast "" -}}
21 {{- $uriLast = $uriParts | last -}}
22 {{- $uriParts = $uriParts | pop -}}
23 {{- end -}}
24
25 {{- range $i, $part := $uriParts -}}
26 {{- if ne $i 1 -}}
27 {{- $href = printf "%s/%s" $href . -}}
28 {{- if ne $i 0 }} / {{ end -}}
29 <a href="{{ $href }}" class="header__uripart">{{ . }}</a>
30 {{- else -}}
31 {{- $href = printf "%s/1" $href -}}
32 {{- end -}}
33 {{- end -}}
34 {{- if ne (len $uriParts) 0 }} / {{ end -}}
35 <span class="header__uripart header__uripart--last">{{ $uriLast -}}</span>
36 </header>
15 <main class="wrap"> 37 <main class="wrap">
16 <pre class="content"> 38 <pre class="content">
17 {{- if .Lines -}} 39 {{- if .Lines -}}