Custom URL based on nanoid

Let’s say I have a file with an id field in the Front Matter.

---
id: F39umGIP7eseg-FYCNBin
title: "Demo"
---

Markdown content

Is there any way I can set this as the URL for this post?

I want each and every post to have a unique nanoid/url regardless of where it’s placed in the directory or its filename. So even if I change the name or place of the file, later on, the URL shouldn’t be changed.

Is this possible in Hugo?

Maybe this can help

Sorry, I’m not really sure from the examples provided here if they’ll achieve what I want. I think slug is what I’m looking for.

I’ll have to try it out and see. I’ll let you know if it works.

Thanks.

url will work best if you need everything relative to the root (e.g. example.com/url). So, even if you move files around between folders, the link remains the same. “Slug” behaves like the last part of a path, so if not configured in the configuration file, it might invoke he directory paths before it. Maybe your question could have been a bit clear (do you want the ID to be the URL?)

1 Like

Yes, I want the id to be the URL. I’ve also tried both slug and url options and you are right, url is the one that gives the desired result.

Thanks for your help :slight_smile:

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