Is it possible to prevent Hugo from automatically generating the taxonomy pages? I ask because I’m using taxonomies for purely internal purposes and don’t need or want any sort of listing page for the taxonomy.
Cheers,
Eric
Is it possible to prevent Hugo from automatically generating the taxonomy pages? I ask because I’m using taxonomies for purely internal purposes and don’t need or want any sort of listing page for the taxonomy.
Cheers,
Eric
I believe the folder structure will be created regardless. If your layouts are empty, your robots.txt avoids crawling the blank pages, and you create redirects (per @digitalcraftsman comment below), I think that would take care of your use case.
Also, you can add whatever front matter you want to your content files, but I believe that only tags and categories are the taxonomies that are generated by default. Any other taxonomies you use won’t be considered as such (ie, as taxonomies) unless you declare them explicitly in your config file.
Is any of this helping, @emarthinsen?
I’m not aware of an option to turn the generation of taxonomy pages of. But you could create a template that redirect users if you want to avoid blank pages.
@rdwatters - Yeah, it’s definitely helpful.
I’m contemplating creating a task that runs after the build to strip out the pages I don’t want. I do wish the creation of the taxonomy pages was more configurable.
Did you try overwriting what is considered to be a Taxonomy?
For example:
[taxonomies]
tag = ""
group = ""
category = ""
Might work in your favour.
Taxonomies are only generated for taxonomies defined in the configuration. The default is tags & categories, but if you set it to nothing than no taxonomy files will be generated.
Hah, so essential, I was right, correct? I’m getting the hang out of this.
I can certainly remove taxonomies from the config. The question is, can I still add a page to a taxonomy that isn’t defined in the config? For instance, let’s say I want to use a “project” taxonomy. Can I add that to my frontmatter:
+++
projects = ["World Domination", "Excel"]
+++
and then retrieve posts for that taxonomy elsewhere?
<ul>
{{ range .Site.Taxonomies.projects.excel }}
<li><a href="{{ .URL }}">{{ .Name }}</a></li>
{{ end }}
</ul>
What I’m trying to do is use a taxonomy internally, but not create any of the default-generated taxonomy pages.
Note, just removing it, makes it default back to tags and categories. You have to explicitly overwrite it.
If you don’t explicitly define something in the config as a taxonomy then it isn’t one. A taxonomy has a very specific meaning in Hugo. It’s explicitly a way to organize content for the final site and is built in with term and listing pages.
If it’s not a taxonomy it’s just meta data and Hugo will just treat that like all the other meta data you specify on the content. Read up more on the front matter… http://gohugo.io/content/front-matter/
@emarthinsen I think the confusion surround the use of “taxonomies” here. I also think I’m understanding what you mean by using the taxonomies “internally.”
In Hugo, taxonomy has a very specific meaning (ie, specific insomuch as it’s similar to the way Wordpress might leverage the idea as well). A taxonomy is a piece of front matter (ie, metadata) that has been identified to build key-value (ie, key list pages and value single pages) as part of your final output site. You can refer to the taxonomy overview to get a better idea of this.
Any front matter you put in your individual content (eg, /content/your-content-whatever.md
) files can be accessed using your templating logic, but only those keys you set up as taxonomies are available to you when creating your list/single taxonomy pages. I think you’re just getting confused in the templating logic layer. E.g., lets say you have a piece of metadata in every .md
file for author:
.
title: My First Title
date: 2016-02-08
publishdate: 2016-02-09
description: This is a description of my first page.
author: Jon Doe
If you wanted to access this page based on author, you could use {{ range where '.Param.author' 'Jon Doe'}}
DO WHATEVER {{ end }}. This, however, only offers you the convenience of adding that templating in specific areas of your site (or partials).
However, let’s say you want to keep a list of all your authors and what each author has written. You might then have front matter as follows:
title: My Second Title
date: 2016-02-08
publishdate: 2016-02-09
description: This is a description of my second page, which has multiple authors.
authors: [Jane Doe, Jon Doe, Bill Bob]
You could then specify authors
as a taxonomy in your config.toml file as follows:
[taxonomies]
authors = "authors"
Then in /layouts/taxonomy/author.html
to show all the pieces written by an individual author:
<h1> Pieces Written By {{ .Title }}</h1>
<ul class="all-titles-by-specific-author">
{{ range .Data.Pages }}
<li>{{ .Title }}</li>
{{ end }}
</ul>
Using the above example, yoursite/authors/jane-doe
would then render as:
<h1>Pieces Written by Jane Doe</h1>
<ul class="all-titles-by-specific-author">
<li>My Second Title</li>
</ul>
If you are not interested in creating any taxonomy pages, see the advice from @Skarlso above. You have to specifically set tag
and category
to no value since these are the only two taxonomies that are included with Hugo by default.
#config.toml
[taxonomies]
tag = ""
category = ""
Does that help?
Thanks for the clear post rdwatters.
By the way, perhaps the Hugo command line messages can be improved. With this in the config file:
[taxonomies]
category = “”
tags = “”
Hugo 0.15 prints to the command line:
Change detected, rebuilding site
2016-02-16 13:27 +0100
31 of 31 drafts rendered
0 future content
315 pages created
0 paginator pages created
0 created
0 created
in 953 ms
Instead of saying 0 created
(which can be confusing → created nothing of what?), it would make more sense to say 0 categories created
(as a confirmation) or just drop the line completely.
(Just my 2 cents for thinking along ).
Hi, this solution does not work for sitemap.xml. Any other ideas?
You can use the disableKinds
option for that in your config.toml
file. Just add the following:
disableKinds = ["sitemap"]
And Hugo should not generate a sitemap anymore.
If you just define an empty set of taxonomies, it will obliterate all mentions of default taxonomies in all files.
(just putting a naked “[taxonomies]” with nothing beneath it worked for me.)
@FrescoWesco How about not including taxonomies
at all. I believe this came up before that if you don’t mention it all (the idea of setting tags
and categories
to empty strings was a previous hack), Hugo’s default behavior is now to render nothing…
The behavior I am encountering goes as follows:
disableKinds: ["taxonomy","taxonomyTerm","sitemap"]
seems to work well. My site is just for a small biz, no need for categories or tags at the moment. I like to make my own sitemap for some reason.
A post was split to a new topic: Help! I don’t know forums or how taxonomies work!?!
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.