diff options
| author | Feuerfuchs <git@feuerfuchs.dev> | 2019-11-17 10:14:58 +0100 |
|---|---|---|
| committer | Feuerfuchs <git@feuerfuchs.dev> | 2019-11-17 10:14:58 +0100 |
| commit | e85a6b1c934d1070e40d11ad94b3ad4d79bdc9b2 (patch) | |
| tree | 66613d0dac2581b117d17879af9c24b31d6f0af7 /template.go | |
| parent | Remove obsolete vars from libgemini (diff) | |
| download | gopherproxy-e85a6b1c934d1070e40d11ad94b3ad4d79bdc9b2.tar.gz gopherproxy-e85a6b1c934d1070e40d11ad94b3ad4d79bdc9b2.tar.bz2 gopherproxy-e85a6b1c934d1070e40d11ad94b3ad4d79bdc9b2.zip | |
Report template errors, add support for start page
Diffstat (limited to 'template.go')
| -rw-r--r-- | template.go | 229 |
1 files changed, 116 insertions, 113 deletions
diff --git a/template.go b/template.go index 3bd8950..7ddc460 100644 --- a/template.go +++ b/template.go | |||
| @@ -2,118 +2,121 @@ 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 }} - {{ .Protocol | title }} proxy</title> | 8 | <title>{{ .Title }} - {{ .Protocol | title }} proxy</title> |
| 9 | <link rel="stylesheet" href="{{ .Assets.Style }}" /> | 9 | <link rel="stylesheet" href="{{ .Assets.Style }}" /> |
| 10 | <style> | 10 | <style> |
| 11 | @font-face { | 11 | @font-face { |
| 12 | font-family: 'Iosevka Term SS03'; | 12 | font-family: 'Iosevka Term SS03'; |
| 13 | font-style: normal; | 13 | font-style: normal; |
| 14 | font-weight: normal; | 14 | font-weight: normal; |
| 15 | src: url('{{ .Assets.FontW2 }}') format('woff2'), | 15 | src: url('{{ .Assets.FontW2 }}') format('woff2'), |
| 16 | url('{{ .Assets.FontW }}') format('woff'); | 16 | url('{{ .Assets.FontW }}') format('woff'); |
| 17 | } | 17 | } |
| 18 | @font-face { | 18 | @font-face { |
| 19 | font-family: 'Iosevka Aile'; | 19 | font-family: 'Iosevka Aile'; |
| 20 | font-style: normal; | 20 | font-style: normal; |
| 21 | font-weight: normal; | 21 | font-weight: normal; |
| 22 | src: url('{{ .Assets.PropFontW2 }}') format('woff2'), | 22 | src: url('{{ .Assets.PropFontW2 }}') format('woff2'), |
| 23 | url('{{ .Assets.PropFontW }}') format('woff'); | 23 | url('{{ .Assets.PropFontW }}') format('woff'); |
| 24 | } | 24 | } |
| 25 | </style> | 25 | </style> |
| 26 | </head> | 26 | </head> |
| 27 | <body class="{{ if not .Lines }}is-plain{{ end }}"> | 27 | <body class="{{ if not .Lines }}is-plain{{ end }}"> |
| 28 | <header class="header header-base"> | 28 | <header class="header header-base"> |
| 29 | <div class="location"> | 29 | <div class="location"> |
| 30 | {{- $page := . -}} | 30 | <a class="location__prefix">{{ .Protocol }}://</a><a class="location__prefix location__prefix--mobile">://</a> |
| 31 | {{- $href := "" -}} | 31 | |
| 32 | {{- $uriParts := split .URI "/" -}} | 32 | {{- if .URI -}} |
| 33 | {{- $uriLast := $uriParts | last -}} | 33 | {{- $page := . -}} |
| 34 | {{- $uriParts = $uriParts | pop -}} | 34 | {{- $href := printf "/%s" .Protocol -}} |
| 35 | {{- if eq $uriLast "" -}} | 35 | {{- $uriParts := split .URI "/" -}} |
| 36 | {{- $uriLast = $uriParts | last -}} | 36 | |
| 37 | {{- $uriParts = $uriParts | pop -}} | 37 | {{- $uriLast := $uriParts | last -}} |
| 38 | {{- end -}} | 38 | {{- $uriParts = $uriParts | pop -}} |
| 39 | {{- if eq $uriLast "" -}} | ||
| 40 | {{- $uriLast = $uriParts | last -}} | ||
| 41 | {{- $uriParts = $uriParts | pop -}} | ||
| 42 | {{- end -}} | ||
| 39 | 43 | ||
| 40 | <a class="location__prefix">{{ .Protocol }}://</a><a class="location__prefix location__prefix--mobile">://</a> | 44 | {{- range $i, $part := $uriParts -}} |
| 41 | {{- $href = printf "%s/%s" $href .Protocol -}} | 45 | {{- if and (eq $page.Protocol "gopher") (eq $i 1) -}} |
| 42 | {{- range $i, $part := $uriParts -}} | 46 | {{- $href = printf "%s/1" $href -}} |
| 43 | {{- if and (eq $page.Protocol "gopher") (eq $i 1) -}} | 47 | {{- $part = $part | trimLeftChar -}} |
| 44 | {{- $href = printf "%s/1" $href -}} | 48 | {{- if not (eq $part "") -}} |
| 45 | {{- $part = $part | trimLeftChar -}} | 49 | {{- $href = printf "%s/%s" $href $part -}} |
| 46 | {{- if not (eq $part "") -}} | 50 | <span class="location__slash">/</span><a href="{{ $href }}/" class="location__uripart">{{ $part }}</a> |
| 47 | {{- $href = printf "%s/%s" $href $part -}} | 51 | {{- end -}} |
| 48 | <span class="location__slash">/</span><a href="{{ $href }}/" class="location__uripart">{{ $part }}</a> | 52 | {{- else -}} |
| 49 | {{- end -}} | 53 | {{- $href = printf "%s/%s" $href . -}} |
| 50 | {{- else -}} | 54 | {{- if ne $i 0 -}} |
| 51 | {{- $href = printf "%s/%s" $href . -}} | 55 | <span class="location__slash">/</span> |
| 52 | {{- if ne $i 0 -}} | 56 | {{- end -}} |
| 53 | <span class="location__slash">/</span> | 57 | <a href="{{ $href }}/" class="location__uripart">{{ . }}</a> |
| 54 | {{- end -}} | 58 | {{- end -}} |
| 55 | <a href="{{ $href }}/" class="location__uripart">{{ . }}</a> | 59 | {{- end -}} |
| 56 | {{- end -}} | 60 | {{- if ne (len $uriParts) 0 -}} |
| 57 | {{- end -}} | 61 | <span class="location__slash">/</span> |
| 58 | {{- if ne (len $uriParts) 0 -}} | 62 | {{- end -}} |
| 59 | <span class="location__slash">/</span> | 63 | {{- if and (eq $page.Protocol "gopher") (eq (len $uriParts) 1) -}} |
| 60 | {{- end -}} | 64 | {{- $uriLast = $uriLast | trimLeftChar -}} |
| 61 | {{- if and (eq $page.Protocol "gopher") (eq (len $uriParts) 1) -}} | 65 | {{- end -}} |
| 62 | {{- $uriLast = $uriLast | trimLeftChar -}} | 66 | <span class="location__uripart">{{ $uriLast }}</span> |
| 63 | {{- end -}} | 67 | {{- end -}} |
| 64 | <span class="location__uripart">{{ $uriLast }}</span> | 68 | </div> |
| 65 | </div> | 69 | <div class="actions"> |
| 66 | <div class="actions"> | 70 | {{- if and (not .Lines) (not .Error) (eq .Protocol "gopher") -}} |
| 67 | {{- if and (not .Lines) (not .Error) (eq .Protocol "gopher") -}} | 71 | <div class="action"><a href="/{{ .URI | replace "^(.*?)/0" "$1/9" }}">View raw</a></div> |
| 68 | <div class="action"><a href="/{{ .URI | replace "^(.*?)/0" "$1/9" }}">View raw</a></div> | 72 | {{- end -}} |
| 69 | {{- end -}} | 73 | <div class="action"><button class="settings-btn">Settings</button></div> |
| 70 | <div class="action"><button class="settings-btn">Settings</button></div> | 74 | </div> |
| 71 | </div> | 75 | </header> |
| 72 | </header> | 76 | <main class="wrap"> |
| 73 | <main class="wrap"> | 77 | <pre class="content content--has-monospace-font{{ if .Lines }} content--has-type-annotations{{ end }}"> |
| 74 | <pre class="content content--has-monospace-font{{ if .Lines }} content--has-type-annotations{{ end }}"> | 78 | {{- if .Lines -}} |
| 75 | {{- if .Lines -}} | 79 | {{- $content := "" -}} |
| 76 | {{- $content := "" -}} | 80 | {{- range .Lines -}} |
| 77 | {{- range .Lines -}} | 81 | {{- if ne $content "" -}} |
| 78 | {{- if ne $content "" -}} | 82 | {{- $content = printf "%s\n" $content -}} |
| 79 | {{- $content = printf "%s\n" $content -}} | 83 | {{- end -}} |
| 80 | {{- end -}} | 84 | {{- if .Link -}} |
| 81 | {{- if .Link -}} | 85 | {{- $content = printf "%s%s" $content (printf "<span class=\"type-annotation\">%s </span><a class=\"link link--%s\" href=\"%s\">%s</a>" .Type .Type .Link (.Text | HTMLEscape)) -}} |
| 82 | {{- $content = printf "%s%s" $content (printf "<span class=\"type-annotation\">%s </span><a class=\"link link--%s\" href=\"%s\">%s</a>" .Type .Type .Link (.Text | HTMLEscape)) -}} | 86 | {{- else -}} |
| 83 | {{- else -}} | 87 | {{- $content = printf "%s%s" $content (printf "<span class=\"type-annotation\"> </span>%s" (.Text | HTMLEscape)) -}} |
| 84 | {{- $content = printf "%s%s" $content (printf "<span class=\"type-annotation\"> </span>%s" (.Text | HTMLEscape)) -}} | 88 | {{- end -}} |
| 85 | {{- end -}} | 89 | {{- end -}} |
| 86 | {{- end -}} | 90 | {{- $content | safeHtml -}} |
| 87 | {{- $content | safeHtml -}} | 91 | {{- else -}} |
| 88 | {{- else -}} | 92 | {{- .RawText -}} |
| 89 | {{- .RawText -}} | 93 | {{- end -}} |
| 90 | {{- end -}} | 94 | </pre> |
| 91 | </pre> | 95 | </main> |
| 92 | </main> | 96 | <aside class="modal modal--settings"> |
| 93 | <aside class="modal modal--settings"> | 97 | <div class="modal__content"> |
| 94 | <div class="modal__content"> | 98 | <header class="modal__head header-base"> |
| 95 | <header class="modal__head header-base"> | 99 | <h1 class="modal__title">Settings</h1> |
| 96 | <h1 class="modal__title">Settings</h1> | 100 | <button class="modal__close-btn">Close</button> |
| 97 | <button class="modal__close-btn">Close</button> | 101 | </header> |
| 98 | </header> | 102 | <div class="setting setting--word-wrap"> |
| 99 | <div class="setting setting--word-wrap"> | 103 | <strong class="setting__label">Wrap wide content</strong> |
| 100 | <strong class="setting__label">Wrap wide content</strong> | 104 | <button class="setting__value">[N/A]</button> |
| 101 | <button class="setting__value">[N/A]</button> | 105 | </div> |
| 102 | </div> | 106 | <div class="setting setting--monospace-font"> |
| 103 | <div class="setting setting--monospace-font"> | 107 | <strong class="setting__label">Monospace font</strong> |
| 104 | <strong class="setting__label">Monospace font</strong> | 108 | <button class="setting__value">[N/A]</button> |
| 105 | <button class="setting__value">[N/A]</button> | 109 | </div> |
| 106 | </div> | 110 | <div class="setting setting--image-previews"> |
| 107 | <div class="setting setting--image-previews"> | 111 | <strong class="setting__label">Image thumbnails</strong> |
| 108 | <strong class="setting__label">Image thumbnails</strong> | 112 | <button class="setting__value">[N/A]</button> |
| 109 | <button class="setting__value">[N/A]</button> | 113 | </div> |
| 110 | </div> | 114 | <div class="setting setting--clickable-plain-links"> |
| 111 | <div class="setting setting--clickable-plain-links"> | 115 | <strong class="setting__label">Clickable links in text files</strong> |
| 112 | <strong class="setting__label">Clickable links in text files</strong> | 116 | <button class="setting__value">[N/A]</button> |
| 113 | <button class="setting__value">[N/A]</button> | 117 | </div> |
| 114 | </div> | 118 | </div> |
| 115 | </div> | 119 | </aside> |
| 116 | </aside> | 120 | <script src="{{ .Assets.JS }}"></script> |
| 117 | <script src="{{ .Assets.JS }}"></script> | 121 | </body> |
| 118 | </body> | ||
| 119 | </html>` | 122 | </html>` |
