liquidjs
liquidjs copied to clipboard
Support for all built-in Jekyll filters: slugify, number_of_words, date_to_xmlschema, date_to_rfc822
liquidjs is "missing" a couple Jekyll-specific filters:
- slugify
- number_of_words
- date_to_xmlschema
- date_to_rfc822
https://jekyllrb.com/docs/liquid/filters
Would you be willing to include them as part of Liquidjs? If so, I'll create a PR. Please let me know.
It'll be great to have these filters! Except for Jekyll logic specific ones like relative_url.
It'll be great to have these filters! Except for Jekyll logic specific ones like relative_url.
I'm specifically missing the push filter to add an element to an array. Liquid's append seems to be adding a string to my array character-wise. @harttle such new filter would be added to https://github.com/harttle/liquidjs/blob/master/src/filters/array.ts right? And it could look something like this? (Inspired by concat)
export function push<T> (v: T[], arg: T): T[] {
assert(arguments.length === 2, 'push expects 2 arguments')
v = toValue(v)
arg = toValue(arg)
return toArray(v).concat([arg])
}
Or even just:
export function push<T> (v: T[], arg: T): T[] {
return concat(v, [arg])
}
I added this in #611. I hope you like the implementation and decide to accept the PR. Once the PR is merged, does the Playground automatically update to support it?
Ideas for how to support the other filters. I used a full checkbox where I found the filter already in the codebase but did not check too deeply if it is really it or how it is implemented.
Update (by @harttle): will use the following list to track latest status.
- [ ]
relative_url- probably no reasonable way to support? - [ ]
absolute_url- just append tohttps://example.com/? Not super meaningful but could be a difference between someone being able to use LiquidJS Playground out of the box or not if they didn't care for the URL but their code was using this filter. - [ ]
date_to_xmlschema- I think this is justnew Date(toValue(v)).toISOString()? - [ ]
date_to_rfc822- I think this is justnew Date(toValue(v)).toUTCString()? - [ ]
date_to_string- similar to the above but custom formatting - [ ]
date_to_string: "ordinal", "US"- ditto - [ ]
date_to_long_string- ditto - [ ]
date_to_long_string: "ordinal"- ditto - [x]
where- implement usingfilteras this is for arrays only - already done - [ ]
where_exp- this could befilter+evalfor simplicity I think or is there a mechanism for expression parsing? - [x]
find- arrayfind - [x]
find_exp- againfind+evalunless there is an expression parser already - [x]
group_by-reduce - [x]
group_by_exp-reduce+eval - [ ]
xml_escape- not sure what exactly this does but probably some/full overlap withencodeURIComponent - [ ]
cgi_escape- or maybe this isencodeURIComponent? - [ ]
uri_escape- or this? :D - [ ]
number_of_words- this one is gonna be complex and I don't have any experience with handling Asian scripts but for the start I could add a simple latin oriented filter which splits by a space and returns thelengthof that - [ ]
array_to_sentence_string- looks like a simplejoinwith an extra condition - [ ]
markdownify- probably can lean on some popular MD NPM library here - I made #620 + #621 - [ ]
smartify- this might be just areplace? - [ ]
sassify- again a candidate for an NPM package - [ ]
slugify- should be possible with a regex assuming the rules of the slugification are well known - [ ]
jsonify- justJSON.stringify- this could potentially be an alias for the existingjsonfilter? - [ ]
normalize_whitespace- regex - [x]
sort- arraysort- already done - [x]
sample- array index access +Math.random- I made #612 - [ ]
to_integer-Numberconstructor - [x]
push,pop,shift,unshift- the JS array method - I made #611 + #614 - [x]
pop- the JS array method - [x]
shift- the JS array method - [x]
unshift- the JS array method - [ ]
inspect- I think we can just useJSON.stringifyhere and we don't need to follow the same format as Jekyll but the one possible edge case is if someone used the output of this incapture
I am also interested in include_relative and it would be cool to have the Playground have some UI to allow you to upload a file for this and process it client-side to make this work.
I added this in https://github.com/harttle/liquidjs/pull/611. I hope you like the implementation and decide to accept the PR.
As long as Shopify/liquid implements this, I'm good to also add this feature.
Once the PR is merged, does the Playground automatically update to support it?
Yes, it's on CI build for master branch.
According to this link it is one of the built-in Jekyll filters: https://jekyllrb.com/docs/liquid/filters. I took this issue to mean there is interest in adding Jekyll-specific filters on top of the base Liquid language. Are you willing to still accept this filter in that case?
@harttle I don't see a CI build here: https://github.com/harttle/liquidjs/actions Did you mean the GitHub Pages deployment step? Or the Check workflow?
@TomasHubelbauer sorry I thought it was brought from shopify.
But it's also OK to bring jekyll filters to LiquidJS as long as it's not jekyll specific (I mean relying on Jekyll config or anything only available in Jekyll, or any concept only makes sense for Jekyll sites).
I don't see a CI build here
There's a docs flow https://github.com/harttle/liquidjs/blob/master/.github/workflows/docs.yml
Then I regret to inform you that I think #611 might not be working. :( I am trying the snippet in the comments there in the Playground to no avail…
No worry, there's a lot work remaining anyway. Thanks for your effort.
@harttle I added tests for push in #614 and turns out that implementation is fine, the reason it doesn't work on the Playground must be something else. Locally I had a problem running build:docs:
+ ./bin/build-contributors.sh
sed: -e: No such file or directory
sed: 1: "docs/themes/navy/layout ...": extra characters at the end of d command
But on CI there is no such issue: https://github.com/harttle/liquidjs/actions/runs/5060635227/jobs/9083770703
So I don't think this is why push is not working on the Playground. Do you have any ideas on why else it might be?
It'll be great to have these filters! Except for Jekyll logic specific ones like
relative_url.
@harttle - Any chance that the group_by filter can be added?
Added group_by, group_by_exp, find, find_exp in the latest version, @bzerangue please try v10.11.0
Awesome! Thank you! I will check it out.
On Sun, Apr 14, 2024 at 6:38 AM Jun Yang @.***> wrote:
Added group_by, group_by_exp, find, find_exp in the latest version, @bzerangue https://github.com/bzerangue please try v10.11.0
— Reply to this email directly, view it on GitHub https://github.com/harttle/liquidjs/issues/443#issuecomment-2054019519, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAGUG2YIGJH3SYRJMHIZFDY5JTDNAVCNFSM5MK4IPU2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TEMBVGQYDCOJVGE4Q . You are receiving this because you were mentioned.Message ID: @.***>