I would like to use string replace to process a text resource (an HTML file).
I use resources.ExecuteAsTemplate already - but there are other changes I’d like to make to change some of the strings.
Basically, I want a version of replace that works on resources - just like ExecuteAsTemplate does.
Ideally, I could make a pipeline that gets a resource, does a string replace, and then does an execute as template. Something like (I know this doesn’t work):
It works like a charm - and once I am in string land, I can do all kinds of other things!
Three small semi-related questions…
ExecuteAsTemplate puts the result in a root-relative directory. Is there a way to put it in the same directory as the page bundle is going into (the html for the page bundle)?
It seems like the temp file (“some-path” in the example) doesn’t actually become a file in the result. (this is good - I don’t want the temp file). Can I re-use the temp file name?
It seems that the original file (from a page bundle) is copied into the result (in the example, foo.js would be in the built result alongside new.js). Is there a way to prevent this?
{{ with resources.ExecuteAsTemplate (add page.Path "/target.json") page . }}
this will use the same logical path as the current page
no publish is expected. You will have to explicitly publish it in case you need that. see docs
The resources.FromString function returns a resource created from a string, caching the result using the target path as its cache key.
I did a quick test, and in that use case it works. Guess the caching will only affect publishing the resource twice blocking a duplicate render to the same path. I expect than the first publish wins. → So I would guess you can.
use build options
frontmatter of the page bundle index page
[build]
publishResources = false
Hint: if you use 3) to suppress the automatic publishing of resources, you may use the same name for your target file in 1) without a duplicatePathWarning.
if you just use the same name without setting 3) the resource will be published twice to the same path and the last one wins. (in your use case that may work, but in others won’t)
guess so you could name all TARGETPATH arguments the same