Support array values in findBy filter for multiple authors#1969
Support array values in findBy filter for multiple authors#1969reatlat wants to merge 3 commits into
Conversation
Allow the findBy filter to match against array fields, enabling support for multiple authors on starters, plugins, etc. e.g. "author": ["user-a", "user-b"]
Demonstrates the new array support in the findBy filter by listing multiple authors on FreshJuice starter projects.
|
|
||
| if (Array.isArray(gotten)) { | ||
| if (typeof value === "string") { | ||
| let valueLower = value.toLowerCase(); |
There was a problem hiding this comment.
This might lead to some issues down the line (Turkish-I problem).
I recommend using localeCompare instead.
There was a problem hiding this comment.
Great catch, thanks! Switched to localeCompare with { sensitivity: "base" } in both the array and string comparison paths.
Avoids the Turkish-I problem and other locale-specific casing issues.
Ryuno-Ki
left a comment
There was a problem hiding this comment.
LGTM (But I don't have permissions to actually get this PR in)
|
Hey @zachleat and @Snapstromegon, just wanted to kindly bump this PR. It's been open for a bit and I'd love to get your eyes on it when you have a moment. The change is fairly small, it adds array support to the Thanks for all the amazing work on 11ty, really appreciate your time! Let's Build Awesome 🟢 |
Summary
findByfilter ineleventy.config.jsto support array values, enabling fields likeauthorto list multiple authors["freshjuice-dev", "reatlat"]as a real-world use caseProblem
Currently, starters (and plugins) can only have a single
authorstring. This means a project with multiple contributors can only appear on one author's page.Solution
Add an
Array.isArray()check to thefindByfunction so that when a field value is an array, it matches if any element in the array equals the search value. This is fully backward-compatible — existing string values continue to work unchanged.Test plan