greenelab / lab-website-template

An easy-to-use, flexible website template for labs.
https://greenelab.github.io/lab-website-template/
BSD 3-Clause "New" or "Revised" License
364 stars 315 forks source link

List filters do not match exact value #255

Closed miltondp closed 7 months ago

miltondp commented 7 months ago

Checks

Link to your website repo

https://github.com/pivlab/pivlab-website

Version of Lab Website Template you are using

1.2.0

Description

I created this PR on my lab's website repo to change the order in which lab members are shown. I found that the filters parameter of the List component does not match values exactly; instead, it looks for substrings. For instance, if you have two roles in _data/types.yaml named programmer and programmer-lab, a filter with role: programmer will match both.

This could be fixed by changing the documentation of the List component.

This is how I fixed the bug (see $ at the end of role in second line):

{% include list.html data="members" component="portrait" filters="role: programmer-lab, group: " %}
{% include list.html data="members" component="portrait" filters="role: programmer$, group: " %}
vincerubinetti commented 7 months ago

I will update the documentation about this. Originally I planned to have plain strings be exact matches but at some point I removed that and forgot to update the documentation.

Unfortunately, the filter always receives a plain string (because it comes from liquid/jekyll which doesn't have a special type for regex) and then has to decide whether to treat it as an exact match or regex somehow. I guess I could try to check for if the string contains special regex characters like + or *, but that could be brittle. It's probably best to just always treat it like a regex, and thus a plain string like "lab" would just be a partial match, and you'd have to do ^lab$ for an exact match.

miltondp commented 7 months ago

I agree!

On Wed, Apr 17, 2024, 1:29 PM Vincent Rubinetti @.***> wrote:

I will update the documentation about this. Originally I planned to have plain strings be exact matches but at some point I removed that and forgot to update the documentation.

Unfortunately, the filter always receives either a plain string and then has to decide whether to treat it as an exact match or regex somehow. I guess I could try to check for if the string contains special regex characters like + or *, but that could be brittle. It's probably best to just always treat it like a regex, and thus a plain string like "lab" would just be a partial match.

— Reply to this email directly, view it on GitHub https://github.com/greenelab/lab-website-template/issues/255#issuecomment-2062058409, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABKFD7GK3QU77G3TRKQPO3Y53ERVAVCNFSM6AAAAABGL5CY56VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANRSGA2TQNBQHE . You are receiving this because you authored the thread.Message ID: @.***>

vincerubinetti commented 7 months ago

Fixed with https://github.com/greenelab/lab-website-template-docs/commit/0d93949d4adb98301114a255edf6e83a858007c3