Add resources.Match and resources.GetMatch

Fix #6190
This commit is contained in:
Bjørn Erik Pedersen
2019-08-12 16:43:37 +02:00
parent 17ca8f0c4c
commit b64617fe4f
10 changed files with 407 additions and 19 deletions

View File

@@ -502,3 +502,33 @@ func TestMultiSiteResource(t *testing.T) {
b.AssertFileContent("public/text/pipes.txt", "Hugo Pipes")
}
func TestResourcesMatch(t *testing.T) {
t.Parallel()
b := newTestSitesBuilder(t)
b.WithContent("page.md", "")
b.WithSourceFile(
"assets/jsons/data1.json", "json1 content",
"assets/jsons/data2.json", "json2 content",
"assets/jsons/data3.xml", "xml content",
)
b.WithTemplates("index.html", `
{{ $jsons := (resources.Match "jsons/*.json") }}
{{ $json := (resources.GetMatch "jsons/*.json") }}
{{ printf "JSONS: %d" (len $jsons) }}
JSON: {{ $json.RelPermalink }}: {{ $json.Content }}
{{ range $jsons }}
{{- .RelPermalink }}: {{ .Content }}
{{ end }}
`)
b.Build(BuildCfg{})
b.AssertFileContent("public/index.html",
"JSON: /jsons/data1.json: json1 content",
"JSONS: 2", "/jsons/data1.json: json1 content")
}