zad
zad

Reputation: 93

Section Hierarchy in Hugo

I'm trying to build a structure for permalinks in Hugo + blogdown where a post will have the permalink structure of

websitename/category/slug

Not sure how to do this because I've set the config.toml permalink structure to

    [permalinks] 
        posts = "/:section/:slug"

and I place the post (an .md file) into a folder, which is a category, underneath the posts file but I get a url similar to websitename/posts/category/slug... when what I really want is websitename/category/slug.

I was hoping to make the category the section, but not have "post" in the URL.

I'm still trying to figure out where to place the _index.md file but have not been very successful. Any help would be appreciated.

Upvotes: 4

Views: 1179

Answers (1)

TC Zhang
TC Zhang

Reputation: 2797

The permalink is set on a per section basis. The sections are the first-level directories under content, not under content/posts/.

So, if you want the permalink to be websitename/category/slug, arrange category directories(or sections by the Hugo term) like this:

content
├── category1
│   └── 2015-01-04-first-post.md
├── category2
│   └── 2015-01-27-dear-diary.md
├── _index.md
├── page
│   └── about.md
└── post
    ├── 2017-03-07-bigimg-sample.md
    └── 2017-03-20-photoswipe-gallery-sample.md

and set

[permalinks] 
    category1 = "/:section/:slug"
    category2 = "/:section/:slug"
    page = "/:section/:slug"
    post = "/:section/:slug"

in your config.yaml

Source: https://gohugo.io/content-management/urls/#permalinks

Upvotes: 2

Related Questions