mirror of
				https://github.com/gohugoio/hugo.git
				synced 2024-05-11 05:54:58 +00:00 
			
		
		
		
	Fix IsAncestor and IsDescendant when the same page is passed
This commit is contained in:
		
				
					committed by
					
						
						Bjørn Erik Pedersen
					
				
			
			
				
	
			
			
			
						parent
						
							5c41f41ad4
						
					
				
				
					commit
					8d5766d417
				
			@@ -395,8 +395,8 @@ Blog Section: {{ template "print-page" $blog }}
 | 
			
		||||
Blog Sub Section: {{ template "print-page" $blogSub }}
 | 
			
		||||
Page: {{ template "print-page" $page }}
 | 
			
		||||
Bundle: {{ template "print-page" $bundle }}
 | 
			
		||||
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 }}
 | 
			
		||||
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 }}
 | 
			
		||||
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 }}
 | 
			
		||||
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 }}
 | 
			
		||||
IsDescendant overlap1: false: {{ $overlap1.IsDescendant $overlap2 }}
 | 
			
		||||
IsDescendant overlap2: false: {{ $overlap2.IsDescendant $overlap1 }}
 | 
			
		||||
IsAncestor overlap1: false: {{ $overlap1.IsAncestor $overlap2 }}
 | 
			
		||||
@@ -438,8 +438,8 @@ Draft5: {{ if (.Site.GetPage "blog/draftsection/sub/page") }}FOUND{{ end }}|
 | 
			
		||||
        Blog Sub Section: Page 3|/blog/subsection/|2019-06-03|Current Section: blog/subsection|Resources: json: /blog/subsection/subdata.json|
 | 
			
		||||
        Page: Page 1|/blog/page1/|2019-06-01|Current Section: blog|Resources: 
 | 
			
		||||
        Bundle: Page 12|/blog/bundle/|0001-01-01|Current Section: blog|Resources: json: /blog/bundle/data.json|page: |
 | 
			
		||||
        IsDescendant: true: true true: true true: true true: true true: true false: false
 | 
			
		||||
        IsAncestor: true: true true: true true: true true: true true: true true: true false: false false: false  false: false
 | 
			
		||||
        IsDescendant: true: true true: true true: true true: true true: true true: true false: false
 | 
			
		||||
        IsAncestor: true: true true: true true: true true: true true: true true: true true: true false: false false: false  false: false
 | 
			
		||||
        IsDescendant overlap1: false: false
 | 
			
		||||
        IsDescendant overlap2: false: false
 | 
			
		||||
        IsAncestor overlap1: false: false
 | 
			
		||||
 
 | 
			
		||||
@@ -54,6 +54,10 @@ func (pt pageTree) IsAncestor(other interface{}) (bool, error) {
 | 
			
		||||
		return false, nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if ref1.key == ref2.key {
 | 
			
		||||
		return true, nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if strings.HasPrefix(ref2.key, ref1.key+"/") {
 | 
			
		||||
		return true, nil
 | 
			
		||||
	}
 | 
			
		||||
@@ -101,6 +105,10 @@ func (pt pageTree) IsDescendant(other interface{}) (bool, error) {
 | 
			
		||||
		return false, nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if ref1.key == ref2.key {
 | 
			
		||||
		return true, nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if strings.HasPrefix(ref1.key, ref2.key+"/") {
 | 
			
		||||
		return true, nil
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user