Thanks @zwbets - I understand the confusion, as I am not very clear.
Some more explanation for people.
OBJECTIVE
I am trying to make a partial that will let people easily have their markdown images converted to responsive/srcset type images without shortcodes.
This way people can ‘set and forget’ their image processing, or have more granular control at the page level or even specific image level - including adding classes - and all with natural markdown.
OPERATION
I intend the partial to to work at:
- the img level, using commands/values in the alt text string after a
#
symbol (“for an image”) (eg ![alt text#class: wide-image lazy](image.jpg)
,
then falling back to any
- commands/values at the page level (.Params in frontmatter) (“for a page”),
then falling back to
- commands/values the site level (.Site.Params. from config files) (“sitewide”).
Currently, the sort of commands/values intended to be included:
- “isOn” - if image/images are processed at all
- “srcFolder” - optional central image folder, instead of page bundles
- “sizes” - the user-defined output parameters like widths and quality (possibly height too?)
- “conditions” - the media conditions
- “class” - add css class value(s)
- “leave” - used to tell partial not to replace a particular image (except strip the “#leave” from alt text)
This process really involves two steps:
- replacing the img references in the html; and
- generating the smaller image versions (using the width of the original)
PROGRESS
I am very much at the beginning of this.
What I am trying to do now relates to the first step - replacing the image references in the html.
At the moment, I am finding the references and replacing them with some test text.
However, the replacement value is not changing between the two test images as expected.
(Side note: The two image references are actually the same one, but it doesn’t matter for this part as it is the references I’m working on for now).
Instead, both images are replaced with the same test text when I expecting (hoping) it would differ.
I think the replaceRE
replacement value ($replacement) gets set the first img it comes across, and doesn’t update with each new img replacement in the page. However, as I said, I am a fish out of water and so do not know.
Once we can conditionally determine each image’s output, we can set the per image level command/values and start kicking this into action.
Hope that makes more sense.
I am fully aware this is probably being done awfully, and that an adept coder would probably have this done in like 20-30 minutes. But until someone pitches in, I’ll just keep chipping away at this as I get time.
IGNORE THIS THREAD FOR NOW.
From now on, I will refine my questions to specific issues to prevent confusion.
If I don’t get distracted (likely) and finish this I will share here and/or as a tip and trick, and so others can use.