aboutsummaryrefslogtreecommitdiffstats
path: root/template.go
blob: 33486d5737e81d4b769173c543f3d28cae157689 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package gopherproxy

var tpltext = `<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>{{ .Title }}</title>
    <link rel="preload" href="/assets/IBMPlexMono-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous" />
    <style>
      {{ .Style | safeCss }}
    </style>
  </head>
  <body>
    <header class="header">
      {{- $href     := "" -}}
      {{- $uriParts := split .URI "/" -}}
      {{- $uriLast  := $uriParts | last -}}
      {{- $uriParts  = $uriParts | pop -}}
      {{- if eq $uriLast "" -}}
        {{- $uriLast  = $uriParts | last -}}
        {{- $uriParts = $uriParts | pop -}}
      {{- end -}}
      {{- if eq (len $uriParts) 1 -}}
        {{- $uriLast  = $uriParts | last -}}
        {{- $uriParts = $uriParts | pop -}}
      {{- end -}}

      {{- range $i, $part := $uriParts -}}
        {{- if ne $i 1 -}}
          {{- $href = printf "%s/%s" $href . -}}
          {{- if ne $i 0 }} / {{ end -}}
          <a href="{{ $href }}" class="header__uripart">{{ . }}</a>
        {{- else -}}
          {{- $href = printf "%s/1" $href -}}
        {{- end -}}
      {{- end -}}
      {{- if ne (len $uriParts) 0 }} / {{ end -}}
      <span class="header__uripart header__uripart--last">{{ $uriLast -}}</span>
    </header>
    <main class="wrap">
      <pre class="content">
        {{- if .Lines -}}
          {{- $content := "" -}}
          {{- range .Lines -}}
            {{- if ne $content "" -}}
              {{- $content = printf "%s\n" $content -}}
            {{- end -}}
            {{- if .Link -}}
              {{- $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 | HTMLEscape)) -}}
            {{- else -}}
              {{- $content = printf "%s%s" $content (printf "     %s" (.Text | HTMLEscape)) -}}
            {{- end -}}
          {{- end -}}
          {{- $content | safeHtml -}}
        {{- else -}}
          {{- .RawText -}}
        {{- end -}}
      </pre>
    </main>
    <script type="text/javascript">
      var qry=document.getElementsByClassName('link--QRY')
      var i=qry.length
      while (i--) {
        qry[i].addEventListener('click', function(e) {
          e.preventDefault();
          var resp=prompt("Please enter required input: ", "")
          if (resp !== null && resp !== "") window.location = e.target.href + "?" + resp
          return false;
        })
      }
    </script>
  </body>
</html>`