Build year-month-day permalink from custom metadata

Hi all,

I am using year-month-day-permalinks like this:

  post: "/:year/:month/:day/:title"

Is it possible to build a year-month-day-permalink from custom metadata and not from builtin date?


I create events with a startdate and enddate metadata. How can I use startdate to build the permalink?

If I use date I have to use --buildFuture to display the events.

Sounds like you are asking to use a front matter parameter in the permalink, but that won’t work. You can use the permalink configuration values.

However, any piece of content can have it’s URL overridden in front matter. I’d probably combine a custom archetype with a slug or URL set to the path you want.

Special note: even if you use a pattern like /:year/:month/:day/:title, it won’t generate all the paths implied.


Not generated:

Given that, I might add the start date of the event in the filename, and have the archetype figure it out from there, and avoid sub-folders in the URL. :slight_smile:

So you think I should build the path from the filename? Somewhere I saw a hint to this.

I fear that all solution that comes to my mind implies a lot of work because the site (mis)uses the date metadata to build event pathes for quite a long time. Only after updating hugo to a current version it stops building future content by default. As it also uses the filename as last part of the url I fear that I have to insert aliases in all events to prevent breaking links in the internet pointing to the site.

My hope was that there is some trick to use another date string metadata for building the path.

Something like this in config.toml:

    base = startdate
    event = "/events/:year/:month/:day/:filename"

“base” points to the frontmatter metadata that is used to build the path.

If you really want those values in the URL, just put your events in sub-directories.

If an event is happening on November 12, put your content at content/events/2018/11/12/

The date front matter is for publication date, whereas you want start and end date elsewhere. In your archetype you could even set the start date by the file path, I think. But it will require some transformation to set the correct value.

1 Like

Did you get this figured out? This is exactly how I want to configure my weblog so I can import and existing WordPress blog and maintain my old links.

@juh2 was trying to accommodate a date-based permalink pattern based on event date, as opposed to publish date for the post.

@fahrni Are you importing events from WordPress, or just posts? Normally posts use the publish date for permalinks.

Posts. Here’s what I’m after.

This is how I structured my WordPress posts. I want the exact structure with Hugo so my links don’t break if someone visits after I’ve switched over.

It seems like my new posts need to be created in that structure?

Your use case is very straightforward, you don’t need to put them in sub-directories. That was a very specific solution, among many, for the event date issue.

For what you want, you just set the permalinks as usual. In fact, the topic post has settings you can use:

  post: "/:year/:month/:day/:title"

See all the permalink config values, they are very similar to structure tags in WordPress.