hugolib: Only return RSSLink when RSS is available

Fixes #1302
This commit is contained in:
Bjørn Erik Pedersen 2017-03-01 12:30:41 +01:00
parent b7a672fd22
commit cc15864744
4 changed files with 14 additions and 4 deletions

View file

@ -6,9 +6,9 @@ import (
"strings" "strings"
"testing" "testing"
"html/template"
"os" "os"
"path/filepath" "path/filepath"
"text/template"
//"github.com/fortytw2/leaktest" //"github.com/fortytw2/leaktest"
"github.com/fsnotify/fsnotify" "github.com/fsnotify/fsnotify"
@ -370,6 +370,9 @@ func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) {
require.Equal(t, "Home", enSite.Menus["main"].ByName()[0].Name) require.Equal(t, "Home", enSite.Menus["main"].ByName()[0].Name)
require.Equal(t, "Heim", nnSite.Menus["main"].ByName()[0].Name) require.Equal(t, "Heim", nnSite.Menus["main"].ByName()[0].Name)
// Issue #1302
require.Equal(t, template.URL(""), enSite.RegularPages[0].RSSLink)
// Issue #3108 // Issue #3108
next := enSite.RegularPages[0].Next next := enSite.RegularPages[0].Next
require.NotNil(t, next) require.NotNil(t, next)

View file

@ -186,7 +186,7 @@ type Page struct {
Sitemap Sitemap Sitemap Sitemap
RSSLink template.HTML RSSLink template.URL
URLPath URLPath
permalink *url.URL permalink *url.URL
@ -1670,7 +1670,7 @@ func (p *Page) Hugo() *HugoInfo {
return hugoInfo return hugoInfo
} }
func (p *Page) RSSlink() template.HTML { 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", "Use RSSlink", "RSSLink", true) helpers.Deprecated(".Page", "Use RSSlink", "RSSLink", true)

View file

@ -2087,7 +2087,9 @@ func (s *Site) newHomePage() *Page {
func (s *Site) setPageURLs(p *Page, in string) { func (s *Site) setPageURLs(p *Page, in string) {
p.URLPath.URL = s.PathSpec.URLizeAndPrep(in) p.URLPath.URL = s.PathSpec.URLizeAndPrep(in)
p.URLPath.Permalink = s.Info.permalink(p.URLPath.URL) p.URLPath.Permalink = s.Info.permalink(p.URLPath.URL)
p.RSSLink = template.HTML(s.Info.permalink(in + ".xml")) if p.Kind != KindPage && p.Kind != KindTaxonomyTerm {
p.RSSLink = template.URL(s.Info.permalink(in + ".xml"))
}
} }
func (s *Site) newTaxonomyPage(plural, key string) *Page { func (s *Site) newTaxonomyPage(plural, key string) *Page {

View file

@ -15,6 +15,7 @@ package hugolib
import ( import (
"fmt" "fmt"
"html/template"
"path/filepath" "path/filepath"
"reflect" "reflect"
"testing" "testing"
@ -125,6 +126,10 @@ others:
s := h.Sites[0] s := h.Sites[0]
// Issue #1302
term := s.getPage(KindTaxonomyTerm, "others")
require.Equal(t, template.URL(""), term.RSSLink)
// Issue #3070 preserveTaxonomyNames // Issue #3070 preserveTaxonomyNames
if preserveTaxonomyNames { if preserveTaxonomyNames {
helloWorld := s.getPage(KindTaxonomy, "others", "Hello Hugo world") helloWorld := s.getPage(KindTaxonomy, "others", "Hello Hugo world")