Genrating unique code for each page in a directory

Hi there,

I have a listings directory in the content folder I try to make use of .File.UniqueID but is there an option where I can tell Hugo to generate ids starting fro 1 and going on for example the page param


title: "Listing 1"
date: 2023-05-25T18:14:06+03:00
draft: false
listingID: 1


I want the Hugo to automatically fill the unique id for each newly created page and keep consistency 1,2,3,4,5… and so on.

How to approach this


  • There’s math.Counter, which will be unique, but the problem with that is that you will get a different ID each time you build your site, which is probably not what you want …
  • You could use {{ .RelPermalink | crypto.FNV32a }} which would give you stable numeric ID (but it would not be 1,2,3…).
1 Like

can I limit it to for example 5 digits? that will work for me

This may be OK assuming you don’t have millions of pages:

{{ substr  (.RelPermalink | crypto.FNV32a) 4 }}
1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.