diff options
-rw-r--r-- | hugolib/hugo_sites_build_test.go | 2 | ||||
-rw-r--r-- | hugolib/page.go | 12 | ||||
-rw-r--r-- | hugolib/page_test.go | 3 | ||||
-rw-r--r-- | hugolib/site.go | 15 | ||||
-rw-r--r-- | hugolib/site_render.go | 2 | ||||
-rw-r--r-- | output/outputFormat.go | 12 |
6 files changed, 23 insertions, 23 deletions
diff --git a/hugolib/hugo_sites_build_test.go b/hugolib/hugo_sites_build_test.go index e5e36bdcd..5f3ef7a70 100644 --- a/hugolib/hugo_sites_build_test.go +++ b/hugolib/hugo_sites_build_test.go @@ -372,7 +372,7 @@ func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) { require.Equal(t, "Heim", nnSite.Menus["main"].ByName()[0].Name) // Issue #1302 - require.Equal(t, template.URL(""), enSite.RegularPages[0].RSSLink) + require.Equal(t, template.URL(""), enSite.RegularPages[0].RSSLink()) // Issue #3108 next := enSite.RegularPages[0].Next diff --git a/hugolib/page.go b/hugolib/page.go index dba3942de..36c89d958 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -184,8 +184,6 @@ type Page struct { Sitemap Sitemap - RSSLink template.URL - URLPath permalink string relPermalink string @@ -210,6 +208,14 @@ type Page struct { targetPathDescriptorPrototype *targetPathDescriptor } +func (p *Page) RSSLink() template.URL { + f, found := p.outputFormats.GetByName(output.RSSType.Name) + if !found { + return "" + } + return template.URL(newOutputFormat(p, f).Permalink()) +} + func (p *Page) createLayoutDescriptor() output.LayoutDescriptor { var section string @@ -1541,7 +1547,7 @@ func (p *Page) RSSlink() template.URL { // TODO(bep) we cannot have two of these // Remove in Hugo 0.20 helpers.Deprecated(".Page", "RSSlink", "Use RSSLink", true) - return p.RSSLink + return p.RSSLink() } func (p *Page) Ref(ref string) (string, error) { diff --git a/hugolib/page_test.go b/hugolib/page_test.go index d23918603..790a69b38 100644 --- a/hugolib/page_test.go +++ b/hugolib/page_test.go @@ -1346,7 +1346,6 @@ func TestIndexPageSimpleMethods(t *testing.T) { }{ {func(n *Page) bool { return n.IsNode() }}, {func(n *Page) bool { return !n.IsPage() }}, - {func(n *Page) bool { return n.RSSLink == "rssLink" }}, {func(n *Page) bool { return n.Scratch() != nil }}, {func(n *Page) bool { return n.Hugo() != nil }}, {func(n *Page) bool { return n.Now().Unix() == time.Now().Unix() }}, @@ -1354,8 +1353,6 @@ func TestIndexPageSimpleMethods(t *testing.T) { n := s.newHomePage() - n.RSSLink = "rssLink" - if !this.assertFunc(n) { t.Errorf("[%d] Node method error", i) } diff --git a/hugolib/site.go b/hugolib/site.go index 536bf738b..fa37f41d1 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -20,7 +20,6 @@ import ( "io" "net/url" "os" - "path" "path/filepath" "strconv" "strings" @@ -2054,19 +2053,9 @@ func (s *Site) newHomePage() *Page { pages := Pages{} p.Data["Pages"] = pages p.Pages = pages - s.setPageURLs(p, "/") return p } -// TODO(bep) output -func (s *Site) setPageURLs(p *Page, in string) { - p.URLPath.URL = s.PathSpec.URLizeAndPrep(in) - p.URLPath.Permalink = s.permalink(p.URLPath.URL) - if p.Kind != KindPage { - p.RSSLink = template.URL(s.permalink(p.URLPath.URL + ".xml")) - } -} - func (s *Site) newTaxonomyPage(plural, key string) *Page { p := s.newNodePage(KindTaxonomy, plural, key) @@ -2081,8 +2070,6 @@ func (s *Site) newTaxonomyPage(plural, key string) *Page { p.Title = strings.Replace(strings.Title(key), "-", " ", -1) } - s.setPageURLs(p, path.Join(plural, key)) - return p } @@ -2100,13 +2087,11 @@ func (s *Site) newSectionPage(name string, section WeightedPages) *Page { } else { p.Title = sectionName } - s.setPageURLs(p, name) return p } func (s *Site) newTaxonomyTermsPage(plural string) *Page { p := s.newNodePage(KindTaxonomyTerm, plural) p.Title = strings.Title(plural) - s.setPageURLs(p, plural) return p } diff --git a/hugolib/site_render.go b/hugolib/site_render.go index d16adcfaf..5290f0179 100644 --- a/hugolib/site_render.go +++ b/hugolib/site_render.go @@ -218,7 +218,7 @@ func (s *Site) render404() error { p.Title = "404 Page not found" p.Data["Pages"] = s.Pages p.Pages = s.Pages - s.setPageURLs(p, "404.html") + p.URLPath.URL = "404.html" nfLayouts := []string{"404.html"} diff --git a/output/outputFormat.go b/output/outputFormat.go index 2ef5fb62b..7137775db 100644 --- a/output/outputFormat.go +++ b/output/outputFormat.go @@ -23,6 +23,7 @@ import ( var ( // An ordered list of built-in output formats // See https://www.ampproject.org/learn/overview/ + // TODO(bep) output rename to AMPFormat etc. AMPType = Format{ Name: "AMP", MediaType: media.HTMLType, @@ -84,6 +85,17 @@ var builtInTypes = map[string]Format{ type Formats []Format +func (formats Formats) GetByName(name string) (f Format, found bool) { + for _, ff := range formats { + if name == ff.Name { + f = ff + found = true + return + } + } + return +} + // Format represents an output represenation, usually to a file on disk. type Format struct { // The Name is used as an identifier. Internal output formats (i.e. HTML and RSS) |