hugo/hugolib/rss_test.go
Cameron Moore 10c13f5d79 hugolib: Make RSS item limit configurable
Add a new rssLimit site configuration option with default of 15.  Prior
to this fix, you could create your own RSS feed to override the default
limit of 15, but we still had a hardcoded limit of 50 items set in
`hugolib.renderRSS()`.

With this option in place, the `range first 15 .Data.Pages` logic is no
longer hardcoded into the embedded RSS template.

Because the size of the slice passed to the template is now limited to
rssLimit instead of 50, this commit is a breaking change for sites
with a custom RSS template that expects more than 15 items.

Fixes #3035
2017-02-17 19:53:08 +01:00

59 lines
1.8 KiB
Go

// Copyright 2016 The Hugo Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package hugolib
import (
"path/filepath"
"strings"
"testing"
"github.com/spf13/hugo/deps"
)
func TestRSSOutput(t *testing.T) {
t.Parallel()
var (
cfg, fs = newTestCfg()
th = testHelper{cfg}
)
rssLimit := len(weightedSources) - 1
rssURI := "customrss.xml"
cfg.Set("baseURL", "http://auth/bub/")
cfg.Set("rssURI", rssURI)
cfg.Set("title", "RSSTest")
cfg.Set("rssLimit", rssLimit)
for _, src := range weightedSources {
writeSource(t, fs, filepath.Join("content", "sect", src.Name), string(src.Content))
}
buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{})
// Home RSS
th.assertFileContent(t, fs, filepath.Join("public", rssURI), true, "<?xml", "rss version", "RSSTest")
// Section RSS
th.assertFileContent(t, fs, filepath.Join("public", "sect", rssURI), true, "<?xml", "rss version", "Sects on RSSTest")
// Taxonomy RSS
th.assertFileContent(t, fs, filepath.Join("public", "categories", "hugo", rssURI), true, "<?xml", "rss version", "Hugo on RSSTest")
// RSS Item Limit
content := readDestination(t, fs, filepath.Join("public", rssURI))
c := strings.Count(content, "<item>")
if c != rssLimit {
t.Errorf("incorrect RSS item count: expected %d, got %d", rssLimit, c)
}
}