How to create a unique ID for non-file-based pages

I see that we have the following to add a unique ID to any page that is based on a Markdown file:

{{ with .File }}
  {{ .UniqueID }}
{{ end }}

Is there something comparable for non-file-based pages or is it “ok” to “just” MD5 a bunch of parameters like this:

{{ $unique := printf "%s%s%s" .Kind .Section .Slug }}
{{ md5 $unique }}

I am only worried about the performance of this solution, not if people might call me a script kiddie :wink: will it slow down on large sites?

Within a given language (site) the .Page.Path value is unique, and the page does not have to be backed by a file (v0.123.0 and later). If you want a globally unique ID add .Page.Language.Lang. Then pass it through crypto.FNV32a to get something short. Something like:

{{ $uid := printf "%s/%s" .Language.Lang .Path | crypto.FNV32a }}
1 Like