Skip to content

Support where operators for partial matches #11279

@Seirdy

Description

@Seirdy

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions