mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-20 22:23:27 +00:00
hugolib, output: Fix RSSLink vs output formats
And remove the now superflous setPageURLs method.
This commit is contained in:
parent
87188496fb
commit
5761b93c96
6 changed files with 23 additions and 23 deletions
|
@ -372,7 +372,7 @@ func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) {
|
||||||
require.Equal(t, "Heim", nnSite.Menus["main"].ByName()[0].Name)
|
require.Equal(t, "Heim", nnSite.Menus["main"].ByName()[0].Name)
|
||||||
|
|
||||||
// Issue #1302
|
// Issue #1302
|
||||||
require.Equal(t, template.URL(""), enSite.RegularPages[0].RSSLink)
|
require.Equal(t, template.URL(""), enSite.RegularPages[0].RSSLink())
|
||||||
|
|
||||||
// Issue #3108
|
// Issue #3108
|
||||||
next := enSite.RegularPages[0].Next
|
next := enSite.RegularPages[0].Next
|
||||||
|
|
|
@ -184,8 +184,6 @@ type Page struct {
|
||||||
|
|
||||||
Sitemap Sitemap
|
Sitemap Sitemap
|
||||||
|
|
||||||
RSSLink template.URL
|
|
||||||
|
|
||||||
URLPath
|
URLPath
|
||||||
permalink string
|
permalink string
|
||||||
relPermalink string
|
relPermalink string
|
||||||
|
@ -210,6 +208,14 @@ type Page struct {
|
||||||
targetPathDescriptorPrototype *targetPathDescriptor
|
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 {
|
func (p *Page) createLayoutDescriptor() output.LayoutDescriptor {
|
||||||
var section string
|
var section string
|
||||||
|
|
||||||
|
@ -1541,7 +1547,7 @@ func (p *Page) RSSlink() template.URL {
|
||||||
// TODO(bep) we cannot have two of these
|
// TODO(bep) we cannot have two of these
|
||||||
// Remove in Hugo 0.20
|
// Remove in Hugo 0.20
|
||||||
helpers.Deprecated(".Page", "RSSlink", "Use RSSLink", true)
|
helpers.Deprecated(".Page", "RSSlink", "Use RSSLink", true)
|
||||||
return p.RSSLink
|
return p.RSSLink()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Page) Ref(ref string) (string, error) {
|
func (p *Page) Ref(ref string) (string, error) {
|
||||||
|
|
|
@ -1346,7 +1346,6 @@ func TestIndexPageSimpleMethods(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
{func(n *Page) bool { return n.IsNode() }},
|
{func(n *Page) bool { return n.IsNode() }},
|
||||||
{func(n *Page) bool { return !n.IsPage() }},
|
{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.Scratch() != nil }},
|
||||||
{func(n *Page) bool { return n.Hugo() != nil }},
|
{func(n *Page) bool { return n.Hugo() != nil }},
|
||||||
{func(n *Page) bool { return n.Now().Unix() == time.Now().Unix() }},
|
{func(n *Page) bool { return n.Now().Unix() == time.Now().Unix() }},
|
||||||
|
@ -1354,8 +1353,6 @@ func TestIndexPageSimpleMethods(t *testing.T) {
|
||||||
|
|
||||||
n := s.newHomePage()
|
n := s.newHomePage()
|
||||||
|
|
||||||
n.RSSLink = "rssLink"
|
|
||||||
|
|
||||||
if !this.assertFunc(n) {
|
if !this.assertFunc(n) {
|
||||||
t.Errorf("[%d] Node method error", i)
|
t.Errorf("[%d] Node method error", i)
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,6 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -2054,19 +2053,9 @@ func (s *Site) newHomePage() *Page {
|
||||||
pages := Pages{}
|
pages := Pages{}
|
||||||
p.Data["Pages"] = pages
|
p.Data["Pages"] = pages
|
||||||
p.Pages = pages
|
p.Pages = pages
|
||||||
s.setPageURLs(p, "/")
|
|
||||||
return 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 {
|
func (s *Site) newTaxonomyPage(plural, key string) *Page {
|
||||||
|
|
||||||
p := s.newNodePage(KindTaxonomy, plural, key)
|
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)
|
p.Title = strings.Replace(strings.Title(key), "-", " ", -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
s.setPageURLs(p, path.Join(plural, key))
|
|
||||||
|
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2100,13 +2087,11 @@ func (s *Site) newSectionPage(name string, section WeightedPages) *Page {
|
||||||
} else {
|
} else {
|
||||||
p.Title = sectionName
|
p.Title = sectionName
|
||||||
}
|
}
|
||||||
s.setPageURLs(p, name)
|
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Site) newTaxonomyTermsPage(plural string) *Page {
|
func (s *Site) newTaxonomyTermsPage(plural string) *Page {
|
||||||
p := s.newNodePage(KindTaxonomyTerm, plural)
|
p := s.newNodePage(KindTaxonomyTerm, plural)
|
||||||
p.Title = strings.Title(plural)
|
p.Title = strings.Title(plural)
|
||||||
s.setPageURLs(p, plural)
|
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
|
@ -218,7 +218,7 @@ func (s *Site) render404() error {
|
||||||
p.Title = "404 Page not found"
|
p.Title = "404 Page not found"
|
||||||
p.Data["Pages"] = s.Pages
|
p.Data["Pages"] = s.Pages
|
||||||
p.Pages = s.Pages
|
p.Pages = s.Pages
|
||||||
s.setPageURLs(p, "404.html")
|
p.URLPath.URL = "404.html"
|
||||||
|
|
||||||
nfLayouts := []string{"404.html"}
|
nfLayouts := []string{"404.html"}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ import (
|
||||||
var (
|
var (
|
||||||
// An ordered list of built-in output formats
|
// An ordered list of built-in output formats
|
||||||
// See https://www.ampproject.org/learn/overview/
|
// See https://www.ampproject.org/learn/overview/
|
||||||
|
// TODO(bep) output rename to AMPFormat etc.
|
||||||
AMPType = Format{
|
AMPType = Format{
|
||||||
Name: "AMP",
|
Name: "AMP",
|
||||||
MediaType: media.HTMLType,
|
MediaType: media.HTMLType,
|
||||||
|
@ -84,6 +85,17 @@ var builtInTypes = map[string]Format{
|
||||||
|
|
||||||
type Formats []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.
|
// Format represents an output represenation, usually to a file on disk.
|
||||||
type Format struct {
|
type Format struct {
|
||||||
// The Name is used as an identifier. Internal output formats (i.e. HTML and RSS)
|
// The Name is used as an identifier. Internal output formats (i.e. HTML and RSS)
|
||||||
|
|
Loading…
Add table
Reference in a new issue