Additional slug or permalink for content pages

I’m currently building a Hugo website that is basically a kind of catalogue. The info about all catalogue entries is stored in a YAML file. Every entry has got an ID that consists of a letter and a number. I use hugo-data-to-pages to generate content pages from the YAML file. Each content page is stored under content/entries/[id]/index.md so that, for example, example.org/entries/g3/ is a valid URL.

I will regularly revise the catalogue in the future, for example by changing the listing order of the entries. Since this will change the IDs I cannot use them for a permanent link. That’s why I gave each entry a slug parameter making the URL change to example.org/entries/[slug].

Now, I still want the user to be able to access the entries using their ID, meaning I want all content pages to still be also available under the original example.org/entries/[id] path.

How do I achieve that?

It would probably be possible to configure hugo-data-to-pages to create a duplicate of the catalogue with the ID path. However, I’d like to do it “correctly” and not to “only make it work”.

Thank you!

I am relatively ignorant to how hugo-data-to-pages works. IF it creates markdown files from your data file then you probably have a template somewhere how the tool should format your content files.

Frontmatter aliases is then what you want to look into:

aliases = ["some other path", "and another"]

will create two redirects to the current content file URL.

If it is some JS solution that just serves the content somehow from your data file, then it’s probably a good idea to open an issue in the project itself to come to a solution.

2 Likes

Yes, hugo-data-to-pages just creates markdown files with the respective YAML as front matter.

Thanks, that’s exactly what I need! I’ve added an aliases parameter to each entry and now it works exactly the way I wanted it to.

But what would I need to do if I didn’t want to create a redirect to the slug path but instead wanted the actual content itself to be available under the ID path?

It’s not possible to create three pages for one page and two aliases… you would probably have to add three items (pages) for that with identical content. This might solve your issue, but will lead to “double content” and SEO-hell… If you are ok with that :wink: go with it. Else live with the aliases.

Another solution would depend on what server you use. Some servers (Apache) can do some magic and serve rewritten content without redirecting, but this is out of the scope of Hugo and I never tried it.

1 Like

Okay, thanks, then I’ll stick with the aliases :smile:

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