mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-16 20:53:59 +02:00
Simplify .Site.GetPage etc.
This commit is a follow up to a recent overhaul of the GetPage/ref/relref implemenation. The most important change in this commit is the update to `.Site.GetPage`: * To reduce the amount of breakage in the wild to its minimum, I have reworked .Site.GetPage with some rules: * We cannot support more than 2 arguments, i.e. .Site.GetPage "page" "posts" "mypage.md" will now throw an error. I think this is the most uncommon syntax and should be OK. It is an easy fix to change the above to .Site.GetPage "/posts/mypage.md" or similar. * .Site.GetPage "home", .Site.GetPage "home" "" and .Site.GetPage "home" "/" will give you the home page. This means that if you have page in root with the name home.md you need to do .Site.GetPage "/home.md" or similar This commit also fixes some multilingual issues, most notable it is now possible to do cross-language ref/relref lookups by prepending the language code to the path, e.g. `/jp/posts/mypage.md`. This commit also reverts the site building tests related to this to "Hugo 0.44 state", to get better control of the changes made. Closes #4147 Closes #4727 Closes #4728 Closes #4728 Closes #4726 Closes #4652
This commit is contained in:
@@ -104,7 +104,7 @@ Content
|
||||
writeSource(t, fs, filepath.Join("layouts", "_default", "single.html"), "<html>Single|{{ .Title }}</html>")
|
||||
writeSource(t, fs, filepath.Join("layouts", "_default", "list.html"),
|
||||
`
|
||||
{{ $sect := (.Site.GetPage "section" "l1" "l2") }}
|
||||
{{ $sect := (.Site.GetPage "l1/l2") }}
|
||||
<html>List|{{ .Title }}|L1/l2-IsActive: {{ .InSection $sect }}
|
||||
{{ range .Paginator.Pages }}
|
||||
PAG|{{ .Title }}|{{ $sect.InSection . }}
|
||||
@@ -135,19 +135,19 @@ PAG|{{ .Title }}|{{ $sect.InSection . }}
|
||||
}},
|
||||
{"empty1", func(p *Page) {
|
||||
// > b,c
|
||||
assert.NotNil(p.s.getPage(nil, "empty1/b"))
|
||||
assert.NotNil(p.s.getPage(nil, "empty1/b/c"))
|
||||
assert.NotNil(p.s.getPage(KindSection, "empty1", "b"))
|
||||
assert.NotNil(p.s.getPage(KindSection, "empty1", "b", "c"))
|
||||
|
||||
}},
|
||||
{"empty2", func(p *Page) {
|
||||
// > b,c,d where b and d have content files.
|
||||
b, _ := p.s.getPage(nil, "empty2/b")
|
||||
b := p.s.getPage(KindSection, "empty2", "b")
|
||||
assert.NotNil(b)
|
||||
assert.Equal("T40_-1", b.title)
|
||||
c, _ := p.s.getPage(nil, "empty2/b/c")
|
||||
c := p.s.getPage(KindSection, "empty2", "b", "c")
|
||||
assert.NotNil(c)
|
||||
assert.Equal("Cs", c.title)
|
||||
d, _ := p.s.getPage(nil, "empty2/b/c/d")
|
||||
d := p.s.getPage(KindSection, "empty2", "b", "c", "d")
|
||||
assert.NotNil(d)
|
||||
assert.Equal("T41_-1", d.title)
|
||||
|
||||
@@ -156,9 +156,9 @@ PAG|{{ .Title }}|{{ $sect.InSection . }}
|
||||
assert.False(c.Eq("asdf"))
|
||||
|
||||
}},
|
||||
{"/empty3", func(p *Page) {
|
||||
{"empty3", func(p *Page) {
|
||||
// b,c,d with regular page in b
|
||||
b, _ := p.s.getPage(nil, "/empty3/b")
|
||||
b := p.s.getPage(KindSection, "empty3", "b")
|
||||
assert.NotNil(b)
|
||||
assert.Len(b.Pages, 1)
|
||||
assert.Equal("empty3.md", b.Pages[0].File.LogicalName())
|
||||
@@ -200,8 +200,7 @@ PAG|{{ .Title }}|{{ $sect.InSection . }}
|
||||
active, err = p.InSection(child)
|
||||
assert.NoError(err)
|
||||
assert.True(active)
|
||||
homePage, _ := p.s.getPage(nil, "/")
|
||||
active, err = p.InSection(homePage)
|
||||
active, err = p.InSection(p.s.getPage(KindHome))
|
||||
assert.NoError(err)
|
||||
assert.False(active)
|
||||
|
||||
@@ -236,7 +235,7 @@ PAG|{{ .Title }}|{{ $sect.InSection . }}
|
||||
assert.Equal("T2_-1", p.Parent().title)
|
||||
assert.Len(p.Sections(), 0)
|
||||
|
||||
l1, _ := p.s.getPage(nil, "l1")
|
||||
l1 := p.s.getPage(KindSection, "l1")
|
||||
isDescendant, err := l1.IsDescendant(p)
|
||||
assert.NoError(err)
|
||||
assert.False(isDescendant)
|
||||
@@ -266,18 +265,16 @@ PAG|{{ .Title }}|{{ $sect.InSection . }}
|
||||
}},
|
||||
}
|
||||
|
||||
home, _ := s.getPage(nil, "/")
|
||||
home := s.getPage(KindHome)
|
||||
|
||||
for _, test := range tests {
|
||||
sections := strings.Split(test.sections, ",")
|
||||
p, _ := s.Info.GetPage(KindSection, sections...)
|
||||
p := s.getPage(KindSection, sections...)
|
||||
assert.NotNil(p, fmt.Sprint(sections))
|
||||
|
||||
if p.Pages != nil {
|
||||
assert.Equal(p.Pages, p.data["Pages"])
|
||||
}
|
||||
|
||||
fmt.Println(p, test.sections)
|
||||
assert.NotNil(p.Parent(), fmt.Sprintf("Parent nil: %q", test.sections))
|
||||
test.verify(p)
|
||||
}
|
||||
@@ -287,7 +284,7 @@ PAG|{{ .Title }}|{{ $sect.InSection . }}
|
||||
assert.Len(home.Sections(), 9)
|
||||
assert.Equal(home.Sections(), s.Info.Sections())
|
||||
|
||||
rootPage, _ := s.getPage(nil, "mypage.md")
|
||||
rootPage := s.getPage(KindPage, "mypage.md")
|
||||
assert.NotNil(rootPage)
|
||||
assert.True(rootPage.Parent().IsHome())
|
||||
|
||||
@@ -297,7 +294,7 @@ PAG|{{ .Title }}|{{ $sect.InSection . }}
|
||||
// If we later decide to do something about this, we will have to do some normalization in
|
||||
// getPage.
|
||||
// TODO(bep)
|
||||
sectionWithSpace, _ := s.getPage(nil, "Spaces in Section")
|
||||
sectionWithSpace := s.getPage(KindSection, "Spaces in Section")
|
||||
require.NotNil(t, sectionWithSpace)
|
||||
require.Equal(t, "/spaces-in-section/", sectionWithSpace.RelPermalink())
|
||||
|
||||
|
Reference in New Issue
Block a user