Debian Codegraph @

hugolib/rss_test.go

raw
1 // Copyright 2025 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 "testing"
18 )
19
20 // Before Hugo 0.49 we set the pseudo page kind RSS on the page when output to RSS.
21 // This had some unintended side effects, esp. when the only output format for that page
22 // was RSS.
23 // For the page kinds that can have multiple output formats, the Kind should be one of the
24 // standard home, page etc.
25 // This test has this single purpose: Check that the Kind is that of the source page.
26 // See https://github.com/gohugoio/hugo/issues/5138
27 func TestRSSKind(t *testing.T) {
28 t.Parallel()
29
30 files := `
31 -- hugo.toml --
32 baseURL = "http://example.com/"
33 -- layouts/index.rss.xml --
34 RSS Kind: {{ .Kind }}
35 `
36 b := Test(t, files)
37
38 b.AssertFileContent("public/index.xml", "RSS Kind: home")
39 }
40
41 func TestRSSCanonifyURLs(t *testing.T) {
42 t.Parallel()
43
44 files := `
45 -- hugo.toml --
46 baseURL = "http://example.com/"
47 -- layouts/index.rss.xml --
48 <rss>{{ range .Pages }}<item>{{ .Content | html }}</item>{{ end }}</rss>
49 -- content/page.md --
50 ---
51 Title: My Page
52 ---
53
54 Figure:
55
56 {{< figure src="/images/sunset.jpg" title="Sunset" >}}
57 `
58 b := Test(t, files)
59
60 b.AssertFileContent("public/index.xml", "img src=&#34;http://example.com/images/sunset.jpg")
61 }
62
63 // Issue 13332.
64 func TestRSSCanonifyURLsSubDir(t *testing.T) {
65 t.Parallel()
66
67 files := `
68 -- hugo.toml --
69 baseURL = 'https://example.org/subdir'
70 disableKinds = ['section','sitemap','taxonomy','term']
71 [markup.goldmark.renderHooks.image]
72 useEmbedded = 'fallback'
73 [markup.goldmark.renderHooks.link]
74 useEmbedded = 'fallback'
75 -- layouts/_markup/render-image.html --
76 {{- $u := urls.Parse .Destination -}}
77 {{- $src := $u.String | relURL -}}
78 <img srcset="{{ $src }}" src="{{ $src }} 2x">
79 <img src="{{ $src }}">
80 {{- /**/ -}}
81 -- layouts/home.html --
82 {{ .Content }}|
83 -- layouts/single.html --
84 {{ .Content }}|
85 -- layouts/rss.xml --
86 {{ with site.GetPage "/s1/p2" }}
87 {{ .Content | transform.XMLEscape | safeHTML }}
88 {{ end }}
89 -- content/s1/p1.md --
90 ---
91 title: p1
92 ---
93 -- content/s1/p2/index.md --
94 ---
95 title: p2
96 ---
97 ![alt](a.jpg)
98
99 [p1](/s1/p1)
100 -- content/s1/p2/a.jpg --
101 `
102
103 b := Test(t, files)
104
105 b.AssertFileContent("public/index.xml", "https://example.org/subdir/s1/p1/")
106 b.AssertFileContent("public/index.xml",
107 "img src=&#34;https://example.org/subdir/a.jpg",
108 "img srcset=&#34;https://example.org/subdir/a.jpg&#34; src=&#34;https://example.org/subdir/a.jpg 2x")
109 }