mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-29 04:42:13 -05:00
hugolib: apply some more Golint rules
This commit is contained in:
parent
5759007874
commit
e007c9b25d
6 changed files with 33 additions and 34 deletions
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
package hugolib
|
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
|
// https://support.google.com/webmasters/answer/178636?hl=en
|
||||||
type Image struct {
|
type Image struct {
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ type Image struct {
|
||||||
License string
|
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
|
// https://support.google.com/webmasters/answer/80471?hl=en
|
||||||
type Video struct {
|
type Video struct {
|
||||||
ThumbnailLoc string
|
ThumbnailLoc string
|
||||||
|
|
|
@ -21,13 +21,13 @@ import (
|
||||||
* Implementation of a custom sorter for Pages
|
* 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 {
|
type PageSorter struct {
|
||||||
pages Pages
|
pages Pages
|
||||||
by PageBy
|
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
|
type PageBy func(p1, p2 *Page) bool
|
||||||
|
|
||||||
func (by PageBy) Sort(pages Pages) {
|
func (by PageBy) Sort(pages Pages) {
|
||||||
|
@ -41,9 +41,8 @@ func (by PageBy) Sort(pages Pages) {
|
||||||
var DefaultPageSort = func(p1, p2 *Page) bool {
|
var DefaultPageSort = func(p1, p2 *Page) bool {
|
||||||
if p1.Weight == p2.Weight {
|
if p1.Weight == p2.Weight {
|
||||||
return p1.Date.Unix() > p2.Date.Unix()
|
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) }
|
func (ps *PageSorter) Len() int { return len(ps.pages) }
|
||||||
|
@ -59,9 +58,8 @@ func (p Pages) Sort() {
|
||||||
func (p Pages) Limit(n int) Pages {
|
func (p Pages) Limit(n int) Pages {
|
||||||
if len(p) < n {
|
if len(p) < n {
|
||||||
return p[0:n]
|
return p[0:n]
|
||||||
} else {
|
|
||||||
return p
|
|
||||||
}
|
}
|
||||||
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p Pages) ByWeight() Pages {
|
func (p Pages) ByWeight() Pages {
|
||||||
|
|
|
@ -131,7 +131,7 @@ func splitPages(pages Pages, size int) []Pages {
|
||||||
return split
|
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"].
|
// If it's not, one will be created with all pages in Data["Pages"].
|
||||||
func (n *Node) Paginator() (*pager, error) {
|
func (n *Node) Paginator() (*pager, error) {
|
||||||
|
|
||||||
|
@ -163,9 +163,12 @@ func (n *Node) Paginator() (*pager, error) {
|
||||||
return n.paginator, nil
|
return n.paginator, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Paginator on Page isn't supported, calling this yields an error.
|
||||||
func (p *Page) Paginator() (*pager, error) {
|
func (p *Page) Paginator() (*pager, error) {
|
||||||
return nil, errors.New("Paginators not supported for content pages.")
|
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) {
|
func (p *Page) Paginate(seq interface{}) (*pager, error) {
|
||||||
return nil, errors.New("Paginators not supported for content pages.")
|
return nil, errors.New("Paginators not supported for content pages.")
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,7 +125,7 @@ func (sc shortcode) String() string {
|
||||||
return fmt.Sprintf("%s(%q, %t){%s}", sc.name, params, sc.doMarkup, sc.inner)
|
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
|
// only used for testing
|
||||||
func ShortcodesHandle(stringToParse string, page *Page, t tpl.Template) string {
|
func ShortcodesHandle(stringToParse string, page *Page, t tpl.Template) string {
|
||||||
tmpContent, tmpShortcodes := extractAndRenderShortcodes(stringToParse, page, t)
|
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 {
|
if val, ok := replacements[key]; ok {
|
||||||
return []byte(val)
|
return []byte(val)
|
||||||
} else {
|
|
||||||
panic(fmt.Errorf("unknown shortcode token %q", key))
|
|
||||||
}
|
}
|
||||||
|
panic(fmt.Errorf("unknown shortcode token %q", key))
|
||||||
})
|
})
|
||||||
|
|
||||||
return b, err
|
return b, err
|
||||||
|
|
|
@ -167,8 +167,8 @@ func (s *SiteInfo) refLink(ref string, page *Page, relative bool) (string, error
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
var target *Page = nil
|
var target *Page
|
||||||
var link string = ""
|
var link string
|
||||||
|
|
||||||
if refUrl.Path != "" {
|
if refUrl.Path != "" {
|
||||||
for _, page := range []*Page(*s.Pages) {
|
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 {
|
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 {
|
if relative {
|
||||||
|
@ -649,11 +649,11 @@ func readCollator(s *Site, results <-chan HandledResult, errs chan<- error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.page.IsDraft() {
|
if r.page.IsDraft() {
|
||||||
s.draftCount += 1
|
s.draftCount++
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.page.IsFuture() {
|
if r.page.IsFuture() {
|
||||||
s.futureCount += 1
|
s.futureCount++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -851,7 +851,7 @@ func (s *Site) possibleTaxonomies() (taxonomies []string) {
|
||||||
return
|
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 {
|
func (s *Site) RenderAliases() error {
|
||||||
for _, p := range s.Pages {
|
for _, p := range s.Pages {
|
||||||
for _, a := range p.Aliases {
|
for _, a := range p.Aliases {
|
||||||
|
@ -867,7 +867,7 @@ func (s *Site) RenderAliases() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render pages each corresponding to a markdown file
|
// RenderPages renders pages each corresponding to a markdown file
|
||||||
func (s *Site) RenderPages() error {
|
func (s *Site) RenderPages() error {
|
||||||
|
|
||||||
results := make(chan error)
|
results := make(chan error)
|
||||||
|
@ -967,9 +967,8 @@ func (s *Site) appendThemeTemplates(in []string) []string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
} else {
|
|
||||||
return in
|
|
||||||
}
|
}
|
||||||
|
return in
|
||||||
}
|
}
|
||||||
|
|
||||||
type taxRenderInfo struct {
|
type taxRenderInfo struct {
|
||||||
|
@ -979,7 +978,7 @@ type taxRenderInfo struct {
|
||||||
plural string
|
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
|
// each unique term within a taxonomy will have a page created
|
||||||
func (s *Site) RenderTaxonomiesLists() error {
|
func (s *Site) RenderTaxonomiesLists() error {
|
||||||
wg := &sync.WaitGroup{}
|
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) {
|
func (s *Site) RenderListsOfTaxonomyTerms() (err error) {
|
||||||
taxonomies := viper.GetStringMapString("Taxonomies")
|
taxonomies := viper.GetStringMapString("Taxonomies")
|
||||||
for singular, plural := range taxonomies {
|
for singular, plural := range taxonomies {
|
||||||
|
@ -1132,7 +1131,7 @@ func (s *Site) newSectionListNode(section string, data WeightedPages) *Node {
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render a page for each section
|
// RenderSectionLists renders a page for each section
|
||||||
func (s *Site) RenderSectionLists() error {
|
func (s *Site) RenderSectionLists() error {
|
||||||
for section, data := range s.Sections {
|
for section, data := range s.Sections {
|
||||||
|
|
||||||
|
|
|
@ -184,18 +184,18 @@ func (wp WeightedPages) Next(cur *Page) *Page {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p WeightedPages) Len() int { return len(p) }
|
func (wp WeightedPages) Len() int { return len(wp) }
|
||||||
func (p WeightedPages) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
|
func (wp WeightedPages) Swap(i, j int) { wp[i], wp[j] = wp[j], wp[i] }
|
||||||
func (p WeightedPages) Sort() { sort.Stable(p) }
|
func (wp WeightedPages) Sort() { sort.Stable(wp) }
|
||||||
func (p WeightedPages) Count() int { return len(p) }
|
func (wp WeightedPages) Count() int { return len(wp) }
|
||||||
func (p WeightedPages) Less(i, j int) bool {
|
func (wp WeightedPages) Less(i, j int) bool {
|
||||||
if p[i].Weight == p[j].Weight {
|
if wp[i].Weight == wp[j].Weight {
|
||||||
if p[i].Page.Date.Equal(p[j].Page.Date) {
|
if wp[i].Page.Date.Equal(wp[j].Page.Date) {
|
||||||
return p[i].Page.Title < p[j].Page.Title
|
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
|
// TODO mimic PagesSorter for WeightedPages
|
||||||
|
|
Loading…
Reference in a new issue