Add tt{l,d,s} notice to web UI

This commit is contained in:
Tim Van Baak 2025-02-05 12:16:42 -08:00
parent c0d8e8ae31
commit 1ee91c1abe
2 changed files with 34 additions and 4 deletions

View File

@ -3,6 +3,7 @@ package html
import ( import (
"embed" "embed"
"encoding/json" "encoding/json"
"fmt"
"html/template" "html/template"
"io" "io"
"log" "log"
@ -15,11 +16,35 @@ func rawHtml(str string) template.HTML {
return template.HTML(str) return template.HTML(str)
} }
func tsToDate(t int) string { func dateFormat(tm time.Time) string {
tm := time.Unix(int64(t), 0).UTC()
return tm.Format(time.DateTime) return tm.Format(time.DateTime)
} }
func tsToDate(t int) time.Time {
return time.Unix(int64(t), 0).UTC()
}
func until(tm time.Time) string {
dur := time.Until(tm).Round(time.Second)
var format string
if dur < 0 {
format = "%s ago"
dur = dur.Abs()
} else {
format = "in %s"
}
var length string
if dur.Hours() > 24 {
length = fmt.Sprintf("%dd", int(dur.Hours()/24))
} else {
length = dur.String()
}
return fmt.Sprintf(format, length)
}
func massDeactivateVals(items []core.Item) string { func massDeactivateVals(items []core.Item) string {
var shorts []string var shorts []string
for _, item := range items { for _, item := range items {
@ -37,7 +62,9 @@ func massDeactivateVals(items []core.Item) string {
var funcs = template.FuncMap{ var funcs = template.FuncMap{
"raw": rawHtml, "raw": rawHtml,
"dateFormat": dateFormat,
"tsToDate": tsToDate, "tsToDate": tsToDate,
"until": until,
"massDeacVars": massDeactivateVals, "massDeacVars": massDeactivateVals,
} }

View File

@ -56,14 +56,17 @@
{{ if or .Author .Time }} {{ if or .Author .Time }}
<span class="item-info"> <span class="item-info">
{{ .Author }} {{ .Author }}
{{ .Time | tsToDate }} <span title="{{ .Time | tsToDate | until }}">{{ .Time | tsToDate | dateFormat }}</span>
</span><br> </span><br>
{{ end -}} {{ end -}}
{{- /* source/id/created footer line */ -}} {{- /* source/id/created footer line */ -}}
<span class="item-info"> <span class="item-info">
<a href="/item/{{ .Source }}/{{ .Id }}">{{ .Source }}/{{ .Id }}</a> <a href="/item/{{ .Source }}/{{ .Id }}">{{ .Source }}/{{ .Id }}</a>
{{ .Created | tsToDate }} <span title="{{ .Created | tsToDate | until }}">{{ .Created | tsToDate | dateFormat }}</span>
{{ if .Ttl }}<span title="TTL {{ .TtlTime | dateFormat }}, {{ .TtlTime | until }}">[L]</span>{{ end }}
{{ if .Ttd }}<span title="TTD {{ .TtdTime | dateFormat }}, {{ .TtdTime | until }}">[D]</span>{{ end }}
{{ if .Tts }}<span title="TTS {{ .TtsTime | dateFormat }}, {{ .TtsTime | until }}">[S]</span>{{ end }}
</span> </span>
</article> </article>
{{ end -}} {{ end -}}