summaryrefslogtreecommitdiffstats
path: root/hugolib
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-05-23 15:04:00 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-05-24 12:35:45 +0200
commit4d7fa9f114c62ae2ec12257203ed21b0e4d69a04 (patch)
tree2224fdd22410c147863c6dd902a7e981624369e8 /hugolib
parenta985efcecf44afe1d252690ec0a00cf077974f44 (diff)
Fix IsAncestor/IsDescendant for taxonomies
Fixes #7305
Diffstat (limited to 'hugolib')
-rw-r--r--hugolib/page__tree.go8
-rw-r--r--hugolib/taxonomy_test.go52
2 files changed, 52 insertions, 8 deletions
diff --git a/hugolib/page__tree.go b/hugolib/page__tree.go
index 5b53dc4cd..d2ef00e76 100644
--- a/hugolib/page__tree.go
+++ b/hugolib/page__tree.go
@@ -50,10 +50,6 @@ func (pt pageTree) IsAncestor(other interface{}) (bool, error) {
return ref1.n.p.IsHome(), nil
}
- if !ref1.isSection() {
- return false, nil
- }
-
if ref1.key == ref2.key {
return true, nil
}
@@ -101,10 +97,6 @@ func (pt pageTree) IsDescendant(other interface{}) (bool, error) {
return ref2.n.p.IsHome(), nil
}
- if !ref2.isSection() {
- return false, nil
- }
-
if ref1.key == ref2.key {
return true, nil
}
diff --git a/hugolib/taxonomy_test.go b/hugolib/taxonomy_test.go
index 1f43318fa..97058dd19 100644
--- a/hugolib/taxonomy_test.go
+++ b/hugolib/taxonomy_test.go
@@ -655,3 +655,55 @@ Category Paginator /categories/birds/|/categories/cats/|/categories/dogs/|/categ
b.AssertFileContent("public/categories/index.xml", `<link>http://example.com/categories/funny/</link>`)
}
+
+func TestTaxonomiesDirectoryOverlaps(t *testing.T) {
+ t.Parallel()
+
+ b := newTestSitesBuilder(t).WithContent(
+ "abc/_index.md", "---\ntitle: \"abc\"\nabcdefgs: [abc]\n---",
+ "abc/p1.md", "---\ntitle: \"abc-p\"\n---",
+ "abcdefgh/_index.md", "---\ntitle: \"abcdefgh\"\n---",
+ "abcdefgh/p1.md", "---\ntitle: \"abcdefgh-p\"\n---",
+ "abcdefghijk/index.md", "---\ntitle: \"abcdefghijk\"\n---",
+ )
+
+ b.WithConfigFile("toml", `
+baseURL = "https://example.org"
+
+[taxonomies]
+ abcdef = "abcdefs"
+ abcdefg = "abcdefgs"
+ abcdefghi = "abcdefghis"
+`)
+
+ b.WithTemplatesAdded("index.html", `
+{{ range site.Pages }}Page: {{ template "print-page" . }}
+{{ end }}
+{{ $abc := site.GetPage "abcdefgs/abc" }}
+{{ $abcdefgs := site.GetPage "abcdefgs" }}
+abc: {{ template "print-page" $abc }}|IsAncestor: {{ $abc.IsAncestor $abcdefgs }}|IsDescendant: {{ $abc.IsDescendant $abcdefgs }}
+abcdefgs: {{ template "print-page" $abcdefgs }}|IsAncestor: {{ $abcdefgs.IsAncestor $abc }}|IsDescendant: {{ $abcdefgs.IsDescendant $abc }}
+
+{{ define "print-page" }}{{ .RelPermalink }}|{{ .Title }}|{{.Kind }}|Parent: {{ with .Parent }}{{ .RelPermalink }}{{ end }}|CurrentSection: {{ .CurrentSection.RelPermalink}}|FirstSection: {{ .FirstSection.RelPermalink }}{{ end }}
+
+`)
+
+ b.Build(BuildCfg{})
+
+ b.AssertFileContent("public/index.html", `
+ Page: /||home|Parent: |CurrentSection: /|
+ Page: /abc/|abc|section|Parent: /|CurrentSection: /abc/|
+ Page: /abc/p1/|abc-p|page|Parent: /abc/|CurrentSection: /abc/|
+ Page: /abcdefgh/|abcdefgh|section|Parent: /|CurrentSection: /abcdefgh/|
+ Page: /abcdefgh/p1/|abcdefgh-p|page|Parent: /abcdefgh/|CurrentSection: /abcdefgh/|
+ Page: /abcdefghijk/|abcdefghijk|page|Parent: /|CurrentSection: /|
+ Page: /abcdefghis/|Abcdefghis|taxonomyTerm|Parent: /|CurrentSection: /|
+ Page: /abcdefgs/|Abcdefgs|taxonomyTerm|Parent: /|CurrentSection: /|
+ Page: /abcdefs/|Abcdefs|taxonomyTerm|Parent: /|CurrentSection: /|
+ abc: /abcdefgs/abc/|abc|taxonomy|Parent: /abcdefgs/|CurrentSection: /abcdefgs/|
+ abcdefgs: /abcdefgs/|Abcdefgs|taxonomyTerm|Parent: /|CurrentSection: /|
+ abc: /abcdefgs/abc/|abc|taxonomy|Parent: /abcdefgs/|CurrentSection: /abcdefgs/|FirstSection: /|IsAncestor: false|IsDescendant: true
+ abcdefgs: /abcdefgs/|Abcdefgs|taxonomyTerm|Parent: /|CurrentSection: /|FirstSection: /|IsAncestor: true|IsDescendant: false
+`)
+
+}