hugolib, output: Fix RSSLink vs output formats

And remove the now superflous setPageURLs method.
This commit is contained in:
Bjørn Erik Pedersen 2017-03-24 16:54:37 +01:00
parent 87188496fb
commit 5761b93c96
6 changed files with 23 additions and 23 deletions

View File

@ -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

View File

@ -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) {

View File

@ -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)
}

View File

@ -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
}

View File

@ -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"}

View File

@ -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)