hugolib: apply some more Golint rules

This commit is contained in:
bep 2015-03-07 12:53:20 +01:00
parent 5759007874
commit e007c9b25d
6 changed files with 33 additions and 34 deletions

View file

@ -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 @@ type Image struct {
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

View file

@ -21,13 +21,13 @@ import (
* 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 @@ func (by PageBy) Sort(pages Pages) {
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) Sort() {
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 {

View file

@ -131,7 +131,7 @@ func splitPages(pages Pages, size int) []Pages {
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 @@ func (n *Node) Paginator() (*pager, error) {
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.")
}

View file

@ -125,7 +125,7 @@ func (sc shortcode) String() string {
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 @@ func replaceShortcodeTokens(source []byte, prefix string, wrapped bool, replacem
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

View file

@ -167,8 +167,8 @@ func (s *SiteInfo) refLink(ref string, page *Page, relative bool) (string, error
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 @@ func (s *SiteInfo) refLink(ref string, page *Page, relative bool) (string, error
}
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 @@ func readCollator(s *Site, results <-chan HandledResult, errs chan<- error) {
}
if r.page.IsDraft() {
s.draftCount += 1
s.draftCount++
}
if r.page.IsFuture() {
s.futureCount += 1
s.futureCount++
}
}
}
@ -851,7 +851,7 @@ func (s *Site) possibleTaxonomies() (taxonomies []string) {
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 @@ func (s *Site) RenderAliases() error {
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 @@ func (s *Site) appendThemeTemplates(in []string) []string {
}
}
return out
} else {
return in
}
return in
}
type taxRenderInfo struct {
@ -979,7 +978,7 @@ type taxRenderInfo struct {
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 @@ func taxonomyRenderer(s *Site, taxes <-chan taxRenderInfo, results chan<- error,
}
}
// 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 @@ func (s *Site) newSectionListNode(section string, data WeightedPages) *Node {
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 {

View file

@ -184,18 +184,18 @@ func (wp WeightedPages) Next(cur *Page) *Page {
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