diff options
-rw-r--r-- | gopherproxy.go | 9 | ||||
-rw-r--r-- | template.go | 71 |
2 files changed, 49 insertions, 31 deletions
diff --git a/gopherproxy.go b/gopherproxy.go index 82215c5..e41af3d 100644 --- a/gopherproxy.go +++ b/gopherproxy.go | |||
@@ -223,9 +223,12 @@ func ListenAndServe(bind, robotsfile, uri string) error { | |||
223 | } | 223 | } |
224 | 224 | ||
225 | funcMap := template.FuncMap{ | 225 | funcMap := template.FuncMap{ |
226 | "safeCss": func(s string) template.CSS { | 226 | "safeHtml": func(s string) template.HTML { |
227 | return template.CSS(s) | 227 | return template.HTML(s) |
228 | }, | 228 | }, |
229 | "safeCss": func(s string) template.CSS { | ||
230 | return template.CSS(s) | ||
231 | }, | ||
229 | } | 232 | } |
230 | 233 | ||
231 | tpl, err = template.New("gophermenu").Funcs(funcMap).Parse(tpltext) | 234 | tpl, err = template.New("gophermenu").Funcs(funcMap).Parse(tpltext) |
diff --git a/template.go b/template.go index 81730a6..242d0a2 100644 --- a/template.go +++ b/template.go | |||
@@ -2,32 +2,47 @@ package gopherproxy | |||
2 | 2 | ||
3 | var tpltext = `<!doctype html> | 3 | var tpltext = `<!doctype html> |
4 | <html> | 4 | <html> |
5 | <head> | 5 | <head> |
6 | <meta charset="utf-8"> | 6 | <meta charset="utf-8"> |
7 | <meta name="viewport" content="width=device-width, initial-scale=1" /> | 7 | <meta name="viewport" content="width=device-width, initial-scale=1" /> |
8 | <title>{{.Title}}</title> | 8 | <title>{{ .Title }}</title> |
9 | <link rel="preload" href="/assets/IBMPlexMono-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous" /> | 9 | <link rel="preload" href="/assets/IBMPlexMono-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous" /> |
10 | <style> | 10 | <style> |
11 | {{.Style | safeCss}} | 11 | {{ .Style | safeCss }} |
12 | </style> | 12 | </style> |
13 | </head> | 13 | </head> |
14 | <body> | 14 | <body> |
15 | <main class="wrap"> | 15 | <main class="wrap"> |
16 | <pre class="content"> | 16 | <pre class="content"> |
17 | {{if .Lines}}{{range .Lines}} {{if .Link}}<span class="link-type"> {{.Type}} </span> <a class="link link-{{ .Type }}" href="{{.Link}}">{{.Text}}</a>{{else}} {{.Text}}{{end}} | 17 | {{- if .Lines -}} |
18 | {{end}}{{else}}{{.RawText}}{{end}}</pre> | 18 | {{- $content := "" -}} |
19 | </main> | 19 | {{- range .Lines -}} |
20 | <script type="text/javascript"> | 20 | {{- if ne $content "" -}} |
21 | var qry=document.getElementsByClassName('link-QRY') | 21 | {{- $content = printf "%s\n" $content -}} |
22 | var i=qry.length | 22 | {{- end -}} |
23 | while (i--) { | 23 | {{- if .Link -}} |
24 | qry[i].addEventListener('click', function(e) { | 24 | {{- $content = printf "%s%s" $content (printf "<span class=\"link-type\">%s </span> <a class=\"link link--%s\" href=\"%s\">%s</a>" .Type .Type .Link .Text) -}} |
25 | e.preventDefault(); | 25 | {{- else -}} |
26 | var resp=prompt("Please enter required input: ", "") | 26 | {{- $content = printf "%s%s" $content (printf " %s" .Text) -}} |
27 | if (resp !== null && resp !== "") window.location = e.target.href + "?" + resp | 27 | {{- end -}} |
28 | return false; | 28 | {{- end -}} |
29 | }) | 29 | {{- $content | safeHtml -}} |
30 | } | 30 | {{- else -}} |
31 | </script> | 31 | {{- .RawText -}} |
32 | </body> | 32 | {{- end -}} |
33 | </pre> | ||
34 | </main> | ||
35 | <script type="text/javascript"> | ||
36 | var qry=document.getElementsByClassName('link--QRY') | ||
37 | var i=qry.length | ||
38 | while (i--) { | ||
39 | qry[i].addEventListener('click', function(e) { | ||
40 | e.preventDefault(); | ||
41 | var resp=prompt("Please enter required input: ", "") | ||
42 | if (resp !== null && resp !== "") window.location = e.target.href + "?" + resp | ||
43 | return false; | ||
44 | }) | ||
45 | } | ||
46 | </script> | ||
47 | </body> | ||
33 | </html>` | 48 | </html>` |