Unexpected replacement of :counter in resources→title/name

Hello,

I have discovered an inconsistency with the behavior of the special placeholder :counter in name / title parameters in the resources front-matter.

Problem

If a Resource file is “fetched” by one set of resourcessrc rule, and then again using a different resourcessrc rule later, :counter value substituted in name (probably in title too) stays stuck at 1.

The above problem statement might not make sense at first read, so please review the below details.

Details

What works

This scenario works as expected i.e. the :counter is doing expected substitutions in the Resource Name.

Here I have only:

[[resources]]
  src = "**.pdf"
  name = "pdf-file-:counter"

Counter in name increments fine.

What doesn’t work

In this scenario, the Resource that is “fetched” twice (i.e. photo_specs.pdf) has its counter stuck at 1.

Here I have:

[[resources]]
  src = "documents/photo_specs.pdf"
  title = "Photo Specifications"
[[resources]]
  src = "**.pdf"
  name = "pdf-file-:counter"

The difference from the “What works” case is that, here I first set the title for "documents/photo_specs.pdf".

The behavior is strange though… it could be understood if the name rule had no effect on the Name of "documents/photo_specs.pdf"… assuming that Name was set implicitly in the first rule. The problem is that the Name does get almost set as per the name rule but the count is always stuck at 1.

In summary, if a resource is fetched by an src filter earlier, the :counter messes up if set in a later rule.

Or, to put it another way — It seems like :counter can be used only in the set of rules that first “fetches” a resources.


I hope all that made sense… It was a bit complicated to explain the issue.

The counter is grouped by the matcher + first occurnece of either title or name.

[[resources]]
src = "documents/photo_specs.pdf"
title = “Photo Specifications”
[[resources]]
src = "**.pdf"
name = “pdf-file-:counter”

So the above is basically 2 groups with individual counters.
If you had said:

[[resources]]
src = “documents/photo_specs.pdf”
[resources.params]
someParam = “foo”

[[resources]]
src = "**.pdf"
name = "pdf-file-:counter"
title = “Photo Specifications #:counter

They would be in the same group.

If you have suggestions for improvement to the above, they are welcome, but those should come in form of a spec that takes any ambiguity into account.

In the example I provided, there are 3 PDF files, and I wanted to first set the title of just one pdf file. So the alternative you provided would not work, as that would auto-set the titles of all 3 PDF files.

I thought that the example:

[[resources]]
  src = "documents/photo_specs.pdf"
  title = "Photo Specifications"
[[resources]]
  src = "**.pdf"
  name = "pdf-file-:counter"

was unambiguous… set title for just one file and counter-based name for all files.

The counter is grouped by the matcher + first occurrence of either title or name.

How about: “An individual counter should be grouped to matcher for each title and name, but only for the entities that use the :counter placeholder.

So in the example I posted, the counter will be grouped only with the second matcher, as only that uses :counter.

If the example had been:

[[resources]]
  # using arbitrary glob
  src = "**s.pdf"  
  title = "PDF s #:counter"
[[resources]]
  src = "**.pdf"
  name = "pdf-file-:counter"

"documents/photo_specs.pdf" would get a title like "PDF s #1", but name like "pdf-file-3". This was quite an arbitrary example, and thus an arbitrary outcome.

But this would then allow a normal example like in my original post to work as expected.

Sure, create an issue with that concrete suggestion.

1 Like

Thank you. Just to close the loop for anyone else reading this: