shithub: hugo

Download patch

ref: 62e9e7e6ba3eee386c95d0420386132ad8acaa7e
parent: 524eb16686bed7d110c6001c5d98b2ee0a2d80ee
author: Bjørn Erik Pedersen <[email protected]>
date: Wed Nov 16 12:52:03 EST 2016

node to page: Misc. TODO-fixes

Updates #2297

--- a/hugolib/hugo_sites.go
+++ b/hugolib/hugo_sites.go
@@ -191,9 +191,9 @@
 
 func (h *HugoSites) assignMissingTranslations() error {
 	// This looks heavy, but it should be a small number of nodes by now.
-	allPages := h.findAllPagesByNodeTypeNotIn(KindPage)
+	allPages := h.findAllPagesByKindNotIn(KindPage)
 	for _, nodeType := range []string{KindHome, KindSection, KindTaxonomy, KindTaxonomyTerm} {
-		nodes := h.findPagesByNodeTypeIn(nodeType, allPages)
+		nodes := h.findPagesByKindIn(nodeType, allPages)
 
 		// Assign translations
 		for _, t1 := range nodes {
@@ -216,7 +216,7 @@
 	for _, s := range h.Sites {
 
 		// home pages
-		home := s.findPagesByNodeType(KindHome)
+		home := s.findPagesByKind(KindHome)
 		if len(home) > 1 {
 			panic("Too many homes")
 		}
@@ -229,8 +229,8 @@
 		// taxonomy list and terms pages
 		taxonomies := s.Language.GetStringMapString("taxonomies")
 		if len(taxonomies) > 0 {
-			taxonomyPages := s.findPagesByNodeType(KindTaxonomy)
-			taxonomyTermsPages := s.findPagesByNodeType(KindTaxonomyTerm)
+			taxonomyPages := s.findPagesByKind(KindTaxonomy)
+			taxonomyTermsPages := s.findPagesByKind(KindTaxonomyTerm)
 			for _, plural := range taxonomies {
 				tax := s.Taxonomies[plural]
 				foundTaxonomyPage := false
@@ -264,7 +264,7 @@
 			}
 		}
 
-		sectionPages := s.findPagesByNodeType(KindSection)
+		sectionPages := s.findPagesByKind(KindSection)
 		if len(sectionPages) < len(s.Sections) {
 			for name, section := range s.Sections {
 				// A section may be created for the root content folder if a
@@ -544,21 +544,20 @@
 	}
 }
 
-// TODO(bep) np remove
-func (h *HugoSites) findAllPagesByNodeType(n string) Pages {
-	return h.Sites[0].findAllPagesByNodeType(n)
+func (h *HugoSites) findPagesByKindNotIn(kind string, inPages Pages) Pages {
+	return h.Sites[0].findPagesByKindNotIn(kind, inPages)
 }
 
-func (h *HugoSites) findPagesByNodeTypeNotIn(n string, inPages Pages) Pages {
-	return h.Sites[0].findPagesByNodeTypeNotIn(n, inPages)
+func (h *HugoSites) findPagesByKindIn(kind string, inPages Pages) Pages {
+	return h.Sites[0].findPagesByKindIn(kind, inPages)
 }
 
-func (h *HugoSites) findPagesByNodeTypeIn(n string, inPages Pages) Pages {
-	return h.Sites[0].findPagesByNodeTypeIn(n, inPages)
+func (h *HugoSites) findAllPagesByKind(kind string) Pages {
+	return h.findPagesByKindIn(kind, h.Sites[0].AllPages)
 }
 
-func (h *HugoSites) findAllPagesByNodeTypeNotIn(n string) Pages {
-	return h.findPagesByNodeTypeNotIn(n, h.Sites[0].AllPages)
+func (h *HugoSites) findAllPagesByKindNotIn(kind string) Pages {
+	return h.findPagesByKindNotIn(kind, h.Sites[0].AllPages)
 }
 
 // Convenience func used in tests to build a single site/language excluding render phase.
--- a/hugolib/node_as_page_test.go
+++ b/hugolib/node_as_page_test.go
@@ -76,7 +76,7 @@
 	assertFileContent(t, filepath.Join("public", "sect1", "regular1", "index.html"), false, "Single Title: Page 01", "Content Page 01")
 
 	h := s.owner
-	nodes := h.findAllPagesByNodeTypeNotIn(KindPage)
+	nodes := h.findAllPagesByKindNotIn(KindPage)
 	require.Len(t, nodes, 6)
 
 	home := nodes[5] // oldest
@@ -89,7 +89,7 @@
 	section2 := nodes[3]
 	require.Equal(t, "Section2", section2.Title)
 
-	pages := h.findAllPagesByNodeType(KindPage)
+	pages := h.findAllPagesByKind(KindPage)
 	require.Len(t, pages, 4)
 
 	first := pages[0]
@@ -119,7 +119,7 @@
 	assertFileContent(t, filepath.Join("public", "sect1", "page", "2", "index.html"), false,
 		"Pag: Page 02")
 
-	sections := h.findAllPagesByNodeType(KindSection)
+	sections := h.findAllPagesByKind(KindSection)
 
 	require.Len(t, sections, 2)
 
@@ -180,7 +180,7 @@
 	}
 
 	// Home page
-	homePages := s.findIndexNodesByNodeType(KindHome)
+	homePages := s.findPagesByKind(KindHome)
 	require.Len(t, homePages, 1)
 
 	homePage := homePages[0]
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -87,26 +87,36 @@
 	// This collection will be nil for regular pages.
 	Pages Pages
 
-	Params  map[string]interface{}
-	Content template.HTML
-	Summary template.HTML
-	Aliases []string
-	Status  string
-	Images  []Image
-	Videos  []Video
+	// translations will contain references to this page in other language
+	// if available.
+	translations Pages
 
+	// Params contains configuration defined in the params section of page frontmatter.
+	Params map[string]interface{}
+
+	// Content sections
+	Content         template.HTML
+	Summary         template.HTML
 	TableOfContents template.HTML
 
+	Aliases []string
+
+	Images []Image
+	Videos []Video
+
 	Truncated bool
 	Draft     bool
+	Status    string
 
 	PublishDate time.Time
 	ExpiryDate  time.Time
 
+	// PageMeta contains page stats such as word count etc.
+	PageMeta
+
+	// Markup contains the markup type for the content.
 	Markup string
 
-	translations Pages
-
 	extension   string
 	contentType string
 	renderable  bool
@@ -114,7 +124,8 @@
 	Layout            string
 	layoutsCalculated []string
 
-	linkTitle   string
+	linkTitle string
+
 	frontmatter []byte
 
 	// rawContent isn't "raw" as in the same as in the content file.
@@ -126,19 +137,29 @@
 	// state telling if this is a "new page" or if we have rendered it previously.
 	rendered bool
 
-	contentShortCodes   map[string]func() (string, error)
-	shortcodes          map[string]shortcode
-	plain               string // TODO should be []byte
-	plainWords          []string
-	plainInit           sync.Once
-	plainWordsInit      sync.Once
+	// whether the content is in a CJK language.
+	isCJKLanguage bool
+
+	// shortcode state
+	contentShortCodes map[string]func() (string, error)
+	shortcodes        map[string]shortcode
+
+	// the content stripped for HTML
+	plain          string // TODO should be []byte
+	plainWords     []string
+	plainInit      sync.Once
+	plainWordsInit sync.Once
+
+	// rendering configuration
 	renderingConfig     *helpers.Blackfriday
 	renderingConfigInit sync.Once
-	pageMenus           PageMenus
-	pageMenusInit       sync.Once
-	isCJKLanguage       bool
-	PageMeta
+
+	// menus
+	pageMenus     PageMenus
+	pageMenusInit sync.Once
+
 	Source
+
 	Position `json:"-"`
 
 	GitInfo *gitmap.GitInfo
@@ -155,7 +176,6 @@
 	// isn't accomanied by one.
 	sections []string
 
-	// TODO(bep) np Site added to page, keep?
 	site *Site
 
 	// Pulled over from Node. TODO(bep) np reorg and group (embed)
@@ -173,6 +193,7 @@
 	Sitemap Sitemap
 
 	RSSLink template.HTML
+
 	URLPath
 
 	paginator     *Pager
@@ -549,7 +570,6 @@
 		return p.layoutsCalculated
 	}
 
-	// TODO(bep) np taxonomy etc.
 	switch p.Kind {
 	case KindHome:
 		return []string{"index.html", "_default/list.html"}
@@ -580,7 +600,7 @@
 	return layouts(p.Type(), layout)
 }
 
-// TODO(bep) np consolidate and test these NodeType switches
+// TODO(bep) consolidate and test these KindHome switches (see other layouts methods)s
 // rssLayouts returns RSS layouts to use for the RSS version of this page, nil
 // if no RSS should be rendered.
 func (p *Page) rssLayouts() []string {
@@ -600,7 +620,6 @@
 	}
 
 	return nil
-
 }
 
 func layouts(types string, layout string) (layouts []string) {
@@ -1441,7 +1460,7 @@
 	switch p.Kind {
 	case KindPage:
 	case KindHome:
-		pages = s.findPagesByNodeTypeNotIn(KindHome, s.Pages)
+		pages = s.findPagesByKindNotIn(KindHome, s.Pages)
 	case KindSection:
 		sectionData, ok := s.Sections[p.sections[0]]
 		if !ok {
@@ -1721,19 +1740,18 @@
 	return kindUnknown
 }
 
-func (p *Page) setNodeTypeVars(s *Site) {
+func (p *Page) setValuesForKind(s *Site) {
 	if p.Kind == kindUnknown {
 		// This is either a taxonomy list, taxonomy term or a section
-		nodeType := s.nodeTypeFromSections(p.sections)
+		nodeType := s.kindFromSections(p.sections)
 
 		if nodeType == kindUnknown {
-			panic(fmt.Sprintf("Unable to determine node type from %q", p.sections))
+			panic(fmt.Sprintf("Unable to determine page kind from %q", p.sections))
 		}
 
 		p.Kind = nodeType
 	}
-	// TODO(bep) np node URL
-	// Set Node URL
+
 	switch p.Kind {
 	case KindHome:
 		p.URLPath.URL = "/"
--- a/hugolib/page_collections.go
+++ b/hugolib/page_collections.go
@@ -39,8 +39,8 @@
 }
 
 func (c *PageCollections) refreshPageCaches() {
-	c.indexPages = c.findPagesByNodeTypeNotIn(KindPage, c.Pages)
-	c.RegularPages = c.findPagesByNodeTypeIn(KindPage, c.Pages)
+	c.indexPages = c.findPagesByKindNotIn(KindPage, c.Pages)
+	c.RegularPages = c.findPagesByKindIn(KindPage, c.Pages)
 
 	// TODO(bep) np remove eventually
 	for _, n := range c.Pages {
@@ -58,14 +58,8 @@
 	return &PageCollections{rawAllPages: pages}
 }
 
-// TODO(bep) np clean and remove finders
-
-func (c *PageCollections) findPagesByNodeType(n string) Pages {
-	return c.findPagesByNodeTypeIn(n, c.Pages)
-}
-
 func (c *PageCollections) getPage(typ string, path ...string) *Page {
-	pages := c.findPagesByNodeTypeIn(typ, c.Pages)
+	pages := c.findPagesByKindIn(typ, c.Pages)
 
 	if len(pages) == 0 {
 		return nil
@@ -93,14 +87,10 @@
 	return nil
 }
 
-func (c *PageCollections) findIndexNodesByNodeType(n string) Pages {
-	return c.findPagesByNodeTypeIn(n, c.indexPages)
-}
-
-func (*PageCollections) findPagesByNodeTypeIn(n string, inPages Pages) Pages {
+func (*PageCollections) findPagesByKindIn(kind string, inPages Pages) Pages {
 	var pages Pages
 	for _, p := range inPages {
-		if p.Kind == n {
+		if p.Kind == kind {
 			pages = append(pages, p)
 		}
 	}
@@ -107,10 +97,10 @@
 	return pages
 }
 
-func (*PageCollections) findPagesByNodeTypeNotIn(n string, inPages Pages) Pages {
+func (*PageCollections) findPagesByKindNotIn(kind string, inPages Pages) Pages {
 	var pages Pages
 	for _, p := range inPages {
-		if p.Kind != n {
+		if p.Kind != kind {
 			pages = append(pages, p)
 		}
 	}
@@ -117,12 +107,8 @@
 	return pages
 }
 
-func (c *PageCollections) findAllPagesByNodeType(n string) Pages {
-	return c.findPagesByNodeTypeIn(n, c.Pages)
-}
-
-func (c *PageCollections) findRawAllPagesByNodeType(n string) Pages {
-	return c.findPagesByNodeTypeIn(n, c.rawAllPages)
+func (c *PageCollections) findPagesByKind(kind string) Pages {
+	return c.findPagesByKindIn(kind, c.Pages)
 }
 
 func (c *PageCollections) addPage(page *Page) {
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -1330,18 +1330,14 @@
 
 	s.assembleTaxonomies()
 
-	// TODO(bep) np
 	for _, p := range s.AllPages {
-		// setNodeTypeVars needs taxonomies
-		p.setNodeTypeVars(s)
+		// this depends on taxonomies
+		p.setValuesForKind(s)
 	}
 
-	// assembleSections: Needs pages (temp lookup)
 	s.assembleSections()
 
-	// TODO(bep) np Site.LastMod
-	pages := s.Pages
-	s.Info.LastChange = pages[0].Lastmod
+	s.Info.LastChange = s.Pages[0].Lastmod
 
 	return
 }
@@ -1530,8 +1526,8 @@
 	s.Sections = make(Taxonomy)
 	s.Info.Sections = s.Sections
 	// TODO(bep) np check these vs the caches
-	regularPages := s.findPagesByNodeType(KindPage)
-	sectionPages := s.findPagesByNodeType(KindSection)
+	regularPages := s.findPagesByKind(KindPage)
+	sectionPages := s.findPagesByKind(KindSection)
 
 	for i, p := range regularPages {
 		s.Sections.add(p.Section(), WeightedPage{regularPages[i].Weight, regularPages[i]}, s.Info.preserveTaxonomyNames)
@@ -1558,7 +1554,7 @@
 	}
 }
 
-func (s *Site) nodeTypeFromSections(sections []string) string {
+func (s *Site) kindFromSections(sections []string) string {
 	if _, isTaxonomy := s.Taxonomies[sections[0]]; isTaxonomy {
 		if len(sections) == 1 {
 			return KindTaxonomyTerm