resource: Add front matter metadata to Resource

This commit expands the Resource interface with 3 new methods:

* Name
* Title
* Params

All of these can be set in the Page front matter. `Name` will get its default value from the base filename, and is the value used in the ByPrefix and GetByPrefix lookup methods.

Fixes #4244
This commit is contained in:
Bjørn Erik Pedersen 2018-01-15 20:40:39 +01:00
parent f8a119b606
commit 20c9b6ec81
No known key found for this signature in database
GPG key ID: 330E6E2BD4859D8F
27 changed files with 627 additions and 187 deletions

View file

@ -143,13 +143,13 @@ PAG|{{ .Title }}|{{ $sect.InSection . }}
// > b,c,d where b and d have content files.
b := p.s.getPage(KindSection, "empty2", "b")
assert.NotNil(b)
assert.Equal("T40_-1", b.Title)
assert.Equal("T40_-1", b.title)
c := p.s.getPage(KindSection, "empty2", "b", "c")
assert.NotNil(c)
assert.Equal("Cs", c.Title)
assert.Equal("Cs", c.title)
d := p.s.getPage(KindSection, "empty2", "b", "c", "d")
assert.NotNil(d)
assert.Equal("T41_-1", d.Title)
assert.Equal("T41_-1", d.title)
assert.False(c.Eq(d))
assert.True(c.Eq(c))
@ -165,7 +165,7 @@ PAG|{{ .Title }}|{{ $sect.InSection . }}
}},
{"top", func(p *Page) {
assert.Equal("Tops", p.Title)
assert.Equal("Tops", p.title)
assert.Len(p.Pages, 2)
assert.Equal("mypage2.md", p.Pages[0].LogicalName())
assert.Equal("mypage3.md", p.Pages[1].LogicalName())
@ -178,16 +178,16 @@ PAG|{{ .Title }}|{{ $sect.InSection . }}
assert.True(active)
}},
{"l1", func(p *Page) {
assert.Equal("L1s", p.Title)
assert.Equal("L1s", p.title)
assert.Len(p.Pages, 2)
assert.True(p.Parent().IsHome())
assert.Len(p.Sections(), 2)
}},
{"l1,l2", func(p *Page) {
assert.Equal("T2_-1", p.Title)
assert.Equal("T2_-1", p.title)
assert.Len(p.Pages, 3)
assert.Equal(p, p.Pages[0].Parent())
assert.Equal("L1s", p.Parent().Title)
assert.Equal("L1s", p.Parent().title)
assert.Equal("/l1/l2/", p.URLPath.URL)
assert.Equal("/l1/l2/", p.RelPermalink())
assert.Len(p.Sections(), 1)
@ -223,16 +223,16 @@ PAG|{{ .Title }}|{{ $sect.InSection . }}
}},
{"l1,l2_2", func(p *Page) {
assert.Equal("T22_-1", p.Title)
assert.Equal("T22_-1", p.title)
assert.Len(p.Pages, 2)
assert.Equal(filepath.FromSlash("l1/l2_2/page_2_2_1.md"), p.Pages[0].Path())
assert.Equal("L1s", p.Parent().Title)
assert.Equal("L1s", p.Parent().title)
assert.Len(p.Sections(), 0)
}},
{"l1,l2,l3", func(p *Page) {
assert.Equal("T3_-1", p.Title)
assert.Equal("T3_-1", p.title)
assert.Len(p.Pages, 2)
assert.Equal("T2_-1", p.Parent().Title)
assert.Equal("T2_-1", p.Parent().title)
assert.Len(p.Sections(), 0)
l1 := p.s.getPage(KindSection, "l1")
@ -252,7 +252,7 @@ PAG|{{ .Title }}|{{ $sect.InSection . }}
}},
{"perm a,link", func(p *Page) {
assert.Equal("T9_-1", p.Title)
assert.Equal("T9_-1", p.title)
assert.Equal("/perm-a/link/", p.RelPermalink())
assert.Len(p.Pages, 4)
first := p.Pages[0]