Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've experimented with a new way of generating unique IDs. These are used on some shortcodes like
gallery
.There have been several iterations and all of them have had issues. I submitted a PR time ago (#738) that used
.Ordinal
to generate a unique number inside the page, to fix several galleries in the same page having the same ID. It was later discovered that this didn't work properly on nested shortcodes, like for example, inside a timeline (#1125 (comment)). The current solution generates an id with a random sequence of numbers. Even if it would be very rare, it cannot be discarded the possibility of generating the same id twice in the same page. And it could go unnoticed by a developer that their site suddenly has some page with a broken gallery, since each build is a gamble.My new approach consists on having a partial that can be reusable on everything that needs unique IDs, and this partial iterates through all the parents of the shortcode and gets
.Ordinal
on all of them, and generates an ID concatenating the.RelPermalink
and all ordinals. Then returns the MD5 of the ID. This approach works on all known cases and is deterministic.For example, in a page with a timeline with two galleries, and then another gallery outside the timeline, the sequence of ordinals for each gallery would be like this:
It currently supports up to 16 nested shortcodes, which probably is more than enough. But the amount can be increased easily.