Multiple permalinks

Hi,

I’ve been reading this documentation:

What I am seeking to do is create two permalinks for the same post, one organized by date, the other with a title - like so:

'/:year/:month/:day'
'/:year/:month/:slug'

Creating, essentially, a human memorizable shortlink, and one better for computers - to be specific, this would allow me to setup permashortlinks trivially.

I understand I can manually create a suitable alias inside the post file, but I would like hugo to create the alias automatically for all posts.

Wondering if this is possible?

2 Likes

— not answering your main question —

Using 2 links (just as a links) to that same article is bad for SEO.
Google and others will penalize you for Duplicated Content.

To do this correctly, one link shall be set as canonical.
The best is to do a 301 redirects but you can also use the Hugo aliases feature.

---
url: 
aliases:
---

— back to your question —

Re to '/:year/:month/:day' just create a folder structure in YYYY/MM/DD and that’s will be sorted by default unless url specified. Then do alias manually or specify archetype for that do this automatically based on filename if you will be using hugo new to add post.

For example this:

title: "{{ replace .Name "-" " " | title }}"

Will create title automatically prefilled based on markdown filename (that may be your slug)
Next, just sort the year and date automatic generation.

for example:

aliases: /{{ dateFormat "2006" .Date }}/{{ dateFormat "01" .Date }}/{{ replace .Name "-" " " | title }}

The aliases however are meta redirects hence you will not be using them for positioning in search engines and the only 1 URL shall be.

I’m not sure if it’s possible but it’s a very good idea to add support in Hugo.

Something like the following.

It could be something like:

baseURL = "https://google.com/"
shortURL = "https://g.goog/"

The default [permalinks] configuration would be something like:

shortener = "/:random[7:10]/"
  • [7:10] = minimum to maximum characters
  • :random = [a-zA-Z][0-9]

Would need some collision check though.

Or, you can do something like:

shortener = "/:shortslug-:random[2:5]/"
  • :shortslug = frontmatter param like slug but only used to give more control to your shortURLs

Together, it will lessen collisions too.

In any case, yeah, currently I’m not so sure there’s an easy way to integrate short URLs into Hugo without actually using a hosted script which generates and stores the generated shortened URLs in some database.