Compare commits

...
4 Commits
Author SHA1 Message Date
Yang Jun 2331da37a9 chore: use Node@20 to build 2024-04-28 23:13:12 +08:00
Yang Jun 52a3059727 fix: case/when array equality, #673 2024-04-28 23:07:27 +08:00
Yang Jun 1e4414950c feat: introduce where_exp filter from Jekyll 2024-04-28 23:07:22 +08:00
Yang Jun 9b0e61249e docs: add customerio as contributor 2024-04-28 23:01:59 +08:00
22 changed files with 140 additions and 1271 deletions
+1 -1
View File
@@ -22,7 +22,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '14'
node-version: '20'
- name: Install dependencies
run: npm ci
- name: Build
+1 -1
View File
@@ -12,7 +12,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '14'
node-version: '20'
- name: Install dependencies
run: npm ci
- name: Test
+1 -1
View File
@@ -12,7 +12,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '14'
node-version: '20'
- name: Build
run: |
npm ci
+1 -1
View File
@@ -12,7 +12,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '14'
node-version: '20'
- name: Install dependencies
run: npm ci
- name: Lint
+1 -1
View File
@@ -17,7 +17,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '14'
node-version: '20'
- name: Download artifacts
uses: actions/download-artifact@v3
with:
+1 -1
View File
@@ -16,7 +16,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '14'
node-version: '20'
- name: Install dependencies
run: npm ci
- name: Download artifacts
+1
View File
@@ -13,6 +13,7 @@ node_modules/
# tmp
docs/public/js/liquid.browser.min.js
docs/themes/navy/layout/partial/all-contributors.swig
docs/themes/navy/layout/partial/financial-contributors.swig
dist/
demo/*/yarn.json
+1
View File
@@ -91,6 +91,7 @@ Special thanks to the following sponsors!
<td align="center" valign="top" width="14.28%"><a href="https://opencollective.com/khaled-salem"><img src="https://images.opencollective.com/khaled-salem/avatar/256.png?height=256" width="100px;" alt="Khaled Salem"/><br /><sub><b>Khaled Salem</b></sub></a></td>
<td align="center" valign="top" width="14.28%"><a href="https://sentry.io/"><img src="https://avatars.githubusercontent.com/u/1396951?v=4?s=100" width="100px;" alt="Sentry"/><br /><sub><b>Sentry</b></sub></a></td>
<td align="center" valign="top" width="14.28%"><a href="https://www.checkoutblocks.com/"><img src="https://avatars.githubusercontent.com/u/114603307?v=4?s=100" width="100px;" alt="Checkout Blocks"/><br /><sub><b>Checkout Blocks</b></sub></a></td>
<td align="center" valign="top" width="14.28%"><a href="https://customer.io/"><img src="https://avatars.githubusercontent.com/u/1152079?v=4?s=100" width="100px;" alt="Customer IO"/><br /><sub><b>Customer IO</b></sub></a></td>
</tr>
</tbody>
</table>
+2 -4
View File
@@ -11,7 +11,5 @@ sed -i \
source/tutorials/changelog.md
cp source/tutorials/changelog.md source/zh-cn/tutorials/changelog.md
sed -i -e '1i\
---\ntitle: Changelog\nauto: true\n---\n' source/tutorials/changelog.md
sed -i -e '1i\
---\ntitle: 更新日志\nauto: true\n---\n' source/zh-cn/tutorials/changelog.md
sed -i -e '1i\---\ntitle: Changelog\nauto: true\n---\n' source/tutorials/changelog.md
sed -i -e '1i\---\ntitle: 更新日志\nauto: true\n---\n' source/zh-cn/tutorials/changelog.md
+6 -9
View File
@@ -10,15 +10,12 @@ sedi() {
}
# create docs/themes/navy/layout/partial/all-contributors.swig
cp .all-contributorsrc docs/.all-contributorsrc
sedi \
-e 's/README.md/docs\/themes\/navy\/layout\/partial\/all-contributors.swig/g' \
-e 's/"contributorsPerLine": 7/"contributorsPerLine": 65535/g' \
docs/.all-contributorsrc
touch docs/themes/navy/layout/partial/all-contributors.swig
all-contributors --config docs/.all-contributorsrc generate
sedi 's/<br \/>.*<\/td>/<\/a><\/td>/g' docs/themes/navy/layout/partial/all-contributors.swig
awk '/ALL-CONTRIBUTORS-LIST:START/{flag=1;next}/ALL-CONTRIBUTORS-LIST:END/{flag=0}flag' README.md | \
sed 's/<br \/>.*<\/td>/<\/a><\/td>/g' | \
sed 's/width="[^"]*"//g' | \
tr -d '\n' | \
sed 's/<\/tr>\s*<tr>//g' \
> docs/themes/navy/layout/partial/all-contributors.swig
# create docs/themes/navy/layout/partial/financial-contributors.swig
awk '/FINANCIAL-CONTRIBUTORS-BEGIN/{flag=1;next}/FINANCIAL-CONTRIBUTORS-END/{flag=0}flag' README.md | \
-1247
View File
File diff suppressed because it is too large Load Diff
-1
View File
@@ -28,7 +28,6 @@
"hexo-uglify": "^1.0.0"
},
"devDependencies": {
"all-contributors-cli": "^6.8.1",
"eslint": "^6.0.1",
"eslint-config-hexo": "^4.0.0"
},
+1
View File
@@ -88,6 +88,7 @@ filters:
url_decode: url_decode.html
url_encode: url_encode.html
where: where.html
where_exp: where_exp.html
tags:
overview: overview.html
+1 -1
View File
@@ -12,7 +12,7 @@ Categories | Filters
Math | plus, minus, modulo, times, floor, ceil, round, divided_by, abs, at_least, at_most
String | append, prepend, capitalize, upcase, downcase, strip, lstrip, rstrip, strip_newlines, split, replace, replace_first, replace_last,remove, remove_first, remove_last, truncate, truncatewords
HTML/URI | escape, escape_once, url_encode, url_decode, strip_html, newline_to_br
Array | slice, map, sort, sort_natural, uniq, where, group_by, group_by_exp, find, find_exp, first, last, join, reverse, concat, compact, size, push, pop, shift, unshift
Array | slice, map, sort, sort_natural, uniq, where, where_exp, group_by, group_by_exp, find, find_exp, first, last, join, reverse, concat, compact, size, push, pop, shift, unshift
Date | date
Misc | default, json, raw
+37
View File
@@ -0,0 +1,37 @@
---
title: where_exp
---
{% since %}v10.12.0{% endsince %}
Select all the objects in an array where the expression is true. In this example, assume you have a list of products and you want to show your kitchen products separately. Using `where_exp`, you can create an array containing only the products that have a `"type"` of `"kitchen"`.
Input
```liquid
All products:
{% for product in products %}
- {{ product.title }}
{% endfor %}
{% assign kitchen_products = products | where_exp: "item", "item.type == 'kitchen'" %}
Kitchen products:
{% for product in kitchen_products %}
- {{ product.title }}
{% endfor %}
```
Output
```text
All products:
- Vacuum
- Spatula
- Television
- Garlic press
Kitchen products:
- Spatula
- Garlic press
```
[truthy]: ../tutorials/truthy-and-falsy.html
+1 -1
View File
@@ -12,7 +12,7 @@ LiquidJS 共支持 40+ 个过滤器,可以分为如下几类:
数学 | plus, minus, modulo, times, floor, ceil, round, divided_by, abs, at_least, at_most
字符串 | append, prepend, capitalize, upcase, downcase, strip, lstrip, rstrip, strip_newlines, split, replace, replace_first, replace_last, remove, remove_first, remove_last, truncate, truncatewords
HTML/URI | escape, escape_once, url_encode, url_decode, strip_html, newline_to_br
数组 | slice, map, sort, sort_natural, uniq, where, group_by, group_by_exp, find, find_exp, first, last, join, reverse, concat, compact, size, push, pop, shift, unshift
数组 | slice, map, sort, sort_natural, uniq, where, where_exp, group_by, group_by_exp, find, find_exp, first, last, join, reverse, concat, compact, size, push, pop, shift, unshift
日期 | date
其他 | default, json
+37
View File
@@ -0,0 +1,37 @@
---
title: where_exp
---
{% since %}v10.12.0{% endsince %}
从数组中选择所有表达式值为真的对象。下面的例子中,假设你要从产品列表中筛选出来厨房用品。利用 `where_exp` 可以创建一个只包含 `"type"``"kitchen"` 的列表。
输入
```liquid
All products:
{% for product in products %}
- {{ product.title }}
{% endfor %}
{% assign kitchen_products = products | where_exp: "item", "item.type == 'kitchen'" %}
Kitchen products:
{% for product in kitchen_products %}
- {{ product.title }}
{% endfor %}
```
输出
```text
All products:
- Vacuum
- Spatula
- Television
- Garlic press
Kitchen products:
- Spatula
- Garlic press
```
[truthy]: ../tutorials/truthy-and-falsy.html
@@ -1 +0,0 @@
<table> <tbody> <tr> <td align="center" valign="top" ><a href="https://www.opensense.com/"><img src="https://images.opencollective.com/opensense-inc/bf840ae/logo/256.png?height=100" alt="Opensense Inc."/></a></td> <td align="center" valign="top" ><a href="https://www.11ty.dev/"><img src="https://avatars.githubusercontent.com/u/35147177?v=4?s=100" alt="Eleventy"/></a></td> <td align="center" valign="top" ><a href="http://about.me/peterdehaan"><img src="https://avatars2.githubusercontent.com/u/557895?v=4?s=100" alt="Peter deHaan"/></a></td> <td align="center" valign="top" ><a href="https://opencollective.com/touchless"><img src="https://images.opencollective.com/touchless/273bc74/logo/256.png?height=100" alt="Touchless"/></a></td> <td align="center" valign="top" ><a href="https://www.dropkiq.com/"><img src="https://images.opencollective.com/1bertlol/43a8ea8/logo/256.png?height=100" alt="Adam Darrah"/></a></td> <td align="center" valign="top" ><a href="https://dailycontributors.com/"><img src="https://images.opencollective.com/dailycontributors/3c2e057/logo/256.png?height=100&width=100" alt="Dailycontributors"/></a></td> <td align="center" valign="top" ><a href="https://github.com/coni2k"><img src="https://avatars0.githubusercontent.com/u/1284601?v=4?s=100" alt="coni2k"/></a></td> <td align="center" valign="top" ><a href="https://github.com/amit777"><img src="https://avatars0.githubusercontent.com/u/2703309?v=4?s=100" alt="amit777"/></a></td> <td align="center" valign="top" ><a href="https://opencollective.com/khaled-salem"><img src="https://images.opencollective.com/khaled-salem/avatar/256.png?height=256" alt="Khaled Salem"/></a></td> <td align="center" valign="top" ><a href="https://sentry.io/"><img src="https://avatars.githubusercontent.com/u/1396951?v=4?s=100" alt="Sentry"/></a></td> <td align="center" valign="top" ><a href="https://www.checkoutblocks.com/"><img src="https://avatars.githubusercontent.com/u/114603307?v=4?s=100" alt="Checkout Blocks"/></a></td> </tr> </tbody></table>
+10
View File
@@ -102,6 +102,16 @@ export function * where<T extends object> (this: FilterImpl, arr: T[], property:
})
}
export function * where_exp<T extends object> (this: FilterImpl, arr: T[], itemName: string, exp: string): IterableIterator<unknown> {
const filtered: unknown[] = []
const keyTemplate = new Value(stringify(exp), this.liquid)
for (const item of toArray(arr)) {
const value = yield keyTemplate.value(new Context({ [itemName]: item }))
if (value) filtered.push(item)
}
return filtered
}
export function * group_by<T extends object> (arr: T[], property: string): IterableIterator<unknown> {
const map = new Map()
arr = toArray(arr)
+2 -1
View File
@@ -1,4 +1,5 @@
import { ValueToken, Liquid, toValue, evalToken, Value, Emitter, TagToken, TopLevelToken, Context, Template, Tag, ParseStream } from '..'
import { equals } from '../render'
export default class extends Tag {
value: Value
@@ -58,7 +59,7 @@ export default class extends Tag {
for (const branch of this.branches) {
for (const valueToken of branch.values) {
const value = yield evalToken(valueToken, ctx, ctx.opts.lenientIf)
if (target === value) {
if (equals(target, value)) {
yield r.renderTemplates(branch.templates, ctx, emitter)
branchHit = true
break
+22
View File
@@ -476,6 +476,28 @@ describe('filters/array', function () {
`)
})
})
describe('where_exp', function () {
const products = [
{ title: 'Vacuum', type: 'living room' },
{ title: 'Spatula', type: 'kitchen' },
{ title: 'Television', type: 'living room' },
{ title: 'Garlic press', type: 'kitchen' },
{ title: 'Coffee mug', available: true },
{ title: 'Limited edition sneakers', available: false },
{ title: 'Boring sneakers', available: true }
]
it('should support filter by exp', function () {
return test(`{% assign kitchen_products = products | where_exp: "item", "item.type == 'kitchen'" %}
Kitchen products:
{% for product in kitchen_products -%}
- {{ product.title }}
{% endfor %}`, { products }, `
Kitchen products:
- Spatula
- Garlic press
`)
})
})
describe('group_by', function () {
const members = [
{ graduation_year: 2003, name: 'Jay' },
+13
View File
@@ -119,4 +119,17 @@ describe('tags/case', function () {
'{%- endcase %}', {})
expect(result).toEqual('show this')
})
it('should apply value equal for arrays', () => {
const engine = new Liquid()
const result = engine.parseAndRenderSync(`
{%- assign x = "a,b,c" | split: "," %}
{%- assign y = "a,b,c" | split: "," %}
{% case x %}{% when y %}TRUE{% else %}FALSE{% endcase %}
{% if x == y %}TRUE{% else %}FALSE{% endif %}
`)
expect(result).toEqual(`
TRUE
TRUE
`)
})
})