Hello guys. as the title said. I want to make my post auto move to “unrecognized” category if my post frontmatter (category = null’). How can i do it?
Well, you cannot automatically set a value, but you can create a page to list pages without a category.
content/categories/unrecognized/_index.md
+++
title = "Unrecognized"
date = 2021-08-11T05:56:00-07:00
draft = false
layout = "unrecognized"
+++
layouts/categories/unrecognized.html
{{ range where site.RegularPages "Params.categories" "eq" nil }}
<h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2>
{{ end }}
Thanks you so much <3. Simple but it working great .
I do not understand how that would help in this context. Please explain. Thanks.
config.toml
[[cascade]]
categories = ["unrecognized"]
[cascade._target]
kind = "page"
path = "/blog/**"
I forgot that cascade
does not overwrite existing values.
Perhaps he is indicating a cascade would help? That is make the default for categories be [ "unrecognized" ]
?
Hello. Sorry if it late. But can you explain what is that settings . I read the docs but can’t understand what is cascade
thing do
[[cascade]]
categories = ["unrecognized"]
[cascade._target]
kind = "page"
path = "/blog/**"
I hadn’t used it in the config.toml
the way @jmooring has until he showed this!
It’s called a cascade because (the way I learned about it) one sets it in a top level file (e.g. /content/blog/_index.md
) and the settings apply to everything below that page (in the case I will show, all pages in /content/blog
and any subdirectories of content/blog
(it ‘cascades’ like a waterfall).
So, in my /content/blog/_index/md
I would have (in toml format):
categories = []
[[cascade]]
categories = [ "unrecognized" ]
or in YAML format:
categories:
cascade:
categories:
- unrecognized
The categories outside the cascade is for the page itself (e.g. what on the live site would be /blog
). This is needed if you want the page where you define the cascade to have a different setting than the pages below it.
@jmooring’s solution is ‘nicer’ because you don’t need to do the extra /blog
categories setting.
If in config.toml
you set
It applies the settings in the [[cascade]]
section (categories = ["unrecognized"]
)
to any pages that match [cascade._target]
specification
In this case any page (kind = "page"
) in the path /content/blog/**
(**
means any file in /content/blog
and in any subdirectories (nested) of /content/blog
).
If you’re wondering about the /content
thing, it is because all pages in Hugo comes from the /content
directory of the root of the Hugo directory, so /content
is omitted in any Hugo config, because Hugo ‘knows’ what you mean.
Hope that’s not to confusing…it’s early/late.
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.