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