Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2016-09-18 20:10:11 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2016-09-18 20:16:39 +0300
commit4a79fa0c33f364cd753c022e0f741403985699b2 (patch)
tree1b0219c7dc48dac830e84ccda991ec5041ecdc1c /hugolib
parent83533a88810563f79a59043918e9c54ce65dcbe0 (diff)
Revert the "standardize author data"
There were some breaking changes etc. that is too late to fix for 0.17. Let us think this through and add proper author support for Hugo 0.18. Fixes #2464 Revert "docs: Add documentation for author profiles" This reverts commit b6673e5309685ae162fdef2dc39c3ce4385c6005. Revert "Add First Class Author Support" This reverts commit cf978c06496d99e76b08418422dda5797d90fed6.
Diffstat (limited to 'hugolib')
-rw-r--r--hugolib/author.go151
-rw-r--r--hugolib/node.go19
-rw-r--r--hugolib/page.go42
-rw-r--r--hugolib/site.go9
4 files changed, 36 insertions, 185 deletions
diff --git a/hugolib/author.go b/hugolib/author.go
index 9aa71b5df..0f4327097 100644
--- a/hugolib/author.go
+++ b/hugolib/author.go
@@ -13,51 +13,23 @@
package hugolib
-import (
- "fmt"
- "regexp"
- "sort"
- "strings"
-
- "github.com/spf13/cast"
-)
-
-var (
- onlyNumbersRegExp = regexp.MustCompile("^[0-9]*$")
-)
-
-// Authors is a list of all authors and their metadata.
-type Authors []Author
-
-// Get returns an author from an ID
-func (a Authors) Get(id string) Author {
- for _, author := range a {
- if author.ID == id {
- return author
- }
- }
- return Author{}
-}
+// AuthorList is a list of all authors and their metadata.
+type AuthorList map[string]Author
// Author contains details about the author of a page.
type Author struct {
- ID string
- GivenName string // givenName OR firstName
- FirstName string // alias for GivenName
- FamilyName string // familyName OR lastName
- LastName string // alias for FamilyName
- DisplayName string // displayName
- Thumbnail string // thumbnail
- Image string // image
- ShortBio string // shortBio
- Bio string // bio
- Email string // email
- Social AuthorSocial // social
- Params map[string]string // params
- Weight int
+ GivenName string
+ FamilyName string
+ DisplayName string
+ Thumbnail string
+ Image string
+ ShortBio string
+ LongBio string
+ Email string
+ Social AuthorSocial
}
-// AuthorSocial is a place to put social usernames per author. These are the
+// AuthorSocial is a place to put social details per author. These are the
// standard keys that themes will expect to have available, but can be
// expanded to any others on a per site basis
// - website
@@ -71,102 +43,3 @@ type Author struct {
// - linkedin
// - skype
type AuthorSocial map[string]string
-
-// URL is a convenience function that provides the correct canonical URL
-// for a specific social network given a username. If an unsupported network
-// is requested, only the username is returned
-func (as AuthorSocial) URL(key string) string {
- switch key {
- case "github":
- return fmt.Sprintf("https://github.com/%s", as[key])
- case "facebook":
- return fmt.Sprintf("https://www.facebook.com/%s", as[key])
- case "twitter":
- return fmt.Sprintf("https://twitter.com/%s", as[key])
- case "googleplus":
- isNumeric := onlyNumbersRegExp.Match([]byte(as[key]))
- if isNumeric {
- return fmt.Sprintf("https://plus.google.com/%s", as[key])
- }
- return fmt.Sprintf("https://plus.google.com/+%s", as[key])
- case "pinterest":
- return fmt.Sprintf("https://www.pinterest.com/%s/", as[key])
- case "instagram":
- return fmt.Sprintf("https://www.instagram.com/%s/", as[key])
- case "youtube":
- return fmt.Sprintf("https://www.youtube.com/user/%s", as[key])
- case "linkedin":
- return fmt.Sprintf("https://www.linkedin.com/in/%s", as[key])
- default:
- return as[key]
- }
-}
-
-func mapToAuthors(m map[string]interface{}) Authors {
- authors := make(Authors, len(m))
- for authorID, data := range m {
- authorMap, ok := data.(map[string]interface{})
- if !ok {
- continue
- }
- authors = append(authors, mapToAuthor(authorID, authorMap))
- }
- sort.Stable(authors)
- return authors
-}
-
-func mapToAuthor(id string, m map[string]interface{}) Author {
- author := Author{ID: id}
- for k, data := range m {
- switch k {
- case "givenName", "firstName":
- author.GivenName = cast.ToString(data)
- author.FirstName = author.GivenName
- case "familyName", "lastName":
- author.FamilyName = cast.ToString(data)
- author.LastName = author.FamilyName
- case "displayName":
- author.DisplayName = cast.ToString(data)
- case "thumbnail":
- author.Thumbnail = cast.ToString(data)
- case "image":
- author.Image = cast.ToString(data)
- case "shortBio":
- author.ShortBio = cast.ToString(data)
- case "bio":
- author.Bio = cast.ToString(data)
- case "email":
- author.Email = cast.ToString(data)
- case "social":
- author.Social = normalizeSocial(cast.ToStringMapString(data))
- case "params":
- author.Params = cast.ToStringMapString(data)
- }
- }
-
- // set a reasonable default for DisplayName
- if author.DisplayName == "" {
- author.DisplayName = author.GivenName + " " + author.FamilyName
- }
-
- return author
-}
-
-// normalizeSocial makes a naive attempt to normalize social media usernames
-// and strips out extraneous characters or url info
-func normalizeSocial(m map[string]string) map[string]string {
- for network, username := range m {
- username = strings.TrimSpace(username)
- username = strings.TrimSuffix(username, "/")
- strs := strings.Split(username, "/")
- username = strs[len(strs)-1]
- username = strings.TrimPrefix(username, "@")
- username = strings.TrimPrefix(username, "+")
- m[network] = username
- }
- return m
-}
-
-func (a Authors) Len() int { return len(a) }
-func (a Authors) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
-func (a Authors) Less(i, j int) bool { return a[i].Weight < a[j].Weight }
diff --git a/hugolib/node.go b/hugolib/node.go
index 820c483a6..566fd4799 100644
--- a/hugolib/node.go
+++ b/hugolib/node.go
@@ -21,9 +21,11 @@ import (
"sync"
"time"
- "github.com/spf13/cast"
- "github.com/spf13/hugo/helpers"
jww "github.com/spf13/jwalterweatherman"
+
+ "github.com/spf13/hugo/helpers"
+
+ "github.com/spf13/cast"
)
type Node struct {
@@ -320,16 +322,3 @@ func (n *Node) addLangFilepathPrefix(outfile string) string {
}
return helpers.FilePathSeparator + filepath.Join(n.Lang(), outfile)
}
-
-// Author returns the first defined author, sorted by Weight
-func (n *Node) Author() Author {
- if len(n.Site.Authors) == 0 {
- return Author{}
- }
- return n.Site.Authors[0]
-}
-
-// Authors returns all defined authors, sorted by Weight
-func (n *Node) Authors() Authors {
- return n.Site.Authors
-}
diff --git a/hugolib/page.go b/hugolib/page.go
index 1d826f51e..b72cfcfe9 100644
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -190,41 +190,33 @@ 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()
- if len(authors) == 0 {
- return Author{}
+
+ for _, author := range authors {
+ return author
}
- return authors[0]
+ return Author{}
}
-// 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}
- }
+func (p *Page) Authors() AuthorList {
+ authorKeys, ok := p.Params["authors"]
+ if !ok {
+ return AuthorList{}
}
-
- authorIDs, ok := p.Params["authors"].([]string)
- if !ok || len(authorIDs) == 0 || len(p.Site.Authors) == 0 {
- return Authors{}
+ authors := authorKeys.([]string)
+ if len(authors) < 1 || len(p.Site.Authors) < 1 {
+ return AuthorList{}
}
- authors := make([]Author, 0, len(authorIDs))
- for _, authorID := range authorIDs {
- a := p.Site.Authors.Get(authorID)
- if a.ID == authorID {
- authors = append(authors, a)
+ al := make(AuthorList)
+ for _, author := range authors {
+ a, ok := p.Site.Authors[author]
+ if ok {
+ al[author] = a
}
}
-
- return authors
+ return al
}
func (p *Page) UniqueID() string {
diff --git a/hugolib/site.go b/hugolib/site.go
index f7872ba99..87c440d38 100644
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -165,7 +165,7 @@ type SiteInfo struct {
BaseURL template.URL
Taxonomies TaxonomyList
- Authors Authors
+ Authors AuthorList
Social SiteSocial
Sections Taxonomy
Pages *Pages // Includes only pages in this language
@@ -176,6 +176,7 @@ type SiteInfo struct {
Hugo *HugoInfo
Title string
RSSLink string
+ Author map[string]interface{}
LanguageCode string
DisqusShortname string
GoogleAnalytics string
@@ -732,11 +733,6 @@ func (s *Site) readDataFromSourceFS() error {
}
err = s.loadData(dataSources)
-
- // extract author data from /data/_authors then delete it from .Data
- s.Info.Authors = mapToAuthors(cast.ToStringMap(s.Data["_authors"]))
- delete(s.Data, "_authors")
-
s.timerStep("load data")
return err
}
@@ -912,6 +908,7 @@ func (s *Site) initializeSiteInfo() {
s.Info = SiteInfo{
BaseURL: template.URL(helpers.SanitizeURLKeepTrailingSlash(viper.GetString("BaseURL"))),
Title: lang.GetString("Title"),
+ Author: lang.GetStringMap("author"),
Social: lang.GetStringMapString("social"),
LanguageCode: lang.GetString("languagecode"),
Copyright: lang.GetString("copyright"),