Move item template to its own file
This commit is contained in:
parent
1057b54b3d
commit
565522535f
@ -1,55 +1,5 @@
|
||||
{{ define "title" }}{{ if .Items }}({{ len .Items }}) {{ end }}Intake{{ end }}
|
||||
|
||||
{{ define "buttons" -}}
|
||||
<button class="item-button" title="Deactivate {{ .Source }}/{{ .Id }}">✕</button>
|
||||
<button class="item-button" title="Punt {{ .Source }}/{{ .Id }}">↷</button>
|
||||
{{- if .Link }}<a class="item-link" href="{{ .Link }}" target="_blank">⇗</a>
|
||||
{{ end -}}
|
||||
{{ end }}
|
||||
|
||||
{{ define "item-title" -}}
|
||||
<span class="item-title">{{ or .Title .Id | raw }}</span>
|
||||
{{- end }}
|
||||
|
||||
{{ define "item" -}}
|
||||
<article id="{{ .Source }}-{{ .Id }}">
|
||||
|
||||
{{/* The item title is a clickable <summary> if there is body content */}}
|
||||
{{ if .Body }}
|
||||
<details>
|
||||
<summary>
|
||||
{{ template "buttons" . }}
|
||||
{{ template "item-title" . }}
|
||||
</summary>
|
||||
{{ if .Body }}
|
||||
<p>{{ raw .Body }}</p>
|
||||
{{ end }}
|
||||
</details>
|
||||
{{ template "buttons" . }}
|
||||
{{ else }}
|
||||
{{ template "buttons" . }}
|
||||
{{ template "item-title" . }}<br>
|
||||
{{ end }}
|
||||
{{/* end if .Body */}}
|
||||
|
||||
{{/* author/time footer line */}}
|
||||
{{ if or .Author .Time }}
|
||||
<span class="item-info">
|
||||
{{ .Author }}
|
||||
{{ .Time | tsToDate }}
|
||||
</span><br>
|
||||
{{ end }}
|
||||
|
||||
{{/* source/id/created footer line */}}
|
||||
<span class="item-info">
|
||||
{{ .Source }}/{{ .Id }}
|
||||
{{ .Created | tsToDate }}
|
||||
</span>
|
||||
|
||||
</article>
|
||||
{{ end }}
|
||||
{{/* end define "item" */}}
|
||||
|
||||
{{ define "content" -}}
|
||||
<article class="center">
|
||||
<span class="item-title">
|
||||
@ -67,7 +17,6 @@
|
||||
<button>Deactivate All</button>
|
||||
</article>
|
||||
|
||||
{{/* if .Items */}}
|
||||
{{ else }}
|
||||
<article class="center">
|
||||
<span class="item-title">Feed is empty</span>
|
||||
|
@ -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
|
||||
|
49
web/html/item.html
Normal file
49
web/html/item.html
Normal file
@ -0,0 +1,49 @@
|
||||
{{ define "buttons" -}}
|
||||
<button class="item-button" title="Deactivate {{ .Source }}/{{ .Id }}">✕</button>
|
||||
<button class="item-button" title="Punt {{ .Source }}/{{ .Id }}">↷</button>
|
||||
{{- if .Link }}<a class="item-link" href="{{ .Link }}" target="_blank">⇗</a>
|
||||
{{ end -}}
|
||||
{{ end }}
|
||||
|
||||
{{ define "item-title" -}}
|
||||
<span class="item-title">{{ or .Title .Id | raw }}</span>
|
||||
{{- end }}
|
||||
|
||||
{{ define "item" -}}
|
||||
<article id="{{ .Source }}-{{ .Id }}">
|
||||
|
||||
{{/* The item title is a clickable <summary> if there is body content */}}
|
||||
{{ if .Body }}
|
||||
<details>
|
||||
<summary>
|
||||
{{ template "buttons" . }}
|
||||
{{ template "item-title" . }}
|
||||
</summary>
|
||||
{{ if .Body }}
|
||||
<p>{{ raw .Body }}</p>
|
||||
{{ end }}
|
||||
</details>
|
||||
{{ template "buttons" . }}
|
||||
{{ else }}
|
||||
{{ template "buttons" . }}
|
||||
{{ template "item-title" . }}<br>
|
||||
{{ end }}
|
||||
{{/* end if .Body */}}
|
||||
|
||||
{{/* author/time footer line */}}
|
||||
{{ if or .Author .Time }}
|
||||
<span class="item-info">
|
||||
{{ .Author }}
|
||||
{{ .Time | tsToDate }}
|
||||
</span><br>
|
||||
{{ end }}
|
||||
|
||||
{{/* source/id/created footer line */}}
|
||||
<span class="item-info">
|
||||
{{ .Source }}/{{ .Id }}
|
||||
{{ .Created | tsToDate }}
|
||||
</span>
|
||||
|
||||
</article>
|
||||
{{ end }}
|
||||
{{/* end define "item" */}}
|
Loading…
Reference in New Issue
Block a user