Configure post url for hugo website
19 February 2025 | Updated on 27 February 2025
Configure post url permalink settings for hugo website and get warnings in case you create pages with duplicate slugs that would result in url collisions.
Configure permalinks for page types
- change
permalinks
settings in yourhugo.yaml
configurationpermalinks: # post: "/:year/:month/:slug/" post: "/:slug/"
Problem: Identical post URLs
- hugo will lets you create multiple pages with the same slug/url warning
- in case you changed
permalinks
behaviour to ignore subfolder structures like year and month collisions could happen more often
Get warnings for duplicate paths
- be sure to include drafts via
-D
hugo --printPathWarnings -D
- of course you can also include this flag into your dev server command
hugo server --buildDrafts --disableFastRender --cleanDestinationDir --printPathWarnings
Custom post url via slug
- use the front matter of your post/page to configure the
slug
manually. - to create a useful
slug
by default you can adjust page archetypes
Example archetype configuration
- you could change the
archetypes/default
to the following content:--- draft: true date: '{{ .Date }}' # lastmod: '{{ .Date }}' # tags: # - tag1 # - tag2 title: '{{ replace .File.ContentBaseName "-" " " | title }}' slug: '{{ replace .File.ContentBaseName " " "-" | strings.ToLower }}' # description: 'writeyourdescriptionhere' ---
- and use a permalinks configuration with
/:slug/
only (as seen at the beginning) - then use the following command to create a new post:
hugo new content posts/2025/02/my-new-blog-post/index.md
- the post is structured by subfolders in your git repo (year, month)
- but hugo will generate a website without year or month in the url
Additional resources
Related content
You can add interactive diagrams to your hugo page via plotly.
Learn how to structure your pages so you do not only get one big list of blog posts.
Create a bash script which loads and environment variables via an .env file and allows you to call different sub commands via functions.
Learn how to configure the code highlighting chroma theme in hugo hextra.