rss_test.go - hugo - [fork] hugo port for 9front
(HTM) git clone https://git.drkhsh.at/hugo.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) Submodules
(DIR) README
(DIR) LICENSE
---
rss_test.go (4258B)
---
1 // Copyright 2019 The Hugo Authors. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13
14 package hugolib
15
16 import (
17 "path/filepath"
18 "strings"
19 "testing"
20
21 "github.com/gohugoio/hugo/deps"
22 )
23
24 func TestRSSOutput(t *testing.T) {
25 t.Parallel()
26
27 rssLimit := len(weightedSources) - 1
28
29 cfg, fs := newTestCfg()
30 cfg.Set("baseURL", "http://auth/bub/")
31 cfg.Set("title", "RSSTest")
32 cfg.Set("rssLimit", rssLimit)
33 th, configs := newTestHelperFromProvider(cfg, fs, t)
34
35 rssURI := "index.xml"
36
37 for _, src := range weightedSources {
38 writeSource(t, fs, filepath.Join("content", "sect", src[0]), src[1])
39 }
40
41 buildSingleSite(t, deps.DepsCfg{Fs: fs, Configs: configs}, BuildCfg{})
42
43 // Home RSS
44 th.assertFileContent(filepath.Join("public", rssURI), "<?xml", "rss version", "RSSTest")
45 // Section RSS
46 th.assertFileContent(filepath.Join("public", "sect", rssURI), "<?xml", "rss version", "Sects on RSSTest")
47 // Taxonomy RSS
48 th.assertFileContent(filepath.Join("public", "categories", "hugo", rssURI), "<?xml", "rss version", "Hugo on RSSTest")
49
50 // RSS Item Limit
51 content := readWorkingDir(t, fs, filepath.Join("public", rssURI))
52 c := strings.Count(content, "<item>")
53 if c != rssLimit {
54 t.Errorf("incorrect RSS item count: expected %d, got %d", rssLimit, c)
55 }
56
57 // Encoded summary
58 th.assertFileContent(filepath.Join("public", rssURI), "<?xml", "description", "A <em>custom</em> summary")
59 }
60
61 // Before Hugo 0.49 we set the pseudo page kind RSS on the page when output to RSS.
62 // This had some unintended side effects, esp. when the only output format for that page
63 // was RSS.
64 // For the page kinds that can have multiple output formats, the Kind should be one of the
65 // standard home, page etc.
66 // This test has this single purpose: Check that the Kind is that of the source page.
67 // See https://github.com/gohugoio/hugo/issues/5138
68 func TestRSSKind(t *testing.T) {
69 t.Parallel()
70
71 b := newTestSitesBuilder(t)
72 b.WithSimpleConfigFile().WithTemplatesAdded("index.rss.xml", `RSS Kind: {{ .Kind }}`)
73
74 b.Build(BuildCfg{})
75
76 b.AssertFileContent("public/index.xml", "RSS Kind: home")
77 }
78
79 func TestRSSCanonifyURLs(t *testing.T) {
80 t.Parallel()
81
82 b := newTestSitesBuilder(t)
83 b.WithSimpleConfigFile().WithTemplatesAdded("index.rss.xml", `<rss>{{ range .Pages }}<item>{{ .Content | html }}</item>{{ end }}</rss>`)
84 b.WithContent("page.md", `---
85 Title: My Page
86 ---
87
88 Figure:
89
90 {{< figure src="/images/sunset.jpg" title="Sunset" >}}
91
92
93
94 `)
95 b.Build(BuildCfg{})
96
97 b.AssertFileContent("public/index.xml", "img src="http://example.com/images/sunset.jpg")
98 }
99
100 // Issue 13332.
101 func TestRSSCanonifyURLsSubDir(t *testing.T) {
102 t.Parallel()
103
104 files := `
105 -- hugo.toml --
106 baseURL = 'https://example.org/subdir'
107 disableKinds = ['section','sitemap','taxonomy','term']
108 [markup.goldmark.renderHooks.image]
109 enableDefault = true
110 [markup.goldmark.renderHooks.link]
111 enableDefault = true
112 -- layouts/_default/_markup/render-image.html --
113 {{- $u := urls.Parse .Destination -}}
114 {{- $src := $u.String | relURL -}}
115 <img srcset="{{ $src }}" src="{{ $src }} 2x">
116 <img src="{{ $src }}">
117 {{- /**/ -}}
118 -- layouts/_default/home.html --
119 {{ .Content }}|
120 -- layouts/_default/single.html --
121 {{ .Content }}|
122 -- layouts/_default/rss.xml --
123 {{ with site.GetPage "/s1/p2" }}
124 {{ .Content | transform.XMLEscape | safeHTML }}
125 {{ end }}
126 -- content/s1/p1.md --
127 ---
128 title: p1
129 ---
130 -- content/s1/p2/index.md --
131 ---
132 title: p2
133 ---
134 
135
136 [p1](/s1/p1)
137 -- content/s1/p2/a.jpg --
138 `
139
140 b := Test(t, files)
141
142 b.AssertFileContent("public/index.xml", "https://example.org/subdir/s1/p1/")
143 b.AssertFileContent("public/index.xml",
144 "img src="https://example.org/subdir/a.jpg",
145 "img srcset="https://example.org/subdir/a.jpg" src="https://example.org/subdir/a.jpg 2x")
146 }