I am trying to find a post, that solved an issue like the following. I pretty sure remember that was solved, but I fail to find it.
I have a template for my search feed like the following:
{{- $.Scratch.Add "index" slice -}}
{{- $section := $.Site.GetPage "section" .Section }}
{{- range .Site.AllPages -}}
{{- if or (and (.IsDescendant $section) (and (not .Draft) (not .Params.private))) $section.IsHome -}}
{{- $.Scratch.Add "index" (dict "objectID" .File.UniqueID "date" .Date.UTC.Unix "description" .Description "dir" .File.Dir "expirydate" .ExpiryDate.UTC.Unix "fuzzywordcount" .FuzzyWordCount "keywords" .Keywords "kind" .Kind "lang" .Lang "lastmod" .Lastmod.UTC.Unix "permalink" .Permalink "publishdate" .PublishDate "readingtime" .ReadingTime "relpermalink" .RelPermalink "html" .Params.Description "title" .Title "type" .Type "url" .Permalink "weight" .Weight "wordcount" .WordCount "section" .Section "tags" .Params.Tags "categories" .Params.Categories "author" .Params.authors "content" .Params.Description "excerpt_html" .Params.Description "excerpt_text" .Params.Description "summary" .Summary)}}
{{- end -}}
{{- end -}}
{{- $.Scratch.Get "index" | jsonify -}}
The line in the middle (.Scratch.Add) throws an error:
WARN 2020/09/18 16:24:01 .File.UniqueID on zero object. Wrap it in if or with: {{ with .File }}{{ .UniqueID }}{{ end }}
Doing that would introduce a new issue: The feed requires a unique ID per line. Just going with with
might result in multiple items with null ID. Using time or nano time seems to create identical IDs.
What’s the appropriate way to create a unique ID here?