How can I determine in head.html if a post is in one of the mainSections as defined in config.toml?
In config.toml, I have
mainSections = ["posts", "blog"]
What I want to do is add a meta tag in head.html if the post is in the mainSections “blog”.
I.e., for taxonomy pages, I use this in head.html to add a noindex meta tag:
{{ if .Data.Singular }}
<meta name="robots" content="noindex,nofollow">
{{ end }}
How can I do this for “blog”? This is what I want to do, but it obviously doesn’t work:
{{ if .Data.Blog }}
<meta name="robots" content="noindex,nofollow">
{{ end }}
Thanks!
Assuming this content structure:
content
├── blog
│ ├── blog-1.md
│ └── blog-2.md
└── posts
├── posts-1.md
└── posts-2.md
with config.toml
[params]
mainSections = ["posts", "blog"]
layouts/_default/single.html
{{- if in .Site.Params.mainSections .Type -}}
...
...
{{- end -}}
Thanks, this targets both blog posts and posts posts with the content structure above:
{{- if in .Site.Params.mainSections .Type -}}
And curiously, at least for posts, not the main posts page, but only single posts.
How would I target only the main blog listing and blog single posts and not posts posts?
I’m using this in head.html, not single.html.
And obviously
{{- if in .Site.Params.mainSections "blog" -}}
doesn’t work.
{{- if in .Site.Params.mainSections .Type -}}
{{- if eq .Type "blog" -}}
Irrelevant. Templating code is the same.
Ah, thanks! Using eq .Type is the key.