node to page: Final TODO-fixes

Updates #2297
This commit is contained in:
Bjørn Erik Pedersen
2016-11-16 21:06:10 +01:00
parent 99d11386a7
commit a843d5d3bb
5 changed files with 99 additions and 116 deletions

View File

@@ -15,9 +15,7 @@ package hugolib
import (
"fmt"
"html/template"
"os"
"path"
"strings"
"sync"
@@ -25,7 +23,6 @@ import (
"github.com/spf13/viper"
"github.com/bep/inflect"
"github.com/spf13/hugo/source"
"github.com/spf13/hugo/tpl"
jww "github.com/spf13/jwalterweatherman"
@@ -300,84 +297,6 @@ func (h *HugoSites) createMissingPages() error {
return nil
}
// TODO(bep) np move
// Move the new* methods after cleanup in site.go
func (s *Site) newNodePage(typ string) *Page {
return &Page{
pageInit: &pageInit{},
Kind: typ,
Data: make(map[string]interface{}),
Site: &s.Info,
language: s.Language,
site: s}
}
func (s *Site) newHomePage() *Page {
p := s.newNodePage(KindHome)
p.Title = s.Info.Title
pages := Pages{}
p.Data["Pages"] = pages
p.Pages = pages
s.setPageURLs(p, "/")
return p
}
func (s *Site) setPageURLs(p *Page, in string) {
p.URLPath.URL = s.Info.pathSpec.URLizeAndPrep(in)
p.URLPath.Permalink = s.Info.permalink(p.URLPath.URL)
p.RSSLink = template.HTML(s.Info.permalink(in + ".xml"))
}
func (s *Site) newTaxonomyPage(plural, key string) *Page {
p := s.newNodePage(KindTaxonomy)
p.sections = []string{plural, key}
if s.Info.preserveTaxonomyNames {
key = s.Info.pathSpec.MakePathSanitized(key)
}
if s.Info.preserveTaxonomyNames {
// keep as is in the title
p.Title = key
} else {
p.Title = strings.Replace(strings.Title(key), "-", " ", -1)
}
s.setPageURLs(p, path.Join(plural, key))
return p
}
func (s *Site) newSectionPage(name string, section WeightedPages) *Page {
p := s.newNodePage(KindSection)
p.sections = []string{name}
sectionName := name
if !s.Info.preserveTaxonomyNames && len(section) > 0 {
sectionName = section[0].Page.Section()
}
sectionName = helpers.FirstUpper(sectionName)
if viper.GetBool("pluralizeListTitles") {
p.Title = inflect.Pluralize(sectionName)
} else {
p.Title = sectionName
}
s.setPageURLs(p, name)
return p
}
func (s *Site) newTaxonomyTermsPage(plural string) *Page {
p := s.newNodePage(KindTaxonomyTerm)
p.sections = []string{plural}
p.Title = strings.Title(plural)
s.setPageURLs(p, plural)
return p
}
func (h *HugoSites) setupTranslations() {
master := h.Sites[0]