Add tt{l,d,s} notice to web UI
This commit is contained in:
parent
c0d8e8ae31
commit
1ee91c1abe
@ -3,6 +3,7 @@ package html
|
||||
import (
|
||||
"embed"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io"
|
||||
"log"
|
||||
@ -15,11 +16,35 @@ func rawHtml(str string) template.HTML {
|
||||
return template.HTML(str)
|
||||
}
|
||||
|
||||
func tsToDate(t int) string {
|
||||
tm := time.Unix(int64(t), 0).UTC()
|
||||
func dateFormat(tm time.Time) string {
|
||||
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 {
|
||||
var shorts []string
|
||||
for _, item := range items {
|
||||
@ -37,7 +62,9 @@ func massDeactivateVals(items []core.Item) string {
|
||||
|
||||
var funcs = template.FuncMap{
|
||||
"raw": rawHtml,
|
||||
"dateFormat": dateFormat,
|
||||
"tsToDate": tsToDate,
|
||||
"until": until,
|
||||
"massDeacVars": massDeactivateVals,
|
||||
}
|
||||
|
||||
|
@ -56,14 +56,17 @@
|
||||
{{ if or .Author .Time }}
|
||||
<span class="item-info">
|
||||
{{ .Author }}
|
||||
{{ .Time | tsToDate }}
|
||||
<span title="{{ .Time | tsToDate | until }}">{{ .Time | tsToDate | dateFormat }}</span>
|
||||
</span><br>
|
||||
{{ end -}}
|
||||
|
||||
{{- /* source/id/created footer line */ -}}
|
||||
<span class="item-info">
|
||||
<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>
|
||||
</article>
|
||||
{{ end -}}
|
||||
|
Loading…
Reference in New Issue
Block a user