diff --git a/hugolib/content_map_page.go b/hugolib/content_map_page.go index a8714949b..59e25b729 100644 --- a/hugolib/content_map_page.go +++ b/hugolib/content_map_page.go @@ -652,8 +652,9 @@ func (m *pageMap) getOrCreateResourcesForPage(ps *pageState) resource.Resources sort.SliceStable(res, lessFunc) if len(ps.m.pageConfig.ResourcesMeta) > 0 { + counters := make(map[string]int) for i, r := range res { - res[i] = resources.CloneWithMetadataFromMapIfNeeded(ps.m.pageConfig.ResourcesMeta, r) + res[i] = resources.CloneWithMetadataFromMapIfNeeded(ps.m.pageConfig.ResourcesMeta, r, counters) } sort.SliceStable(res, lessFunc) } diff --git a/hugolib/page_resource_metadata_test.go b/hugolib/page_resource_metadata_test.go new file mode 100644 index 000000000..dc7dc9013 --- /dev/null +++ b/hugolib/page_resource_metadata_test.go @@ -0,0 +1,58 @@ +// Copyright 2026 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 ( + "testing" +) + +// Issue 14921 +func TestResourceMetaCounterPlaceholder(t *testing.T) { + t.Parallel() + + files := ` +-- hugo.toml -- +disableKinds = ['home','rss','section','sitemap','taxonomy','term'] +-- content/p1/index.md -- +--- +title: p1 +resources: + - src: "*specs.pdf" + title: "Specification #:counter" + - src: "**.pdf" + name: "pdf-file-:counter.pdf" +--- +-- content/p1/checklist.pdf -- +-- content/p1/guide.pdf -- +-- content/p1/other_specs.pdf -- +-- content/p1/photo_specs.pdf -- +-- layouts/page.html -- +