Re-add site.RSSLink (and deprecate it)

Fixes #11110
This commit is contained in:
Bjørn Erik Pedersen 2023-06-14 12:04:32 +02:00
parent bb9377b5e5
commit 90b2674ddc
No known key found for this signature in database
GPG key ID: 330E6E2BD4859D8F
3 changed files with 18 additions and 7 deletions

View file

@ -29,6 +29,7 @@ import (
"github.com/gohugoio/hugo/config" "github.com/gohugoio/hugo/config"
"github.com/gohugoio/hugo/config/allconfig" "github.com/gohugoio/hugo/config/allconfig"
"github.com/gohugoio/hugo/deps" "github.com/gohugoio/hugo/deps"
"github.com/gohugoio/hugo/helpers"
"github.com/gohugoio/hugo/identity" "github.com/gohugoio/hugo/identity"
"github.com/gohugoio/hugo/langs" "github.com/gohugoio/hugo/langs"
"github.com/gohugoio/hugo/langs/i18n" "github.com/gohugoio/hugo/langs/i18n"
@ -345,12 +346,10 @@ func (s *Site) Copyright() string {
return s.conf.Copyright return s.conf.Copyright
} }
func (s *Site) RSSLink() string { func (s *Site) RSSLink() template.URL {
rssOutputFormat, found := s.conf.C.KindOutputFormats[page.KindHome].GetByName("rss") helpers.Deprecated("Site.RSSLink", "Use the Output Format's Permalink method instead, e.g. .OutputFormats.Get \"RSS\".Permalink", false)
if !found { rssOutputFormat := s.home.OutputFormats().Get("rss")
return "" return template.URL(rssOutputFormat.Permalink())
}
return s.permalink(rssOutputFormat.BaseFilename())
} }
func (s *Site) Config() page.SiteConfig { func (s *Site) Config() page.SiteConfig {

View file

@ -15,6 +15,7 @@ package hugolib
import ( import (
"fmt" "fmt"
"html/template"
"strings" "strings"
"testing" "testing"
@ -248,7 +249,7 @@ baseName = "feed"
s := h.Sites[0] s := h.Sites[0]
// Issue #3450 // Issue #3450
c.Assert(s.RSSLink(), qt.Equals, "http://example.com/blog/feed.xml") c.Assert(s.RSSLink(), qt.Equals, template.URL("http://example.com/blog/feed.xml"))
} }
// Issue #3614 // Issue #3614

View file

@ -137,6 +137,9 @@ type Site interface {
// LanguagePrefix returns the language prefix for this site. // LanguagePrefix returns the language prefix for this site.
LanguagePrefix() string LanguagePrefix() string
// Deprecated. Use site.Home.OutputFormats.Get "rss" instead.
RSSLink() template.URL
} }
// Sites represents an ordered list of sites (languages). // Sites represents an ordered list of sites (languages).
@ -300,6 +303,10 @@ func (s *siteWrapper) LanguagePrefix() string {
return s.s.LanguagePrefix() return s.s.LanguagePrefix()
} }
func (s *siteWrapper) RSSLink() template.URL {
return s.s.RSSLink()
}
type testSite struct { type testSite struct {
h hugo.HugoInfo h hugo.HugoInfo
l *langs.Language l *langs.Language
@ -444,6 +451,10 @@ func (s testSite) Param(key any) (any, error) {
return nil, nil return nil, nil
} }
func (s testSite) RSSLink() template.URL {
return ""
}
// NewDummyHugoSite creates a new minimal test site. // NewDummyHugoSite creates a new minimal test site.
func NewDummyHugoSite(conf config.AllProvider) Site { func NewDummyHugoSite(conf config.AllProvider) Site {
return testSite{ return testSite{