Workaround Hugo bug where it gets confused about directory parentage. (#5164)

Hugo produces confused results when directories are named as subsets of other
directory names (announcing-1.3 vs. announcing-1.3.1). Instead of using Hugo's
.Parent variable, we compute parentage manually using path names.
This commit is contained in:
Martin Taillefer 2019-10-16 08:13:29 -07:00 committed by GitHub
parent 37b0fd749c
commit b77085ccad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 10 deletions

View File

@ -21,18 +21,21 @@
{{ end }} {{ end }}
{{ $parent := .Page }} {{ $parent := .Page }}
{{ $parentDir := (path.Dir .Page.File.Dir) }}
{{ if $parent.Params.simple_list }} {{ if $parent.Params.simple_list }}
<ul> <ul>
{{ range $pages }} {{ range $pages }}
{{ if eq .Parent $parent }} {{ $pageLocation := (path.Dir (path.Dir .File.Dir)) }}
{{ if eq $parentDir $pageLocation }}
<li><a href="{{ .Permalink }}">{{- .Title -}}</a></li> <li><a href="{{ .Permalink }}">{{- .Title -}}</a></li>
{{ end }} {{ end }}
{{ end }} {{ end }}
</ul> </ul>
{{ else }} {{ else }}
{{ range $pages }} {{ range $pages }}
{{ if eq .Parent $parent }} {{ $pageLocation := (path.Dir (path.Dir .File.Dir)) }}
{{ if eq $parentDir $pageLocation }}
<div class="entry"> <div class="entry">
<h5> <h5>
<a href="{{ .Permalink }}"> <a href="{{ .Permalink }}">

View File

@ -1,11 +1,16 @@
{{ $url := replace .Permalink ( printf "%s" .Site.BaseURL) "" }} {{ $url := replace .Permalink ( printf "%s" .Site.BaseURL) "" }}
{{ $page := .Page }} {{ $page := .Page }}
{{ range $index, $element := split $url "/" }} {{ range $index := split $url "/" }}
{{ if $page }} {{ if $page }}
{{ $.Scratch.Add "urls" (slice $page.Permalink) }} {{ $.Scratch.Add "urls" (slice $page.Permalink) }}
{{ $.Scratch.Add "titles" (slice $page.LinkTitle) }} {{ $.Scratch.Add "titles" (slice $page.LinkTitle) }}
{{ $.Scratch.Add "descriptions" (slice $page.Description) }} {{ $.Scratch.Add "descriptions" (slice $page.Description) }}
{{ $page = $page.Parent }}
{{ $old := $page }}
{{ $page = $page.GetPage (path.Dir (path.Dir $page.File.Path)) }}
{{ if eq $old $page }}
{{ $page = $page.Site.GetPage "home" }}
{{ end }}
{{ end }} {{ end }}
{{ end }} {{ end }}

View File

@ -11,18 +11,22 @@
{{ $pages = sort $pages ".Params.weight" "asc" }} {{ $pages = sort $pages ".Params.weight" "asc" }}
{{ end }} {{ end }}
{{ $parentDir := (path.Dir $parent.File.Dir) }}
{{ $leafSection := true }} {{ $leafSection := true }}
{{ range $pages }} {{ range $pages }}
{{ if eq .Parent $parent }} {{ $pageLocation := (path.Dir (path.Dir .File.Dir)) }}
{{ if not .IsPage }} {{ if eq $parentDir $pageLocation }}
{{ $leafSection = false }} {{ if not .IsPage }}
{{ end }} {{ $leafSection = false }}
{{ end }}
{{ end }} {{ end }}
{{ end }} {{ end }}
<ul role="{{ if $top }}tree{{ else }}group{{ end }}" aria-expanded="{{ if $collapse }}false{{ else }}true{{ end }}"{{ if $leafSection }} class="leaf-section"{{ end }} {{ if $labelledby}}aria-labelledby="{{ $labelledby }}"{{ end }}> <ul role="{{ if $top }}tree{{ else }}group{{ end }}" aria-expanded="{{ if $collapse }}false{{ else }}true{{ end }}"{{ if $leafSection }} class="leaf-section"{{ end }} {{ if $labelledby}}aria-labelledby="{{ $labelledby }}"{{ end }}>
{{ range $pages }} {{ range $pages }}
{{ if eq .Parent $parent }} {{ $pageLocation := (path.Dir (path.Dir .File.Dir)) }}
{{ if eq $parentDir $pageLocation }}
{{ if not .IsPage }} {{ if not .IsPage }}
<li role="treeitem" aria-label="{{ .LinkTitle}}"> <li role="treeitem" aria-label="{{ .LinkTitle}}">
{{ $collapse := not (.IsAncestor $current) }} {{ $collapse := not (.IsAncestor $current) }}

View File

@ -72,7 +72,7 @@
{{ range $page := .Site.Pages }} {{ range $page := .Site.Pages }}
{{ $release := $page.Params.release }} {{ $release := $page.Params.release }}
{{ if eq $release $base_version }} {{ if eq $release $base_version }}
{{ $path := printf "/%supgrade-notes" $page.Dir }} {{ $path := printf "/%supgrade-notes" $page.File.Dir }}
{{ $upgrade_notes = .Page.GetPage $path }} {{ $upgrade_notes = .Page.GetPage $path }}
{{ end }} {{ end }}
{{ end }} {{ end }}