Skip to content

Commit 8d5766d

Browse files
tekezobep
authored andcommitted
Fix IsAncestor and IsDescendant when the same page is passed
1 parent 5c41f41 commit 8d5766d

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

hugolib/content_map_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,8 @@ Blog Section: {{ template "print-page" $blog }}
395395
Blog Sub Section: {{ template "print-page" $blogSub }}
396396
Page: {{ template "print-page" $page }}
397397
Bundle: {{ template "print-page" $bundle }}
398-
IsDescendant: true: {{ $page.IsDescendant $blog }} true: {{ $blogSub.IsDescendant $blog }} true: {{ $bundle.IsDescendant $blog }} true: {{ $page4.IsDescendant $blog }} true: {{ $blog.IsDescendant $home }} false: {{ $home.IsDescendant $blog }}
399-
IsAncestor: true: {{ $blog.IsAncestor $page }} true: {{ $home.IsAncestor $blog }} true: {{ $blog.IsAncestor $blogSub }} true: {{ $blog.IsAncestor $bundle }} true: {{ $blog.IsAncestor $page4 }} true: {{ $home.IsAncestor $page }} false: {{ $page.IsAncestor $blog }} false: {{ $blog.IsAncestor $home }} false: {{ $blogSub.IsAncestor $blog }}
398+
IsDescendant: true: {{ $page.IsDescendant $blog }} true: {{ $blogSub.IsDescendant $blog }} true: {{ $bundle.IsDescendant $blog }} true: {{ $page4.IsDescendant $blog }} true: {{ $blog.IsDescendant $home }} true: {{ $blog.IsDescendant $blog }} false: {{ $home.IsDescendant $blog }}
399+
IsAncestor: true: {{ $blog.IsAncestor $page }} true: {{ $home.IsAncestor $blog }} true: {{ $blog.IsAncestor $blogSub }} true: {{ $blog.IsAncestor $bundle }} true: {{ $blog.IsAncestor $page4 }} true: {{ $home.IsAncestor $page }} true: {{ $blog.IsAncestor $blog }} false: {{ $page.IsAncestor $blog }} false: {{ $blog.IsAncestor $home }} false: {{ $blogSub.IsAncestor $blog }}
400400
IsDescendant overlap1: false: {{ $overlap1.IsDescendant $overlap2 }}
401401
IsDescendant overlap2: false: {{ $overlap2.IsDescendant $overlap1 }}
402402
IsAncestor overlap1: false: {{ $overlap1.IsAncestor $overlap2 }}
@@ -438,8 +438,8 @@ Draft5: {{ if (.Site.GetPage "blog/draftsection/sub/page") }}FOUND{{ end }}|
438438
Blog Sub Section: Page 3|/blog/subsection/|2019-06-03|Current Section: blog/subsection|Resources: json: /blog/subsection/subdata.json|
439439
Page: Page 1|/blog/page1/|2019-06-01|Current Section: blog|Resources:
440440
Bundle: Page 12|/blog/bundle/|0001-01-01|Current Section: blog|Resources: json: /blog/bundle/data.json|page: |
441-
IsDescendant: true: true true: true true: true true: true true: true false: false
442-
IsAncestor: true: true true: true true: true true: true true: true true: true false: false false: false false: false
441+
IsDescendant: true: true true: true true: true true: true true: true true: true false: false
442+
IsAncestor: true: true true: true true: true true: true true: true true: true true: true false: false false: false false: false
443443
IsDescendant overlap1: false: false
444444
IsDescendant overlap2: false: false
445445
IsAncestor overlap1: false: false

hugolib/page__tree.go

+8
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ func (pt pageTree) IsAncestor(other interface{}) (bool, error) {
5454
return false, nil
5555
}
5656

57+
if ref1.key == ref2.key {
58+
return true, nil
59+
}
60+
5761
if strings.HasPrefix(ref2.key, ref1.key+"/") {
5862
return true, nil
5963
}
@@ -101,6 +105,10 @@ func (pt pageTree) IsDescendant(other interface{}) (bool, error) {
101105
return false, nil
102106
}
103107

108+
if ref1.key == ref2.key {
109+
return true, nil
110+
}
111+
104112
if strings.HasPrefix(ref1.key, ref2.key+"/") {
105113
return true, nil
106114
}

0 commit comments

Comments
 (0)