Debian Codegraph @

hugolib/page_resource_metadata_test.go

raw
1 // Copyright 2026 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 // Issue 14921
21 func TestResourceMetaCounterPlaceholder(t *testing.T) {
22 t.Parallel()
23
24 files := `
25 -- hugo.toml --
26 disableKinds = ['home','rss','section','sitemap','taxonomy','term']
27 -- content/p1/index.md --
28 ---
29 title: p1
30 resources:
31 - src: "*specs.pdf"
32 title: "Specification #:counter"
33 - src: "**.pdf"
34 name: "pdf-file-:counter.pdf"
35 ---
36 -- content/p1/checklist.pdf --
37 -- content/p1/guide.pdf --
38 -- content/p1/other_specs.pdf --
39 -- content/p1/photo_specs.pdf --
40 -- layouts/page.html --
41 <ul>
42 {{- range seq 1 4 }}
43 {{- with $.Resources.Get (printf "pdf-file-%d.pdf" .) }}
44 <li><a href="{{ .RelPermalink }}">{{ .Title }}</a></li>
45 {{- end }}
46 {{- end }}
47 </ul>
48 `
49
50 b := Test(t, files)
51
52 b.AssertFileContent("public/p1/index.html",
53 `<a href="/p1/checklist.pdf">checklist.pdf</a>`,
54 `<a href="/p1/guide.pdf">guide.pdf</a>`,
55 `<a href="/p1/other_specs.pdf">Specification #1</a>`,
56 `<a href="/p1/photo_specs.pdf">Specification #2</a>`,
57 )
58 }