shithub: hugo

Download patch

ref: e007c9b25d076f5705afb63fda4f3abd3d05b7b8
parent: 5759007874afc1948f0fab0a97f2184bff686b54
author: bep <[email protected]>
date: Sat Mar 7 07:53:20 EST 2015

hugolib: apply some more Golint rules

--- a/hugolib/media.go
+++ b/hugolib/media.go
@@ -13,7 +13,7 @@
 
 package hugolib
 
-// An image contains metadata for images + image sitemaps
+// An Image contains metadata for images + image sitemaps
 // https://support.google.com/webmasters/answer/178636?hl=en
 type Image struct {
 
@@ -37,7 +37,7 @@
 	License string
 }
 
-// An video contains metadata for videos + video sitemaps
+// A Video contains metadata for videos + video sitemaps
 // https://support.google.com/webmasters/answer/80471?hl=en
 type Video struct {
 	ThumbnailLoc         string
--- a/hugolib/pageSort.go
+++ b/hugolib/pageSort.go
@@ -21,13 +21,13 @@
  * Implementation of a custom sorter for Pages
  */
 
-// A type to implement the sort interface for Pages
+// A PageSorter implements the sort interface for Pages
 type PageSorter struct {
 	pages Pages
 	by    PageBy
 }
 
-// Closure used in the Sort.Less method.
+// PageBy is a closure used in the Sort.Less method.
 type PageBy func(p1, p2 *Page) bool
 
 func (by PageBy) Sort(pages Pages) {
@@ -41,9 +41,8 @@
 var DefaultPageSort = func(p1, p2 *Page) bool {
 	if p1.Weight == p2.Weight {
 		return p1.Date.Unix() > p2.Date.Unix()
-	} else {
-		return p1.Weight < p2.Weight
 	}
+	return p1.Weight < p2.Weight
 }
 
 func (ps *PageSorter) Len() int      { return len(ps.pages) }
@@ -59,9 +58,8 @@
 func (p Pages) Limit(n int) Pages {
 	if len(p) < n {
 		return p[0:n]
-	} else {
-		return p
 	}
+	return p
 }
 
 func (p Pages) ByWeight() Pages {
--- a/hugolib/pagination.go
+++ b/hugolib/pagination.go
@@ -131,7 +131,7 @@
 	return split
 }
 
-// Paginate gets this Node's paginator if it's already created.
+// Paginator gets this Node's paginator if it's already created.
 // If it's not, one will be created with all pages in Data["Pages"].
 func (n *Node) Paginator() (*pager, error) {
 
@@ -163,9 +163,12 @@
 	return n.paginator, nil
 }
 
+// Paginator on Page isn't supported, calling this yields an error.
 func (p *Page) Paginator() (*pager, error) {
 	return nil, errors.New("Paginators not supported for content pages.")
 }
+
+// Paginate on Page isn't supported, calling this yields an error.
 func (p *Page) Paginate(seq interface{}) (*pager, error) {
 	return nil, errors.New("Paginators not supported for content pages.")
 }
--- a/hugolib/shortcode.go
+++ b/hugolib/shortcode.go
@@ -125,7 +125,7 @@
 	return fmt.Sprintf("%s(%q, %t){%s}", sc.name, params, sc.doMarkup, sc.inner)
 }
 
-// all in  one go: extract, render and replace
+// ShortcodesHandle does all in  one go: extract, render and replace
 // only used for testing
 func ShortcodesHandle(stringToParse string, page *Page, t tpl.Template) string {
 	tmpContent, tmpShortcodes := extractAndRenderShortcodes(stringToParse, page, t)
@@ -467,9 +467,8 @@
 
 		if val, ok := replacements[key]; ok {
 			return []byte(val)
-		} else {
-			panic(fmt.Errorf("unknown shortcode token %q", key))
 		}
+		panic(fmt.Errorf("unknown shortcode token %q", key))
 	})
 
 	return b, err
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -167,8 +167,8 @@
 		return "", err
 	}
 
-	var target *Page = nil
-	var link string = ""
+	var target *Page
+	var link string
 
 	if refUrl.Path != "" {
 		for _, page := range []*Page(*s.Pages) {
@@ -179,7 +179,7 @@
 		}
 
 		if target == nil {
-			return "", errors.New(fmt.Sprintf("No page found with path or logical name \"%s\".\n", refUrl.Path))
+			return "", fmt.Errorf("No page found with path or logical name \"%s\".\n", refUrl.Path)
 		}
 
 		if relative {
@@ -649,11 +649,11 @@
 			}
 
 			if r.page.IsDraft() {
-				s.draftCount += 1
+				s.draftCount++
 			}
 
 			if r.page.IsFuture() {
-				s.futureCount += 1
+				s.futureCount++
 			}
 		}
 	}
@@ -851,7 +851,7 @@
 	return
 }
 
-// Render shell pages that simply have a redirect in the header
+// RenderAliases renders shell pages that simply have a redirect in the header
 func (s *Site) RenderAliases() error {
 	for _, p := range s.Pages {
 		for _, a := range p.Aliases {
@@ -867,7 +867,7 @@
 	return nil
 }
 
-// Render pages each corresponding to a markdown file
+// RenderPages renders pages each corresponding to a markdown file
 func (s *Site) RenderPages() error {
 
 	results := make(chan error)
@@ -967,9 +967,8 @@
 			}
 		}
 		return out
-	} else {
-		return in
 	}
+	return in
 }
 
 type taxRenderInfo struct {
@@ -979,7 +978,7 @@
 	plural   string
 }
 
-// Render the listing pages based on the meta data
+// RenderTaxonomiesLists renders the listing pages based on the meta data
 // each unique term within a taxonomy will have a page created
 func (s *Site) RenderTaxonomiesLists() error {
 	wg := &sync.WaitGroup{}
@@ -1093,7 +1092,7 @@
 	}
 }
 
-// Render a page per taxonomy that lists the terms for that taxonomy
+// RenderListsOfTaxonomyTerms renders a page per taxonomy that lists the terms for that taxonomy
 func (s *Site) RenderListsOfTaxonomyTerms() (err error) {
 	taxonomies := viper.GetStringMapString("Taxonomies")
 	for singular, plural := range taxonomies {
@@ -1132,7 +1131,7 @@
 	return n
 }
 
-// Render a page for each section
+// RenderSectionLists renders a page for each section
 func (s *Site) RenderSectionLists() error {
 	for section, data := range s.Sections {
 
--- a/hugolib/taxonomy.go
+++ b/hugolib/taxonomy.go
@@ -184,18 +184,18 @@
 	return nil
 }
 
-func (p WeightedPages) Len() int      { return len(p) }
-func (p WeightedPages) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
-func (p WeightedPages) Sort()         { sort.Stable(p) }
-func (p WeightedPages) Count() int    { return len(p) }
-func (p WeightedPages) Less(i, j int) bool {
-	if p[i].Weight == p[j].Weight {
-		if p[i].Page.Date.Equal(p[j].Page.Date) {
-			return p[i].Page.Title < p[j].Page.Title
+func (wp WeightedPages) Len() int      { return len(wp) }
+func (wp WeightedPages) Swap(i, j int) { wp[i], wp[j] = wp[j], wp[i] }
+func (wp WeightedPages) Sort()         { sort.Stable(wp) }
+func (wp WeightedPages) Count() int    { return len(wp) }
+func (wp WeightedPages) Less(i, j int) bool {
+	if wp[i].Weight == wp[j].Weight {
+		if wp[i].Page.Date.Equal(wp[j].Page.Date) {
+			return wp[i].Page.Title < wp[j].Page.Title
 		}
-		return p[i].Page.Date.After(p[i].Page.Date)
+		return wp[i].Page.Date.After(wp[i].Page.Date)
 	}
-	return p[i].Weight < p[j].Weight
+	return wp[i].Weight < wp[j].Weight
 }
 
 // TODO mimic PagesSorter for WeightedPages