Permalink confliction

Hi, I need help for solving confliction on permalink. I mean, I want to control what happens when two pages have the same permalink.
By defalut, Hugo seems to override the older one with newer one without warning.

Basically I set a date and a slug for the posts with filename (2019-10-26-this-is-a-slug.md), and set my Permalink /:slug.
I need some solution for this, like in these ways:

  1. automatically add some number to newer conflicting permalink. Like renaming /posts/this-is-a-slug/ to /posts/this-is-a-slug-1/
  2. Raise an error when confliction found and abort building pages.

I have set my config.toml as below:

baseURL = "http://example.org/"
languageCode = "en-us"
title = "My New Hugo Site"
theme = "ananke"

[permalinks]
  posts = "/:slug/"

[frontmatter]
  date = ["date", "publishDate", ":filename", "lastmod"]

I searched a lot and found nothing about how to control the conflicting permalinks.
Thank you in advance for helping me.

1 Like

Why not instead set permalink config to filename?

[permalinks]
  posts = "/:filename/"

You can’t have two files with the same filename, so as a consequence the generated permalinks should be unique.

That is what I’m planning to do if there is no solution.
I want to avoide it because it makes the url longer :disappointed_relieved:
Thanks anyway

As of v0.55.0, hugo has this flag:

--path-warnings   print warnings on duplicate target paths etc.

IMHO, this should flag should default to on.

5 Likes

Thank you so much! Although Hugo keep bulding and exit with 0, now I know there are duplicate paths. I hope there is a option to abort building if there are warnings.

1 Like