How to display ancestors, not just first section? #63
-
Sorry for the vague title. I couldn't figure out better title for this problem. By default, HB Cards Theme shows Topmost Section next to Estimated Read Time. I want to display the page's ancestors like 'Section 1 / Section 1-2 / Section 1-2-3', so I modified {{- /* Don't use .FirstSection (everything become 'Blog') */ -}}
{{- with .CurrentSection -}}
<span class="hb-blog-post-section">
<div class="badge bg-secondary text-decoration-none fw-normal">
{{- range .Ancestors.Reverse -}}
{{- if or .IsHome (eq .Title "Blog") -}}
{{- continue -}}
{{- end -}}
<a class="bg-secondary text-decoration-none fw-normal" style="color: var(--hb-badge-color);" href="{{ .RelPermalink }}">{{ .Title }}</a>
<div class="bg-secondary text-decoration-none fw-normal" style="display: inline-block; color: var(--hb-badge-color); opacity: 0.45;"> / </div>
{{- end -}}
<a class="bg-secondary text-decoration-none fw-normal" style="color: var(--hb-badge-color);" href="{{ .RelPermalink }}">{{ .Title }}</a>
</div>
</span>
{{- end -}} I didn't want to show 'Blog' in sections, I added corresponding code too. Here is a breif summary of this modified code.
But recent change broke my code. I tried to update my code to fit latest update, but I couldn't. How can I fix my code to display things as it used to do? PS. Should I create my own partial |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 33 replies
-
I'm afraid not possible, since it was cached by the firstSection. I can treat it a feature request instead, are you want to display the closest parent section instead? |
Beta Was this translation helpful? Give feedback.
-
Is there any reason to remove
Yes, the newer changes cache partials which will produce same output as far as possible. |
Beta Was this translation helpful? Give feedback.
-
With github.com/hbstack/[email protected], you can disable the first section by configuring cascade. // hugo.yaml
cascade:
- _target:
path: /**
params:
meta:
first_section: false And then create // params.yaml
// ...
hugopress:
modules:
hb-custom:
// ...
hooks:
hb-blog-post-meta:
cacheable: false With this, you don't have to care about upstream changes, you can append any meta you want. |
Beta Was this translation helpful? Give feedback.
With github.com/hbstack/[email protected], you can disable the first section by configuring cascade.
And then create
hb-blog-post-meta
hook, and save it aslayouts/partials/hugopress/modules/hb-custom/hooks/hb-blog-post-meta.html
, please do not forgot to configure it in params.yaml to tell hooks system to load it.With this, you don't have to care about upstream changes, you can append any meta you want.