Skip to content

Commit

Permalink
Rename taxonomy kinds from taxonomy to term, taxonomyTerm to taxonomy
Browse files Browse the repository at this point in the history
And we have taken great measures to limit potential site breakage:

* For `disableKinds` and `outputs` we try to map from old to new values if possible, if not we print an ERROR that can be toggled off if not relevant.
* The layout lookup is mostly compatible with more options for the new `term` kind.

That leaves:

* Where queries in site.Pages using taxonomy/taxonomyTerm Kind values as filter.
* Other places where these kind value are used in the templates (classes etc.)

Fixes gohugoio#6911
Fixes gohugoio#7395
  • Loading branch information
bep committed Jun 18, 2020
1 parent 9679023 commit fc045e1
Show file tree
Hide file tree
Showing 44 changed files with 644 additions and 220 deletions.
21 changes: 21 additions & 0 deletions common/constants/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2020 The Hugo Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package constants

// Error IDs.
// Do not change these values.
const (
ErrIDAmbigousDisableKindTaxonomy = "error-disable-taxonomy"
ErrIDAmbigousOutputKindTaxonomy = "error-output-taxonomy"
)
52 changes: 52 additions & 0 deletions common/loggers/ignorableLogger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2020 The Hugo Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package loggers

import (
"fmt"
"strings"
)

// IgnorableLogger is a logger that ignores certain log statements.
type IgnorableLogger struct {
logger *Logger
statements map[string]bool
}

// NewIgnorableLogger wraps the given logger and ignores the log statement IDs given.
func NewIgnorableLogger(logger *Logger, statements ...string) IgnorableLogger {
statementsSet := make(map[string]bool)
for _, s := range statements {
statementsSet[strings.ToLower(s)] = true

}
return IgnorableLogger{
logger: logger,
statements: statementsSet,
}
}

func (l IgnorableLogger) Errorf(statementID, format string, v ...interface{}) {
if l.statements[statementID] {
// Ignore.
return
}
ignoreMsg := fmt.Sprintf(`
If you feel that this should not be logged as an ERROR, you can ignore it by adding this to your site config:
ignoreErrors = [%q]`, statementID)

format += ignoreMsg

l.logger.ERROR.Printf(format, v...)
}
13 changes: 7 additions & 6 deletions docs/content/en/content-management/taxonomies.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
---
title: Taxonomies
linktitle:
description: Hugo includes support for user-defined taxonomies to help you demonstrate logical relationships between content for the end users of your website.
description: Hugo includes support for user-defined taxonomies..
date: 2017-02-01
publishdate: 2017-02-01
lastmod: 2017-02-01
keywords: [taxonomies,metadata,front matter,terms]
categories: [content management]
menu:
Expand Down Expand Up @@ -32,7 +31,6 @@ Term
Value
: a piece of content assigned to a term

{{< youtube pCPCQgqC8RA >}}

## Example Taxonomy: Movie Website

Expand Down Expand Up @@ -97,9 +95,13 @@ Without adding a single line to your [site config][config] file, Hugo will autom
If you do not want Hugo to create any taxonomies, set `disableKinds` in your [site config][config] to the following:

{{< code-toggle copy="false" >}}
disableKinds = ["taxonomy","taxonomyTerm"]
disableKinds = ["taxonomy","term"]
{{</ code-toggle >}}

{{< new-in "0.73.0" >}} We have fixed the before confusing page kinds used for taxonomies (see the listing below) to be in line with the terms used when we talk about taxonomies. We have been careful to avoid site breakage, and you should get an ERROR in the console if you need to adjust your `disableKinds` section.

{{< page-kinds >}}

### Default Destinations

When taxonomies are used---and [taxonomy templates][] are provided---Hugo will automatically create both a page listing all the taxonomy's terms and individual pages with lists of content associated with each term. For example, a `categories` taxonomy declared in your configuration and used in your content front matter will create the following pages:
Expand Down Expand Up @@ -190,7 +192,7 @@ By using taxonomic weight, the same piece of content can appear in different pos
Currently taxonomies only support the [default `weight => date` ordering of list content](/templates/lists/#default-weight-date). For more information, see the documentation on [taxonomy templates](/templates/taxonomy-templates/).
{{% /note %}}

## Add custom metadata to a Taxonomy Term
## Add custom metadata a Taxonomy or Term

If you need to add custom metadata to your taxonomy terms, you will need to create a page for that term at `/content/<TAXONOMY>/<TERM>/_index.md` and add your metadata in it's front matter. Continuing with our 'Actors' example, let's say you want to add a wikipedia page link to each actor. Your terms pages would be something like this:

Expand All @@ -201,7 +203,6 @@ If you need to add custom metadata to your taxonomy terms, you will need to crea
---
{{< /code >}}

You can later use your custom metadata as shown in the [Taxonomy Terms Templates documentation](/templates/taxonomy-templates/#displaying-custom-metadata-in-taxonomy-terms-templates).

[`urlize` template function]: /functions/urlize/
[content section]: /content-management/sections/
Expand Down
2 changes: 1 addition & 1 deletion docs/content/en/getting-started/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ disableHugoGeneratorInject (false)
: Hugo will, by default, inject a generator meta tag in the HTML head on the _home page only_. You can turn it off, but we would really appreciate if you don't, as this is a good way to watch Hugo's popularity on the rise.

disableKinds ([])
: Enable disabling of all pages of the specified *Kinds*. Allowed values in this list: `"page"`, `"home"`, `"section"`, `"taxonomy"`, `"taxonomyTerm"`, `"RSS"`, `"sitemap"`, `"robotsTXT"`, `"404"`.
: Enable disabling of all pages of the specified *Kinds*. Allowed values in this list: `"page"`, `"home"`, `"section"`, `"taxonomy"`, `"term"`, `"RSS"`, `"sitemap"`, `"robotsTXT"`, `"404"`.

disableLiveReload (false)
: Disable automatic live reloading of browser window.
Expand Down
8 changes: 4 additions & 4 deletions docs/content/en/templates/lookup-order.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Type
: Is value of `type` if set in front matter, else it is the name of the root section (e.g. "blog"). It will always have a value, so if not set, the value is "page".

Section
: Is relevant for `section`, `taxonomy` and `taxonomyTerm` types.
: Is relevant for `section`, `taxonomy` and `term` types.

{{% note %}}
**Tip:** The examples below looks long and complex. That is the flexibility talking. Most Hugo sites contain just a handful of templates:
Expand Down Expand Up @@ -72,13 +72,13 @@ In Hugo, layouts can live in either the project's or the themes' layout folders,

{{< datatable-filtered "output" "layouts" "Kind == section" "Example" "OutputFormat" "Suffix" "Template Lookup Order" >}}

## Examples: Layout Lookup for Taxonomy List Pages
## Examples: Layout Lookup for Taxonomy Pages

{{< datatable-filtered "output" "layouts" "Kind == taxonomy" "Example" "OutputFormat" "Suffix" "Template Lookup Order" >}}

## Examples: Layout Lookup for Taxonomy Terms Pages
## Examples: Layout Lookup for Term Pages

{{< datatable-filtered "output" "layouts" "Kind == taxonomyTerm" "Example" "OutputFormat" "Suffix" "Template Lookup Order" >}}
{{< datatable-filtered "output" "layouts" "Kind == term" "Example" "OutputFormat" "Suffix" "Template Lookup Order" >}}



Expand Down
12 changes: 8 additions & 4 deletions docs/content/en/templates/output-formats.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ Formats are set based on that.
| `page` | HTML |
| `home` | HTML, RSS |
| `section` | HTML, RSS |
| `taxonomyTerm` | HTML, RSS |
| `taxonomy` | HTML, RSS |
| `taxonomy` | HTML, RSS |
| `term` | HTML, RSS |

### Customizing Output Formats

Expand All @@ -156,10 +156,14 @@ Example from site config file:


Note that in the above examples, the *output formats* for `section`,
`taxonomyTerm` and `taxonomy` will stay at their default value `["HTML",
`taxonomy` and `term` will stay at their default value `["HTML",
"RSS"]`.

* The `outputs` definition is per [`Page` `Kind`][page_kinds] (`page`, `home`, `section`, `taxonomy`, or `taxonomyTerm`).
{{< new-in "0.73.0" >}} We have fixed the before confusing page kinds used for taxonomies (see the listing below) to be in line with the terms used when we talk about taxonomies. We have been careful to avoid site breakage, and you should get an ERROR in the console if you need to adjust your `outputs` section.

{{% page-kinds %}}

* The `outputs` definition is per [`Page` `Kind`][page_kinds] (`page`, `home`, `section`, `taxonomy`, or `term`).
* The names (e.g. `HTML`, `AMP`) used must match the `Name` of a defined *Output Format*.
* These names are case insensitive.
* These can be overridden per `Page` in the front matter of content files.
Expand Down
8 changes: 1 addition & 7 deletions docs/content/en/templates/section-templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,7 @@ See [Template Lookup](/templates/lookup-order/).

Every `Page` in Hugo has a `.Kind` attribute.

| Kind | Description | Example |
|----------------|--------------------------------------------------------------------|-------------------------------------------------------------------------------|
| `home` | The home page | `/index.html` |
| `page` | A page showing a _regular page_ | `my-post` page (`/posts/my-post/index.html`) |
| `section` | A page listing _regular pages_ from a given [_section_][sections] | `posts` section (`/posts/index.html`) |
| `taxonomy` | A page listing _regular pages_ from a given _taxonomy term_ | page for the term `awesome` from `tags` taxonomy (`/tags/awesome/index.html`) |
| `taxonomyTerm` | A page listing terms from a given _taxonomy_ | page for the `tags` taxonomy (`/tags/index.html`) |
{{% page-kinds %}}

## `.Site.GetPage` with Sections

Expand Down
Loading

0 comments on commit fc045e1

Please sign in to comment.