Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support where operators for partial matches #11279

Closed
Seirdy opened this issue Jul 23, 2023 · 2 comments · Fixed by #11281
Closed

Support where operators for partial matches #11279

Seirdy opened this issue Jul 23, 2023 · 2 comments · Fixed by #11281

Comments

@Seirdy
Copy link
Contributor

Seirdy commented Jul 23, 2023

Currently, the where function is a concise way to filter a collection by comparing exact matches between the collections’ data and known values. However, there’s no way to filter it to contain non-exact matches, such as substring, regex, or other types of matches.

One use-case: on my website, I have a data template containing Webmentions (a type of decentralized commenting) for my entire site. Each Webmention has a target URL. I insert Webmentions whose target URL matches the current page, so that each page can end with its own comments section.

I used to use a where filter to select just the mentions whose targets match the canonical URL of the current page; however, this didn’t account for fragments. I wanted the fragments at the end of a target URL to be ignored during comparison. where doesn’t support operators regular expressions, substring matching, or URL parsing. I had to resort to iteration and appending. Here’s a diff containing that change: Seirdy/seirdy.one@6fc55df (plaintext).

Discussed on discourse.gohugo.io

@Seirdy
Copy link
Contributor Author

Seirdy commented Jul 23, 2023

Fixed a typo: s/when/where/g

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants