I have a layout where i show the commit date with .GitInfo.AuthorDate
This works fine, except if a content file is added locally which was not committed yet,
hugo server throws an error:
executing "events/list.ics" at <.GitInfo.AuthorDate>: can't evaluate field GitInfo in type time.Time
Tried with…
{{ with .GitInfo.AuthorDate }}DTSTAMP:{{dateFormat "20060102T150405" .GitInfo.AuthorDate}}{{ end }}
But same error.
So how can i make it not throwing an error but just ignoring that line?
After re-reading your requirements: the following does not throw errors (this time tested):
{{ with .GitInfo }}
{{ with .GitInfo.AuthorDate }}DTSTAMP:{{dateFormat "20060102T150405" .GitInfo.AuthorDate}}{{ end }}
{{ end }}
If you only use the inner with-line, then Hugo has to assume, that .GitInfo exists - which throws the error. If .GitInfo would exist, but no AuthorDate then the inner line would not throw an error.
Thanks for your help, but I still get thrown this error.
The issue is that not all content .md files are committed, so .GitInfo exists, but .GitInfo.AuthorDate does not.