summaryrefslogtreecommitdiffstats
path: root/resource/resource_test.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-01-27 10:22:42 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-01-27 10:22:42 +0100
commit7b472e46084b603045b87cea870ffc73ac1cf7e7 (patch)
tree34da0356f12344350555c44300dba8038061ece3 /resource/resource_test.go
parent96e3fbcf23ceb946504d7e82ea08bf1c30b0fe5f (diff)
downloadhugo-7b472e46084b603045b87cea870ffc73ac1cf7e7.tar.gz
hugo-7b472e46084b603045b87cea870ffc73ac1cf7e7.zip
resource: Start Resources :counter first time they're used
This is less surprising and more flexible than the original implementation. Given: ```toml [[resources]] src = "documents/photo_specs.pdf" title = "Photo Specifications" [[resources]] src = "**.pdf" name = "pdf-file-:counter" ``` Every `pdf` in the bundle will have an unique counter, but the `photo_specs.pdf` is still allowed to have its specific `title`. If you change the above example to: ```toml [[resources]] src = "documents/*specs.pdf" title = "Photo Specifications #:conter" [[resources]] src = "**.pdf" name = "pdf-file-:counter" ``` We are talking about two different groups of documents, each with its own counters starting at 1. Fixes #4335
Diffstat (limited to 'resource/resource_test.go')
-rw-r--r--resource/resource_test.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/resource/resource_test.go b/resource/resource_test.go
index 54d200c1c..fc6416e6a 100644
--- a/resource/resource_test.go
+++ b/resource/resource_test.go
@@ -312,6 +312,48 @@ func TestAssignMetadata(t *testing.T) {
assert.Equal("Name #2", logo1.Name())
}},
+ // Start counting first time :counter is used
+ // See https://github.com/gohugoio/hugo/issues/4335
+ {[]map[string]interface{}{
+ map[string]interface{}{
+ "title": "Third Logo",
+ "src": "logo3.png",
+ },
+ map[string]interface{}{
+ "title": "Other Logo #:counter",
+ "name": "Name #:counter",
+ "src": "logo*",
+ },
+ }, func(err error) {
+ assert.NoError(err)
+ assert.Equal("Third Logo", logo3.Title())
+ assert.Equal("Name #3", logo3.Name())
+ assert.Equal("Other Logo #1", logo2.Title())
+ assert.Equal("Name #1", logo2.Name())
+ assert.Equal("Other Logo #2", logo1.Title())
+ assert.Equal("Name #2", logo1.Name())
+
+ }},
+ {[]map[string]interface{}{
+ map[string]interface{}{
+ "name": "third-logo",
+ "src": "logo3.png",
+ },
+ map[string]interface{}{
+ "title": "Logo #:counter",
+ "name": "Name #:counter",
+ "src": "logo*",
+ },
+ }, func(err error) {
+ assert.NoError(err)
+ assert.Equal("Logo #3", logo3.Title())
+ assert.Equal("third-logo", logo3.Name())
+ assert.Equal("Logo #1", logo2.Title())
+ assert.Equal("Name #1", logo2.Name())
+ assert.Equal("Logo #2", logo1.Title())
+ assert.Equal("Name #2", logo1.Name())
+
+ }},
{[]map[string]interface{}{
map[string]interface{}{
"title": "Third Logo #:counter",