From 867ff4d28be2008adeab55cf2f155d7925132528 Mon Sep 17 00:00:00 2001 From: Feuerfuchs Date: Wed, 5 Jun 2019 17:29:31 +0200 Subject: Improved template readability --- gopherproxy.go | 9 +++++--- 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 { } funcMap := template.FuncMap{ - "safeCss": func(s string) template.CSS { - return template.CSS(s) - }, + "safeHtml": func(s string) template.HTML { + return template.HTML(s) + }, + "safeCss": func(s string) template.CSS { + return template.CSS(s) + }, } 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 var tpltext = ` - - - -{{.Title}} - - - - -
-
-{{if .Lines}}{{range .Lines}} {{if .Link}} {{.Type}}  {{.Text}}{{else}}      {{.Text}}{{end}}
-{{end}}{{else}}{{.RawText}}{{end}}
-
- - + + + + {{ .Title }} + + + + +
+
+        {{- if .Lines -}}
+          {{- $content := "" -}}
+          {{- range .Lines -}}
+            {{- if ne $content "" -}}
+              {{- $content = printf "%s\n" $content -}}
+            {{- end -}}
+            {{- if .Link -}}
+              {{- $content = printf "%s%s" $content (printf "%s  %s" .Type .Type .Link .Text) -}}
+            {{- else -}}
+              {{- $content = printf "%s%s" $content (printf "     %s" .Text) -}}
+            {{- end -}}
+          {{- end -}}
+          {{- $content | safeHtml -}}
+        {{- else -}}
+          {{- .RawText -}}
+        {{- end -}}
+      
+
+ + ` -- cgit v1.2.3-70-g09d2