Skip to content

Commit

Permalink
Assign correct header to sub sections and articles
Browse files Browse the repository at this point in the history
  • Loading branch information
julianbyte committed Nov 8, 2024
1 parent 8840122 commit 8c9575c
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,7 @@
## 2024-11-04
### Fix
- Fixes deprecation warnings for resources.ToCSS on layouts. @mpilo-khathwane https://spandigital.atlassian.net/browse/PRSDM-6522

## 2024-11-07
### Bugfix
- Assign correct header to sub sections and articles. @julianbyte https://spandigital.atlassian.net/browse/PRSDM-6186
68 changes: 63 additions & 5 deletions layouts/partials/article/title.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,75 @@
{{ $articleLink := ($.Scratch.Get "articleLink") }}

{{ if (eq .Parent.Title .Title) }}
{{/* No title - For when the main title is the same as the first article */}}
{{/* No title - For when the main title is the same as the first article */}}
{{ else }}
<div class="article-title article-actions" data-align="center-left">
{{ if .Data.Pages }}
<h1> {{ .Title }}</h1>

{{/* Calculate depth by counting parents, ignoring the global site title (`$.Site.Title`) to avoid an extra heading level */}}
{{ $depth := 0 }}
{{ $currentPage := . }}

{{ with $currentPage.Parent }}
{{ if ne .Title $.Site.Title }}
{{ $depth = add $depth 1 }}
{{ end }}

{{ with .Parent }}
{{ if ne .Title $.Site.Title }}
{{ $depth = add $depth 1 }}
{{ end }}

{{ with .Parent }}
{{ if ne .Title $.Site.Title }}
{{ $depth = add $depth 1 }}
{{ end }}

{{ with .Parent }}
{{ if ne .Title $.Site.Title }}
{{ $depth = add $depth 1 }}
{{ end }}

{{ with .Parent }}
{{ if ne .Title $.Site.Title }}
{{ $depth = add $depth 1 }}
{{ end }}

{{ with .Parent }}
{{ if ne .Title $.Site.Title }}
{{ $depth = add $depth 1 }}
{{ end }}

{{/* Add more nesting if your structure goes deeper */}}
{{ end }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}

{{/* Set heading level based on depth, capping at 6 */}}
{{ $headingLevel := add $depth 1 }}
{{ if gt $headingLevel 6 }}
{{ $headingLevel = 6 }}
{{ end }}

{{/* Output the heading tag based on calculated level */}}
{{ if eq $headingLevel 1 }}
<h1>{{ .Title }}</h1>
{{ else if eq $headingLevel 2 }}
<h2>{{ .Title }}</h2>
{{ else if eq $headingLevel 3 }}
<h3>{{ .Title }}</h3>
{{ else if eq $headingLevel 4 }}
<h4>{{ .Title }}</h4>
{{ else if eq $headingLevel 5 }}
<h5>{{ .Title }}</h5>
{{ else }}
<h2> {{ .Title }}</h2>
<h6>{{ .Title }}</h6>
{{ end }}

<div class="permalink">
<a id="{{.Page.RelPermalink}}" data-slug="#{{ $slug }}"></a>
<a style="cursor:pointer;" onclick="copyPermalink( {{ $articleLink }} )" id="{{.Page.RelPermalink}}" data-slug="#{{ $slug }}" class="link-icon" title="Permalink to this article"></a>
</div>
</div>
{{ end }}

0 comments on commit 8c9575c

Please sign in to comment.