Add old content warning

This commit is contained in:
Jan-Lukas Else 2020-11-03 18:00:03 +01:00
parent f300c3d498
commit 11c4467caa
9 changed files with 38 additions and 10 deletions

View File

@ -82,7 +82,7 @@ func initRendering() error {
} }
return d.Format(format) return d.Format(format)
}, },
"longDate": func(date string, localeString string) string { "longdate": func(date string, localeString string) string {
d, err := dateparse.ParseIn(date, time.Local) d, err := dateparse.ParseIn(date, time.Local)
if err != nil { if err != nil {
return "" return ""
@ -93,6 +93,24 @@ func initRendering() error {
"now": func() string { "now": func() string {
return time.Now().String() return time.Now().String()
}, },
"dateadd": func(date string, years, months, days int) string {
d, err := dateparse.ParseIn(date, time.Local)
if err != nil {
return ""
}
return d.AddDate(years, months, days).String()
},
"datebefore": func(date string, before string) bool {
d, err := dateparse.ParseIn(date, time.Local)
if err != nil {
return false
}
b, err := dateparse.ParseIn(before, time.Local)
if err != nil {
return false
}
return d.Before(b)
},
"asset": assetFile, "asset": assetFile,
"string": getTemplateStringVariant, "string": getTemplateStringVariant,
"include": func(templateName string, data ...interface{}) (template.HTML, error) { "include": func(templateName string, data ...interface{}) (template.HTML, error) {
@ -145,7 +163,7 @@ func initRendering() error {
"absolute": func(path string) string { "absolute": func(path string) string {
return appConfig.Server.PublicAddress + path return appConfig.Server.PublicAddress + path
}, },
"blogRelative": func(blog *configBlog, path string) string { "blogrelative": func(blog *configBlog, path string) string {
return blog.getRelativePath(path) return blog.getRelativePath(path)
}, },
"jsonFile": func(filename string) *map[string]interface{} { "jsonFile": func(filename string) *map[string]interface{} {

View File

@ -1,6 +1,6 @@
{{ define "header" }} {{ define "header" }}
<header> <header>
<h1><a href="{{ blogRelative .Blog "/" }}" rel="home" title="{{ .Blog.Title }}">{{ .Blog.Title }}</a></h1> <h1><a href="{{ blogrelative .Blog "/" }}" rel="home" title="{{ .Blog.Title }}">{{ .Blog.Title }}</a></h1>
{{ with .Blog.Description }}<p><i>{{ . }}</i></p>{{ end }} {{ with .Blog.Description }}<p><i>{{ . }}</i></p>{{ end }}
<nav> <nav>
{{ with menu .Blog "main" }} {{ with menu .Blog "main" }}

View File

@ -0,0 +1,7 @@
{{ define "oldcontentwarning" }}
{{ if .Data.Published }}
{{ if (datebefore (dateadd .Data.Published 1 0 0) now) }}
<strong class="p border-top border-bottom">{{ string .Blog.Lang "oldcontent" }}</strong>
{{ end }}
{{ end }}
{{ end }}

View File

@ -11,9 +11,10 @@
{{ include "postmeta" . }} {{ include "postmeta" . }}
{{ include "postactions" . }} {{ include "postactions" . }}
{{ if .Data.Content }} {{ if .Data.Content }}
{{ include "oldcontentwarning" . }}
<div class=e-content> <div class=e-content>
{{ with p .Data "audio" }} {{ with p .Data "audio" }}
<audio controls preload="metadata" class="fw"><source src="{{ . }}"/></audio> <audio controls preload="none" class="fw"><source src="{{ . }}"/></audio>
{{ end }} {{ end }}
{{ content .Data }} {{ content .Data }}
{{ with p .Data "link" }} {{ with p .Data "link" }}

View File

@ -1,8 +1,8 @@
{{ define "postmeta" }} {{ define "postmeta" }}
<div class="p"> <div class="p">
{{ $section := (index .Blog.Sections .Data.Section) }} {{ $section := (index .Blog.Sections .Data.Section) }}
{{ if .Data.Published }}<div>{{ string .Blog.Lang "publishedon" }} <time class="dt-published" datetime="{{ dateformat .Data.Published "2006-01-02T15:04:05Z07:00"}}">{{ longDate .Data.Published .Blog.TimeLang }}</time>{{ if $section }} in <a href="{{ blogRelative .Blog $section.Name }}">{{ $section.Title }}</a>{{ end }}</div>{{ end }} {{ if .Data.Published }}<div>{{ string .Blog.Lang "publishedon" }} <time class="dt-published" datetime="{{ dateformat .Data.Published "2006-01-02T15:04:05Z07:00"}}">{{ longdate .Data.Published .Blog.TimeLang }}</time>{{ if $section }} in <a href="{{ blogrelative .Blog $section.Name }}">{{ $section.Title }}</a>{{ end }}</div>{{ end }}
{{ if .Data.Updated }}<div>{{ string .Blog.Lang "updatedon" }} <time class="dt-updated" datetime="{{ dateformat .Data.Updated "2006-01-02T15:04:05Z07:00"}}">{{ longDate .Data.Updated .Blog.TimeLang }}</time></div>{{ end }} {{ if .Data.Updated }}<div>{{ string .Blog.Lang "updatedon" }} <time class="dt-updated" datetime="{{ dateformat .Data.Updated "2006-01-02T15:04:05Z07:00"}}">{{ longdate .Data.Updated .Blog.TimeLang }}</time></div>{{ end }}
{{ if p .Data "replylink" }} {{ if p .Data "replylink" }}
<div>{{ string .Blog.Lang "replyto" }}: <a class="u-in-reply-to" href="{{ p .Data "replylink" }}" target="_blank" rel="noopener">{{ p .Data "replytitle" | default (p .Data "replylink") }}</a></div> <div>{{ string .Blog.Lang "replyto" }}: <a class="u-in-reply-to" href="{{ p .Data "replylink" }}" target="_blank" rel="noopener">{{ p .Data "replytitle" | default (p .Data "replylink") }}</a></div>
{{ end }} {{ end }}

View File

@ -6,7 +6,7 @@
{{ if gt (len $tvs) 0 }} {{ if gt (len $tvs) 0 }}
<p><b>{{ $tax.Title }}</b>: <p><b>{{ $tax.Title }}</b>:
{{ range $j, $tv := $tvs }} {{ range $j, $tv := $tvs }}
<a class="p-category" rel="tag" href="{{ blogRelative $blog ( printf "/%s/%s" $tax.Name (urlize $tv) ) }}">{{ $tv }}</a> <a class="p-category" rel="tag" href="{{ blogrelative $blog ( printf "/%s/%s" $tax.Name (urlize $tv) ) }}">{{ $tv }}</a>
{{ end }} {{ end }}
</p> </p>
{{ end }} {{ end }}

View File

@ -8,4 +8,5 @@ likeof: "Gefällt mir von"
translations: "Übersetzungen" translations: "Übersetzungen"
share: "Teilen" share: "Teilen"
speak: "Lies mir bitte vor." speak: "Lies mir bitte vor."
stopspeak: "Hör auf zu sprechen!" stopspeak: "Hör auf zu sprechen!"
oldcontent: "⚠️ Dieser Eintrag ist bereits über ein Jahr alt. Er ist möglicherweise nicht mehr aktuell. Meinungen können sich geändert haben."

View File

@ -11,4 +11,5 @@ likeof: "Like of"
translations: "Translations" translations: "Translations"
share: "Share" share: "Share"
speak: "Read to me, please." speak: "Read to me, please."
stopspeak: "Stop speaking!" stopspeak: "Stop speaking!"
oldcontent: "⚠️ This entry is already over one year old. It may no longer be up to date. Opinions may have changed."

View File

@ -10,7 +10,7 @@
{{ $blog := .Blog }} {{ $blog := .Blog }}
{{ $taxonomy := .Data.Taxonomy.Name }} {{ $taxonomy := .Data.Taxonomy.Name }}
{{ range $i, $value := (sort .Data.TaxonomyValues) }} {{ range $i, $value := (sort .Data.TaxonomyValues) }}
<li><a href="{{ blogRelative $blog ( printf "/%s/%s" $taxonomy (urlize .) ) }}">{{ . }}</a></li> <li><a href="{{ blogrelative $blog ( printf "/%s/%s" $taxonomy (urlize .) ) }}">{{ . }}</a></li>
{{ end }} {{ end }}
</ul> </ul>
</main> </main>