ref: 5761b93c96e89a1e269156c179841301e5808fad
parent: 87188496fbb68c39567ec3ee3a55a9305a13e48b
author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
date: Fri Mar 24 12:54:37 EDT 2017
hugolib, output: Fix RSSLink vs output formats And remove the now superflous setPageURLs method.
--- a/hugolib/hugo_sites_build_test.go
+++ b/hugolib/hugo_sites_build_test.go
@@ -372,7 +372,7 @@
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
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -184,8 +184,6 @@
Sitemap Sitemap
- RSSLink template.URL
-
URLPath
permalink string
relPermalink string
@@ -210,6 +208,14 @@
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 @@
// 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) {
--- a/hugolib/page_test.go
+++ b/hugolib/page_test.go
@@ -1346,7 +1346,6 @@
}{
{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() }},
@@ -1353,8 +1352,6 @@
} {
n := s.newHomePage()
-
- n.RSSLink = "rssLink"
if !this.assertFunc(n) {
t.Errorf("[%d] Node method error", i)
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -20,7 +20,6 @@
"io"
"net/url"
"os"
- "path"
"path/filepath"
"strconv"
"strings"
@@ -2054,19 +2053,9 @@
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 @@
p.Title = strings.Replace(strings.Title(key), "-", " ", -1)
}
- s.setPageURLs(p, path.Join(plural, key))
-
return p
}
@@ -2100,7 +2087,6 @@
} else {
p.Title = sectionName
}
- s.setPageURLs(p, name)
return p
}
@@ -2107,6 +2093,5 @@
func (s *Site) newTaxonomyTermsPage(plural string) *Page {
p := s.newNodePage(KindTaxonomyTerm, plural)
p.Title = strings.Title(plural)
- s.setPageURLs(p, plural)
return p
}
--- a/hugolib/site_render.go
+++ b/hugolib/site_render.go
@@ -218,7 +218,7 @@
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"}
--- a/output/outputFormat.go
+++ b/output/outputFormat.go
@@ -23,6 +23,7 @@
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,
@@ -83,6 +84,17 @@
}
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 {