ashur / eleventy-plugin-find

An Eleventy utility filter to find array members that match a set of rules
https://eleventy-plugin-find-demo.netlify.app/
2 stars 0 forks source link

Error while building the website #1

Open xplosionmind opened 2 years ago

xplosionmind commented 2 years ago

This plugin is awesome and provides a great functionality, nevertheless it does not work…

log:

[11ty] Problem writing Eleventy templates: (more in DEBUG output)
[11ty] > Having trouble writing template: _site/filinge/definizione

`TemplateWriterWriteError` was thrown
[11ty] > unexpected token at "( { property:...", file:./_layouts/wrapper.html, line:4, col:2

`ParseError` was thrown
[11ty] > unexpected token at "( { property:..."

`AssertionError` was thrown:
[11ty]     AssertionError: unexpected token at "( { property:..."
        at new AssertionError (/Users/tommi/tommi.space/node_modules/@11ty/eleventy/node_modules/liquidjs/dist/liquid.node.cjs.js:666:28)
        at assert (/Users/tommi/tommi.space/node_modules/@11ty/eleventy/node_modules/liquidjs/dist/liquid.node.cjs.js:824:15)
        at Tokenizer.readFilter (/Users/tommi/tommi.space/node_modules/@11ty/eleventy/node_modules/liquidjs/dist/liquid.node.cjs.js:1946:9)
        at Tokenizer.readFilters (/Users/tommi/tommi.space/node_modules/@11ty/eleventy/node_modules/liquidjs/dist/liquid.node.cjs.js:1935:31)
        at new Value (/Users/tommi/tommi.space/node_modules/@11ty/eleventy/node_modules/liquidjs/dist/liquid.node.cjs.js:2420:34)
        at new Output (/Users/tommi/tommi.space/node_modules/@11ty/eleventy/node_modules/liquidjs/dist/liquid.node.cjs.js:2503:23)
        at Parser.parseToken (/Users/tommi/tommi.space/node_modules/@11ty/eleventy/node_modules/liquidjs/dist/liquid.node.cjs.js:2564:24)
        at Parser.parseTokens (/Users/tommi/tommi.space/node_modules/@11ty/eleventy/node_modules/liquidjs/dist/liquid.node.cjs.js:2554:33)
        at Parser.parse (/Users/tommi/tommi.space/node_modules/@11ty/eleventy/node_modules/liquidjs/dist/liquid.node.cjs.js:2548:21)
        at Liquid.parse (/Users/tommi/tommi.space/node_modules/@11ty/eleventy/node_modules/liquidjs/dist/liquid.node.cjs.js:4282:28)
[11ty] Copied 180 files / Wrote 0 files in 2.62 seconds (v1.0.0)
[11ty] Writing _site/pasticci/index.html from ./content/poetry-it.html (liquid)
[11ty] Writing _site/poetry/index.html from ./content/poetry.html (liquid)
ERROR: "watch:eleventy" exited with 1.
ashur commented 2 years ago

@xplosionmind Thanks for the heads-up, I'll look into it!

ashur commented 2 years ago

@xplosionmind My hunch is that the examples in the README, which are written for Nunjucks but not labeled as such, are incompatible with how Liquid filters work.

If you convert the filter call from Nunjucks:

---
fruits:
  - apple
  - banana
  - cherry
---
{{ fruits | find( "cherry" ) }}

to Liquid's format:

{{ fruits | find: "cherry" }}

I believe things should work as expected.

Things get a little trickier if you want to use a property-value object, since Liquid doesn't seem to accept Objects as filter arguments. Instead, you might capture your ruleset first, pass it through a fromJson filter, and then pass that result to the find filter:

---
fruits:
  - name: apple
    color: red
    sour: false

  - name: banana
    color: yellow
    sour: false

  - name: lemon
    color: yellow
    sour: true
---
{%- capture rules -%}
  {
    "property": "sour",
    "value": true
  }
{%- endcapture -%}
{% assign rules = rules | fromJson %}
{{ fruits | find: rules }}

This is adapted from Passing Object Arguments to Liquid Shortcodes in 11ty, which also describes how to implement the fromJson filter.


Please let me know how it goes! If that seems to sort things out, I'll update the README to show both formats.

Thanks again!