diff options
| author | Shulhan <ms@kilabit.info> | 2020-10-08 19:21:42 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2020-10-08 19:21:42 +0700 |
| commit | ecaec9debf531309bc1f0d21633aabe490dfbb96 (patch) | |
| tree | 53b14fb247ec2d1406c22c6b7825080f12acd5aa | |
| parent | 396d45eee46ad4dcf33c224053e79373cf881f77 (diff) | |
| download | ciigo-ecaec9debf531309bc1f0d21633aabe490dfbb96.tar.xz | |
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.
| -rw-r--r-- | filehtml.go | 14 | ||||
| -rw-r--r-- | 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 = `<!DOCTYPE html> <div class="container"> <h1>{{.Title}}</h1> <div class="meta"> - {{.Author}} - <br /> - {{.Date}} + {{if .Author}}{{.Author}}{{end}} + {{- if .Date}}<br /> + {{.Date}} + {{- end}} </div> {{.Body}} </div> |
