From ac770231436f8a17d348a6a0ab934429df3c57d0 Mon Sep 17 00:00:00 2001 From: Feuerfuchs Date: Mon, 18 May 2020 16:12:43 +0200 Subject: WIP: Refactoring --- internal/port/tpl/_fonts.html | 16 ++++++ internal/port/tpl/_header.html | 48 ++++++++++++++++ internal/port/tpl/_modals.html | 24 ++++++++ internal/port/tpl/gemini.html | 38 +++++++++++++ internal/port/tpl/gopher.html | 59 +++++++++++++++++++ internal/port/tpl/startpage.html | 120 +++++---------------------------------- 6 files changed, 200 insertions(+), 105 deletions(-) create mode 100644 internal/port/tpl/_fonts.html create mode 100644 internal/port/tpl/_header.html create mode 100644 internal/port/tpl/_modals.html (limited to 'internal/port/tpl') diff --git a/internal/port/tpl/_fonts.html b/internal/port/tpl/_fonts.html new file mode 100644 index 0000000..b56aa22 --- /dev/null +++ b/internal/port/tpl/_fonts.html @@ -0,0 +1,16 @@ + diff --git a/internal/port/tpl/_header.html b/internal/port/tpl/_header.html new file mode 100644 index 0000000..5bcd254 --- /dev/null +++ b/internal/port/tpl/_header.html @@ -0,0 +1,48 @@ +
+
+ {{ .Protocol }}://:// + + {{- if .URL -}} + {{- $page := . -}} + {{- $href := printf "/%s" .Protocol -}} + {{- $uriParts := split .URL "/" -}} + + {{- $uriLast := $uriParts | last -}} + {{- $uriParts = $uriParts | pop -}} + {{- if eq $uriLast "" -}} + {{- $uriLast = $uriParts | last -}} + {{- $uriParts = $uriParts | pop -}} + {{- end -}} + + {{- range $i, $part := $uriParts -}} + {{- if and (eq $page.Protocol "gopher") (eq $i 1) -}} + {{- $href = printf "%s/1" $href -}} + {{- $part = $part | trimLeftChar -}} + {{- if not (eq $part "") -}} + {{- $href = printf "%s/%s" $href $part -}} + /{{ $part }} + {{- end -}} + {{- else -}} + {{- $href = printf "%s/%s" $href . -}} + {{- if ne $i 0 -}} + / + {{- end -}} + {{ . }} + {{- end -}} + {{- end -}} + {{- if ne (len $uriParts) 0 -}} + / + {{- end -}} + {{- if and (eq $page.Protocol "gopher") (eq (len $uriParts) 1) -}} + {{- $uriLast = $uriLast | trimLeftChar -}} + {{- end -}} + {{ $uriLast }} + {{- end -}} +
+
+ {{- if and (not .Lines) (not .Error) (eq .Protocol "gopher") -}} + + {{- end -}} +
+
+
diff --git a/internal/port/tpl/_modals.html b/internal/port/tpl/_modals.html new file mode 100644 index 0000000..3c08d9a --- /dev/null +++ b/internal/port/tpl/_modals.html @@ -0,0 +1,24 @@ + diff --git a/internal/port/tpl/gemini.html b/internal/port/tpl/gemini.html index e69de29..08f1b8e 100644 --- a/internal/port/tpl/gemini.html +++ b/internal/port/tpl/gemini.html @@ -0,0 +1,38 @@ + + + + + + {{ .Title }} - Gemini proxy + + {{- template "_fonts.html" . -}} + + + {{- template "_header.html" . -}} + +
+
+				{{- 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 | HTMLEscape)) -}}
+						{{- else -}}
+							{{- $content = printf "%s%s" $content (printf "     %s" (.Text | HTMLEscape)) -}}
+						{{- end -}}
+					{{- end -}}
+					{{- $content | safeHtml -}}
+				{{- else -}}
+					{{- .RawText -}}
+				{{- end -}}
+			
+
+ + {{- template "_modals.html" . -}} + + + + diff --git a/internal/port/tpl/gopher.html b/internal/port/tpl/gopher.html index e69de29..c971847 100644 --- a/internal/port/tpl/gopher.html +++ b/internal/port/tpl/gopher.html @@ -0,0 +1,59 @@ + + + + + + {{ .Title }} - Gopher proxy + + {{- template "_fonts.html" . -}} + + +
+
+ gopher://:// + {{- range $i, $item := .Nav -}} + {{- if ne $i 0 -}} + / + {{- end -}} + {{- if .Current -}} + {{ .Label }} + {{- else -}} + {{ .Label }} + {{- end -}} + {{- end -}} +
+
+ {{- if .IsPlain -}} + + {{- end -}} +
+
+
+ +
+
+        {{- $content := "" -}}
+        {{- $page := . -}}
+        {{- range .Lines -}}
+          {{- if ne $content "" -}}
+            {{- $content = printf "%s\n" $content -}}
+          {{- end -}}
+          {{- if $page.IsPlain -}}
+            {{- $content = printf "%s%s" $content (.Text | HTMLEscape) -}}
+          {{- else -}}
+            {{- if .Link -}}
+              {{- $content = printf "%s%s" $content (printf "%s  %s" .Type .Type .Link (.Text | HTMLEscape)) -}}
+            {{- else -}}
+              {{- $content = printf "%s%s" $content (printf "     %s" (.Text | HTMLEscape)) -}}
+            {{- end -}}
+          {{- end -}}
+        {{- end -}}
+        {{- $content | safeHtml -}}
+			
+
+ + {{- template "_modals.html" . -}} + + + + diff --git a/internal/port/tpl/startpage.html b/internal/port/tpl/startpage.html index 8482a6f..cfe519d 100644 --- a/internal/port/tpl/startpage.html +++ b/internal/port/tpl/startpage.html @@ -3,118 +3,28 @@ - {{ .Title }}{{ if ne .Protocol "startpage" }} - {{ .Protocol | title }} proxy{{ end }} + {{ .Title }} - + {{- template "_fonts.html" . -}} - +
-
- {{ .Protocol }}://:// - - {{- if .URI -}} - {{- $page := . -}} - {{- $href := printf "/%s" .Protocol -}} - {{- $uriParts := split .URI "/" -}} - - {{- $uriLast := $uriParts | last -}} - {{- $uriParts = $uriParts | pop -}} - {{- if eq $uriLast "" -}} - {{- $uriLast = $uriParts | last -}} - {{- $uriParts = $uriParts | pop -}} - {{- end -}} + +
+
+
+
- {{- range $i, $part := $uriParts -}} - {{- if and (eq $page.Protocol "gopher") (eq $i 1) -}} - {{- $href = printf "%s/1" $href -}} - {{- $part = $part | trimLeftChar -}} - {{- if not (eq $part "") -}} - {{- $href = printf "%s/%s" $href $part -}} - /{{ $part }} - {{- end -}} - {{- else -}} - {{- $href = printf "%s/%s" $href . -}} - {{- if ne $i 0 -}} - / - {{- end -}} - {{ . }} - {{- end -}} - {{- end -}} - {{- if ne (len $uriParts) 0 -}} - / - {{- end -}} - {{- if and (eq $page.Protocol "gopher") (eq (len $uriParts) 1) -}} - {{- $uriLast = $uriLast | trimLeftChar -}} - {{- end -}} - {{ $uriLast }} - {{- end -}} - -
- {{- if and (not .Lines) (not .Error) (eq .Protocol "gopher") -}} - - {{- end -}} -
-
-
-
-				{{- 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 | HTMLEscape)) -}}
-						{{- else -}}
-							{{- $content = printf "%s%s" $content (printf "     %s" (.Text | HTMLEscape)) -}}
-						{{- end -}}
-					{{- end -}}
-					{{- $content | safeHtml -}}
-				{{- else -}}
-					{{- .RawText -}}
-				{{- end -}}
+			
+        {{- .Content -}}
 			
- + + {{- template "_modals.html" . -}} + -- cgit v1.2.3-70-g09d2