Filter regex_replace: |regex_replace("/index.html$","/")
kno10 opened this issue · comments
For generating, e.g., canonical URLs it is nice to have a function to strip, e.g., index.html
from the end of a string.
Regular replace
would replace anywhere in a string.
This appears to be popular:
It makes sense for these tools, even though the built-in removesuffix
method strings have in recent Python 3 versions seems to be almost enough for that.
I don't think it belongs into core jinja though - in most contexts this type of logic is better suited elsewhere (for example in case of Flask or even Django, you typically want to let your web framework build URLs and never modify string URLs).
The use of regex is not limited to URLs.
IMHO it is better to have one copy of this functionality in main jekyll, instead of multiple variants of it in salt, ansible, etc.