gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
75.81k stars 7.54k forks source link

Add a "richer" taxonomy configuration #5520

Open bep opened 5 years ago

bep commented 5 years ago

See #5513 -- I will fix that issue so it works as described there, but looking at that issue I realize that many taxonomy related workarounds (and also limitations on what we can do) is rooted in the litle bit to limited configuration options.

In the above issue, @randallmlough was creative and created a taxonomy configuration like the one below:

[taxonomies]
"news-tag" = "news/tags"
"news-category" = "news/categories"

I have made the above a little simpler to wrap my head around it.

The term in the source code used about a taxonomy configuration definition is that the key (news-tag is the singular form and the value is plural. The plural is what you define in front matter and that is used to construct the taxonomy URLs (e.g. news/categories/index.html).

The above works nicely, but you get a tight coupling between content and taxonomy URLs and possibly miss out on other features that is now hard to implement.

I suggest that we as an alternative to the string plural allows a more "complex object":

[taxonomies]
[taxonomies.news-categories]
path = "news/categories"
title = "This is the news"
weight = 30

The above is quickly jotted down, but the thought is that it is the name that defines the front matter key (note that this will default to path which is the same as plural in the "old" way).

This would also make the content less coupled to the URL config:

+++
title = "foo"
news-tags = ["a", "b", "c"]
+++

Content.

/cc @regisphilibert @kaushalmodi @digitalcraftsman @onedrawingperday and gang

regisphilibert commented 5 years ago

I suggest that we as an alternative to the string plural allows a more "complex object":

If the key/value pairs allowed is not limited, this would also be a cleaner way of adding Front Matter to taxonomies (without having to create a content/my-taxo/_index.md).

"path" = "news/categories"

Why path and not URL? Will this parameter also influence the template lookup logic?

onedrawingperday commented 5 years ago
[taxonomies]
[taxonomies.news-tag]
"name" = "news-tags"
"path" = "news/categories"
title = "This is the news"
weight = 30

Hm... I like the above A LOT. It would also eliminate the need to replicate a taxonomy URL as a folder PATH so that we can insert meta data to the list page (exactly as @regisphilibert said above)

@bep I am 100% in favor of what you propose here.

bep commented 5 years ago

Why path and not URL?

It's not a URL. It's used to construct the URLs and the filepaths (news/categories/index.html etc.), but it does not represent "something complete".

This is not related to templates/layouts (not now, anyway).

regisphilibert commented 5 years ago

I suppose this will also influence the filepaths and URLs of its terms: /news/categories/politics

Also, let's say the user needs to have a bundle or some Front Matter outside of their config file. With path set to news/categories will the content dir for this taxonomy (and its terms) still be at the root:

content/news-tags/_index.md
content/news-tags/politics/_index.md

Or under the path value:

content/news/categories/_index.md
content/news/categories/politics/_index.md

I'm asking a lot about this path key because I don't think I ever saw it for other page Kinds.

bep commented 5 years ago

I'm asking a lot about this path key because I don't think I ever saw it for other page Kinds.

Because this is a "new thing". We could call it ... section if that is familiar, but that would probably be even more confusing. But ... path is the same "thing" as the right side of the current taxonomy config. Exactly the same thing. Only more excplicit and more clear (to me, at least).

regisphilibert commented 5 years ago

Ok I understand. As a user, for me the right side of the taxonomy config was just the plural. I never thought passed that.

bep commented 5 years ago

for me the right side of the taxonomy config was just the plural.

I guess the word "plural" is used in the documentation, which I think is fairly confusing. But I guess it creates a convention (categories, tags). We currently only use the "plural" string (that is used in both front matter and as a path element for taxonomies list and terms).

moorereason commented 5 years ago

I like where you're headed here. One comment:

[taxonomies.news-categories]
name = "news-categories"

The name key/value pair is redundant. We can use the table name as the taxonomy name.

bep commented 5 years ago

Why path and not URL?

I notice that we do use url in the front matter for a "similar thing" -- so even if it may not be totally accurate, maybe it is better to be consistent.

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help. If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open. If this is a feature request, and you feel that it is still relevant and valuable, please tell us why. This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.

randallmlough commented 5 years ago

Has there been any more thinking about this? This would really help sites that provide a lot of different content types

sokolovstas commented 5 years ago

Maybe would be useful to configure different fields name in front matter with same taxonomy term like this:

[taxonomies]
[taxonomies.users]
"name" = ["workers", "assistants"]
"path" = "users"

so we can use one term in many fields?