Categories/content got two links generated

I am creating a blog for my daughter and baring it on my other creation, but experienced strange behaviour here:

in config.toml I added

[permalinks]
tags = "/tag/:slug/"
categories = "/category/:slug/"
authors = "/author/:slug/"

So that link to the category will be like that /category/writing/
So Title of this page based on that:

<span>Posts in category {{.Title}}</span>

Will be

Posts in category Writing

However, noticed by accident that there is also a link /writing/ in the root directory that refers to almost that same page but with a different Title.

Posts in category Writings

Have a look at s added to the category Writing.

/category/writing/ > {{.Title}} = "Writing"
/writing/ > {{.Title}} = “Writings”`

Why is that and how to get only a list of pages in the category with slug /category/ on the front, not both?

Ref to that behaviour I found here

The default behavior of Hugo is to pluralize list titles; hence the inflection of the quote section to “Quotes” when called with the .Title page variable. You can change this via the pluralizeListTitles directive in your site configuration.

ps.
I placed each post in a content folder in its folder that is based on the category name, hence this is why this is generated like that, however, how could I turn this off? possible?

As I read here

All content for your website will live inside this directory. Each top-level folder in Hugo is considered a content section. For example, if your site has three main sections—blog, articles, and tutorials—you will have three directories at content/blog, content/articles, and content/tutorials. Hugo uses sections to assign default content types.

Hence that planned behaviour.

Can this be disabled or add redirection to /category/?

Similar behaviour I noticed on other sites when I put /posts/ into subfolder by date (but url for each post is based on the root directory, the sorting is mainly for my organisation of files).

I see link generated /posts/ which is almost a duplicate what’s on :root address so would prefer to redirect it to :root. When redirection is not an issue, would prefer to get this done automatically rather than generate redirection to each folder in /content/ directory if possible?

Don’t do that.

What’s better solution when you don’t want go through the list of 500 markdown files in markdown editor?

At a high level, the problems you are experiencing are related to content modeling.

In your project, the structure of your content directory must be driven by the content model.

Do not let other considerations such as URL management or “finding content in my markdown editor” drive the structure of your content directory. In this respect, Hugo is no different than any other content management system.

In the WordPress and Drupal communities, a frequently asked question is, “Should I create a content Type, or should I assign a Taxonomy Term?” The answer is never both.

Take, for example, a software company that provides products and services to the construction, education, and manufacturing markets. Their site needs to describe each product, each service, and it must provide software tutorials.

Deriving the content model from the markets served is nonsensical.

content/
├── construction/
│   ├── products/
│   ├── services/
│   └── tutorials/
├── education/
│   ├── products/
│   ├── services/
│   └── tutorials/
└── manufacturing/
    ├── products/
    ├── services/
    └── tutorials/

With Hugo, the content Type is determined by the content subdirectory[1] .

“Construction” is not a “type” of content. Instead, it is one of many ways to classify the content. The structure below makes more sense, where industries is a taxonomy with a vocabulary of the following terms: construction, education, manufacturing.

content
├── products/
│   ├── product-a   # industries = ['construction','manufacturing']
│   └── product-b   # industries = ['education']
├── services/
│   ├── service-a   # industries = ['construction','education','manufacturing']
│   └── service-b   # industries = ['construction', manufacturing']
└── tutorials/
    ├── tutorial-a  # industries = ['education','manufacturing']
    └── tutorial-b  # industries = ['construction','education','manufacturing']

One of Hugo’s strengths is its flexibility, but this can cause problems if misused. There are several cases in this forum, with setups similar to the one you describe, where the user experienced indeterminate section rendering due to page collisions. In all cases, the user was letting other considerations such as URL management or “finding content in my markdown editor” drive the structure of the content directory.

Please think about this for a bit, and consider changing your structure. I obviously put significant effort into this reply, so I think it is an important consideration before trying to address the specific problems you described.


  1. Yes, you can override this in front matter to target a particular layout for rendering, but it should not be used for content modeling. ↩︎

1 Like

@idarek I think using taxonomies can help you work around this issue. You would need this content structure ./content/posts/writing/post.md. Then set pluralizeListTitles = false and disableKinds = ['taxonomy'] in your config file. In ./layouts/_default ensure you have a taxonomy.html file with your category structure (the code itself) and a section.html file with this code {{ "<!-- Layout with no content to avoid WARN message about missing page layout -->" | safeHTML }}. This works for my test site, so give it a go and see if it works for you. (Navigating to /posts/ should give a blank page locally and 404 page on your host. Same for /writing/. But /category/writing/ should work normally.)

NB: Hugo’s documentation for Nested sections is very scarce.

Decided to rethink that as @jmooring suggested as don’t want to get this too complicated, as it’s not only about the folder, but other things in hugo that will have impact.

Decided to go back into the /content/ folder with markdown files and if I need to put some into folders like in my example above, I used _redirect to sort that (but don’t need in my current project).

Thank you all.