From 3ff25b37a3d327646255572072d6686d48a142e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Wed, 2 Nov 2016 21:34:19 +0100 Subject: [PATCH] node to page: Handle RSS Updates #2297 --- hugolib/hugo_sites.go | 13 +++++++++---- hugolib/node_as_page_test.go | 25 +++++++++++++++++++++---- hugolib/page.go | 29 +++++++++++++++++++++++++++-- hugolib/site.go | 1 + hugolib/site_render.go | 26 ++++++++++++++++++++++++++ 5 files changed, 84 insertions(+), 10 deletions(-) diff --git a/hugolib/hugo_sites.go b/hugolib/hugo_sites.go index 8332640df..23694319a 100644 --- a/hugolib/hugo_sites.go +++ b/hugolib/hugo_sites.go @@ -17,6 +17,7 @@ import ( "errors" "fmt" "os" + "path" "strings" "sync" "time" @@ -390,6 +391,11 @@ func (h *HugoSites) createMissingNodes() error { // TODO(bep) np check node title etc. s := h.Sites[0] + // TODO(bep) np + for _, p := range s.Pages { + p.setNodeTypeVars(s) + } + home := s.findPagesByNodeType(NodeHome) // home page @@ -460,7 +466,7 @@ func (s *Site) newNodePage(typ NodeType) *Page { language: s.Language, } - return &Page{Node: n} + return &Page{Node: n, site: s} } func (s *Site) newHomePage() *Page { @@ -489,6 +495,7 @@ func (s *Site) newTaxonomyPage(plural, key string) *Page { } // TODO(bep) np check set url + p.URLPath.URL = path.Join(plural, key) return p } @@ -509,7 +516,7 @@ func (s *Site) newSectionPage(name string, section WeightedPages) *Page { } else { p.Title = sectionName } - + p.URLPath.URL = name return p } @@ -613,8 +620,6 @@ func (s *Site) preparePagesForRender(cfg BuildCfg, changed whatChanged) { continue } - p.setNodeTypeVars(s) - // If we got this far it means that this is either a new Page pointer // or a template or similar has changed so wee need to do a rerendering // of the shortcodes etc. diff --git a/hugolib/node_as_page_test.go b/hugolib/node_as_page_test.go index 9c8506503..8276f2d23 100644 --- a/hugolib/node_as_page_test.go +++ b/hugolib/node_as_page_test.go @@ -31,8 +31,8 @@ import ( */ func TestNodesAsPage(t *testing.T) { - //jww.SetStdoutThreshold(jww.LevelDebug) - jww.SetStdoutThreshold(jww.LevelFatal) + jww.SetStdoutThreshold(jww.LevelDebug) + //jww.SetStdoutThreshold(jww.LevelFatal) nodePageFeatureFlag = true defer toggleNodePageFeatureFlag() @@ -105,6 +105,8 @@ Content Page %02d } viper.Set("paginate", 1) + viper.Set("title", "Hugo Rocks") + viper.Set("rssURI", "customrss.xml") s := newSiteDefaultLang() @@ -172,11 +174,18 @@ Content Page %02d // There are no pages to paginate over in the taxonomy terms. + // RSS + assertFileContent(t, filepath.Join("public", "customrss.xml"), false, "Recent content in Home Sweet Home! on Hugo Rocks", "\n") diff --git a/hugolib/site_render.go b/hugolib/site_render.go index bad831d6c..bf6b78231 100644 --- a/hugolib/site_render.go +++ b/hugolib/site_render.go @@ -76,6 +76,10 @@ func pageRenderer(s *Site, pages <-chan *Page, results chan<- error, wg *sync.Wa results <- err } } + + if err := s.renderRSS(p); err != nil { + results <- err + } } } @@ -121,3 +125,25 @@ func (s *Site) renderPaginator(p *Page) error { } return nil } + +func (s *Site) renderRSS(p *Page) error { + layouts := p.rssLayouts() + + if layouts == nil { + // No RSS for this NodeType + return nil + } + + // TODO(bep) np check RSS titles + rssNode := p.copy() + + // TODO(bep) np todelido URL + rssURI := s.Language.GetString("rssURI") + rssNode.URLPath.URL = path.Join(rssNode.URLPath.URL, rssURI) + + if err := s.renderAndWriteXML(rssNode.Title, rssNode.URLPath.URL, rssNode, s.appendThemeTemplates(layouts)...); err != nil { + return err + } + + return nil +}