mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-18 21:11:19 +02:00
committed by
Bjørn Erik Pedersen
parent
44bf76d0f2
commit
cf978c0649
@@ -190,33 +190,41 @@ func (p *Page) Param(key interface{}) (interface{}, error) {
|
||||
return p.Site.Params[keyStr], nil
|
||||
}
|
||||
|
||||
// Author returns the first listed author for a page
|
||||
func (p *Page) Author() Author {
|
||||
authors := p.Authors()
|
||||
|
||||
for _, author := range authors {
|
||||
return author
|
||||
if len(authors) == 0 {
|
||||
return Author{}
|
||||
}
|
||||
return Author{}
|
||||
return authors[0]
|
||||
}
|
||||
|
||||
func (p *Page) Authors() AuthorList {
|
||||
authorKeys, ok := p.Params["authors"]
|
||||
if !ok {
|
||||
return AuthorList{}
|
||||
}
|
||||
authors := authorKeys.([]string)
|
||||
if len(authors) < 1 || len(p.Site.Authors) < 1 {
|
||||
return AuthorList{}
|
||||
}
|
||||
|
||||
al := make(AuthorList)
|
||||
for _, author := range authors {
|
||||
a, ok := p.Site.Authors[author]
|
||||
if ok {
|
||||
al[author] = a
|
||||
// Authors returns all listed authors for a page in the order they
|
||||
// are defined in the front matter. It first checks for a single author
|
||||
// since that it the most common use case, then checks for multiple authors.
|
||||
func (p *Page) Authors() Authors {
|
||||
authorID, ok := p.Params["author"].(string)
|
||||
if ok {
|
||||
a := p.Site.Authors.Get(authorID)
|
||||
if a.ID == authorID {
|
||||
return Authors{a}
|
||||
}
|
||||
}
|
||||
return al
|
||||
|
||||
authorIDs, ok := p.Params["authors"].([]string)
|
||||
if !ok || len(authorIDs) == 0 || len(p.Site.Authors) == 0 {
|
||||
return Authors{}
|
||||
}
|
||||
|
||||
authors := make([]Author, 0, len(authorIDs))
|
||||
for _, authorID := range authorIDs {
|
||||
a := p.Site.Authors.Get(authorID)
|
||||
if a.ID == authorID {
|
||||
authors = append(authors, a)
|
||||
}
|
||||
}
|
||||
|
||||
return authors
|
||||
}
|
||||
|
||||
func (p *Page) UniqueID() string {
|
||||
|
Reference in New Issue
Block a user