Lego2012
5/25/2017 - 9:41 AM

Destination Path via Front Matter

Destination Path via Front Matter

slug

When defined in the front matter, the slug can take the place of the filename for the destination.

content/posts/old-post.md

---
title: New Post
slug: "new-post"
---

This will render to the following destination according to Hugo’s default behavior:

yoursite.com/posts/new-post/

section

section is determined by a content’s location on disk and cannot be specified in the front matter.

type

A content’s type is also determined by its location on disk but, unlike section, it can be specified in the front matter. This can come in especially handy when you want a piece of content to render using a different layout. In the following example, you can create a layout at layouts/new/mylayout.html that Hugo will use to render this piece of content, even in the midst of many other posts.

content/posts/my-post.md

---
title: My Post
type: new
layout: mylayout
---

path

path can be provided in the front matter. This will replace the actual path to the file on disk. Destination will create the destination with the same path, including the section.

url

A complete URL can be provided. This will override all the above as it pertains to the end destination. This must be the path from the baseURL (starting with a /). url will be used exactly as it provided in the front matter and will ignore the --uglyURLs setting in your site configuration:

content/posts/old-url.md

---
title: Old URL
url: /blog/new-url/
---

Assuming your baseURL is configured to https://yoursite.com, the addition of url to the front matter will make old-url.md render to the following destination:

https://yoursite.com/blog/new-url/

You can see more information on how to control output paths in URL Management.