How to hash custom output format?

Hi, I use custom output format to generate search index, is it possible to generate a hash (according to the content) for those output files to avoid using out-of-date caches?

{{- with .Home.OutputFormats.Get "SearchIndex" }}
  {{- $indexURL := printf "%s?v=%s" .RelPermalink "hash_string" }}
{{- end }}

I’ve read the OutputFormat and Output, but couldn’t find any useful variable can be used by hash (md5).

Is there a workaround to get the content of generated output? I’ve tried to use GetPage, but with no luck (nopPage).

{{- warnf "%v" (.Site.GetPage "/search.json") }}

I could use partialCached to fetch the content from build caches, but I believe that there is an easy way to do that. And in my case, I want to collect all related outputs from all sites, partialCached might become a potential buggy implementation (the context).

I guess you could do {{ $hash := .Name | crypto.FNV32a }}.

Sorry for providing the wrong example (.File.UniqueID), I wish to generate a hash string about the content, which will be changed according to the content.

How about:

{{- with .Home.OutputFormats.Get “SearchIndex” }}
{{- (. | fingerprint).RelPermalink }}
{{- end }}

Thanks for your quick reply, but I got an error.

error calling fingerprint: *page.OutputFormat can not be transformed

OK, sorry – yea right, what you want isn’t particulary straight forward to do currently, and the only hackish way I know of is:

  • Make sure the search index is created first (set the weight on output format)
  • In the template for search index, add a .Store.Set "hash" ... or something.
1 Like