From ecaec9debf531309bc1f0d21633aabe490dfbb96 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Thu, 8 Oct 2020 19:21:42 +0700 Subject: all: check for zero last updated when unpacking adoc metadata If the date is zero ("0001-01-01 ...") reset it to empty string and do not render it on HTML output. --- filehtml.go | 14 ++++++++++++++ template_index_html.go | 7 ++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/filehtml.go b/filehtml.go index c3f06e6..dc4384d 100644 --- a/filehtml.go +++ b/filehtml.go @@ -8,7 +8,9 @@ import ( "fmt" "html/template" "strings" + "time" + "github.com/bytesparadise/libasciidoc/pkg/configuration" "github.com/bytesparadise/libasciidoc/pkg/types" ) @@ -90,4 +92,16 @@ func (fhtml *fileHTML) unpackAdocMetadata(doc types.Document, md types.Metadata) fhtml.Metadata[k] = fmt.Sprintf("%v", v) } } + + if len(fhtml.Date) == 0 { + return + } + + dt, err := time.Parse(configuration.LastUpdatedFormat, fhtml.Date) + if err == nil { + if dt.IsZero() { + fhtml.Date = "" + } + return + } } diff --git a/template_index_html.go b/template_index_html.go index cc9c54b..52a775e 100644 --- a/template_index_html.go +++ b/template_index_html.go @@ -39,9 +39,10 @@ const templateIndexHTML = `

{{.Title}}

- {{.Author}} -
- {{.Date}} + {{if .Author}}{{.Author}}{{end}} + {{- if .Date}}
+ {{.Date}} + {{- end}}
{{.Body}}
-- cgit v1.3-5-g9baa