From 565522535f77cea2198aae0214b07c55c1300594 Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Mon, 27 Jan 2025 19:35:13 -0800 Subject: [PATCH] Move item template to its own file --- web/html/feed.html | 51 ---------------------------------------------- web/html/html.go | 7 ++++--- web/html/item.html | 49 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 54 deletions(-) create mode 100644 web/html/item.html diff --git a/web/html/feed.html b/web/html/feed.html index c32f0da..b00a500 100644 --- a/web/html/feed.html +++ b/web/html/feed.html @@ -1,55 +1,5 @@ {{ define "title" }}{{ if .Items }}({{ len .Items }}) {{ end }}Intake{{ end }} -{{ define "buttons" -}} - - -{{- if .Link }} -{{ end -}} -{{ end }} - -{{ define "item-title" -}} -{{ or .Title .Id | raw }} -{{- end }} - -{{ define "item" -}} -
- - {{/* The item title is a clickable if there is body content */}} - {{ if .Body }} -
- - {{ template "buttons" . }} - {{ template "item-title" . }} - - {{ if .Body }} -

{{ raw .Body }}

- {{ end }} -
- {{ template "buttons" . }} - {{ else }} - {{ template "buttons" . }} - {{ template "item-title" . }}
- {{ end }} - {{/* end if .Body */}} - - {{/* author/time footer line */}} - {{ if or .Author .Time }} - - {{ .Author }} - {{ .Time | tsToDate }} -
- {{ end }} - - {{/* source/id/created footer line */}} - - {{ .Source }}/{{ .Id }} - {{ .Created | tsToDate }} - - -
-{{ end }} -{{/* end define "item" */}} - {{ define "content" -}}
@@ -67,7 +17,6 @@
-{{/* if .Items */}} {{ else }}
Feed is empty diff --git a/web/html/html.go b/web/html/html.go index 539a8d3..a884b27 100644 --- a/web/html/html.go +++ b/web/html/html.go @@ -29,8 +29,9 @@ var Stylesheet []byte //go:embed *.html var templates embed.FS -func load(file string) *template.Template { - return template.Must(template.New("layout.html").Funcs(funcs).ParseFS(templates, "layout.html", file)) +func load(files ...string) *template.Template { + files = append([]string{"layout.html"}, files...) + return template.Must(template.New("layout.html").Funcs(funcs).ParseFS(templates, files...)) } var home = load("home.html") @@ -47,7 +48,7 @@ func Home(writer io.Writer, data HomeData) error { return home.Execute(writer, data) } -var feed = load("feed.html") +var feed = load("feed.html", "item.html") type FeedData struct { Items []core.Item diff --git a/web/html/item.html b/web/html/item.html new file mode 100644 index 0000000..0cf60b8 --- /dev/null +++ b/web/html/item.html @@ -0,0 +1,49 @@ +{{ define "buttons" -}} + + +{{- if .Link }} +{{ end -}} +{{ end }} + +{{ define "item-title" -}} +{{ or .Title .Id | raw }} +{{- end }} + +{{ define "item" -}} +
+ +{{/* The item title is a clickable if there is body content */}} +{{ if .Body }} +
+ + {{ template "buttons" . }} + {{ template "item-title" . }} + +{{ if .Body }} +

{{ raw .Body }}

+{{ end }} +
+{{ template "buttons" . }} +{{ else }} +{{ template "buttons" . }} +{{ template "item-title" . }}
+{{ end }} +{{/* end if .Body */}} + +{{/* author/time footer line */}} +{{ if or .Author .Time }} + +{{ .Author }} +{{ .Time | tsToDate }} +
+{{ end }} + +{{/* source/id/created footer line */}} + +{{ .Source }}/{{ .Id }} +{{ .Created | tsToDate }} + + +
+{{ end }} +{{/* end define "item" */}}