-
-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: array_to_sentence_string and number_of_words filters from Jekyll,
- Loading branch information
Showing
9 changed files
with
303 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
title: array_to_sentence_string | ||
--- | ||
|
||
{% since %}v10.13.0{% endsince %} | ||
|
||
Convert an array into a sentence. Useful for listing tags. Optional argument for connector. | ||
|
||
Input | ||
```liquid | ||
{{ "foo,bar,baz" | split: "," | array_to_sentence_string }} | ||
``` | ||
|
||
Output | ||
```text | ||
foo, bar, and baz | ||
``` | ||
|
||
Input | ||
```liquid | ||
{{ "foo,bar,baz" | split: "," | array_to_sentence_string: "or" }} | ||
``` | ||
|
||
Output | ||
```text | ||
foo, bar, or baz | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--- | ||
title: number_of_words | ||
--- | ||
|
||
{% since %}v10.13.0{% endsince %} | ||
|
||
Count the number of words in some text. This filter takes an optional argument to control the handling of Chinese-Japanese-Korean (CJK) characters in the input string: | ||
- Passing `'cjk'` as the argument will count every CJK character detected as one word irrespective of being separated by whitespace. | ||
- Passing `'auto'` (auto-detect) works similar to `'cjk'` but is more performant if the filter is used on a variable string that may or may not contain CJK chars. | ||
|
||
Input | ||
```liquid | ||
{{ "Hello world!" | number_of_words }} | ||
``` | ||
|
||
Output | ||
```text | ||
2 | ||
``` | ||
|
||
Input | ||
```liquid | ||
{{ "你好hello世界world" | number_of_words }} | ||
``` | ||
|
||
Output | ||
```text | ||
1 | ||
``` | ||
|
||
Input | ||
```liquid | ||
{{ "你好hello世界world" | number_of_words: "cjk" }} | ||
``` | ||
|
||
Output | ||
```text | ||
6 | ||
``` | ||
|
||
Input | ||
```liquid | ||
{{ "你好hello世界world" | number_of_words: "auto" }} | ||
``` | ||
|
||
Output | ||
```text | ||
6 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
title: array_to_sentence_string | ||
--- | ||
|
||
{% since %}v10.13.0{% endsince %} | ||
|
||
把数组转化为句子,用于做标签列表。有一个可选的连接词参数。 | ||
|
||
输入 | ||
```liquid | ||
{{ "foo,bar,baz" | split: "," | array_to_sentence_string }} | ||
``` | ||
|
||
输出 | ||
```text | ||
foo, bar, and baz | ||
``` | ||
|
||
输入 | ||
```liquid | ||
{{ "foo,bar,baz" | split: "," | array_to_sentence_string: "or" }} | ||
``` | ||
|
||
输出 | ||
```text | ||
foo, bar, or baz | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--- | ||
title: number_of_words | ||
--- | ||
|
||
{% since %}v10.13.0{% endsince %} | ||
|
||
计算文本中的单词数。此过滤器接受一个可选参数,用于控制输入字符串中汉字-日语-韩语(CJK)字符的处理方式: | ||
- `'cjk'`:将每个检测到的 CJK 字符计为一个单词,无论是否由空格分隔。 | ||
- `'auto'`:与 `'cjk'` 类似,但如果过滤器用于可能包含或不包含 CJK 字符的字符串,则性能更好。 | ||
|
||
输入 | ||
```liquid | ||
{{ "Hello world!" | number_of_words }} | ||
``` | ||
|
||
输出 | ||
```text | ||
2 | ||
``` | ||
|
||
输入 | ||
```liquid | ||
{{ "你好hello世界world" | number_of_words }} | ||
``` | ||
|
||
输出 | ||
```text | ||
1 | ||
``` | ||
|
||
输入 | ||
```liquid | ||
{{ "你好hello世界world" | number_of_words: "cjk" }} | ||
``` | ||
|
||
输出 | ||
```text | ||
6 | ||
``` | ||
|
||
输入 | ||
```liquid | ||
{{ "你好hello世界world" | number_of_words: "auto" }} | ||
``` | ||
|
||
输出 | ||
```text | ||
6 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters