Jekyll:Liquid备忘
escape
行内代码和代码块的情况完全一致
{%assign abc='abc'|slice:1%}
{%assign abc='abc'|slice:1%}
{%assign abc='abc'|slice:1%}✓
\
{\%assign abc='abc'|slice:1%}
{{'abc'|slice:1}}
{{'abc'|slice:1}}
{{'abc'|slice:1}}✓
\b
{\{'abc'|slice:1}}
正文段落和blockquote则情况完全一致,比代码块多几种可用写法
{%assign abc=’abc’|slice:1%} {%assign abc=’abc’|slice:1%}✓ {%assign abc=’abc’|slice:1%}✓
{\%assign abc=’abc’|slice:1%}{{‘abc’|slice:1}} {{‘abc’|slice:1}}✓ {{‘abc’|slice:1}}✓ \b {{‘abc’|slice:1}}✓
其实正文、片段引用中不必带起止括号,去掉起止括号就简洁多了。 奇怪的还有,第二部分的引号都被“smart quote”识别转换了, 第一部分却全都没有。 猜测可能引号前面有等号就不会转换?这方面暂不必要进一步确认了。
Handles、Filters
和JS中“函数”对应的概念, 在Liquid中是“handle”和“filter”,这样命名符合“模板语言”。
Handle
Filter
数字
round
、abs
等数字操作只支持|
一种写法
5|round |
5.round |
5[round] |
5['round'] |
5["round"] |
5 | × | × | × | × |
assign a=5.5
a|round |
a.round |
a[round] |
a['round'] |
a["round"] |
6 | × | × | × | × |
文本
assign a='abc'
a|upcase |
a.upcase |
a[upcase] |
a['upcase'] |
a["upcase"] |
ABC | × | × | × | × |
size
size
则可以|
、.
两种写法
assign abc='abcde'
abc|size |
abc.size |
abc[size] |
abc['size'] |
abc["size"] |
5 | 5 | × | × | × |
assign abc='abc,de,fg'|split:','
abc|size |
abc.size |
abc[size] |
abc['size'] |
abc["size"] |
3 | 3 | × | × | × |
size和slice
从文档看,有部分filter是同时支持string和array的,
如array下的size
也支持string,
Returns the size of a string or array.(文档)
string下的slice
则也支持array
Returns a substring or series of array items, starting at a given 0-based index.(文档)
但并不是所有filter都通用,或者也不是想当然的都通用,只以文档为准。
文档中,slice是string下唯一同时支持array的,array下未专门确认。
经过测试,'abc'|first
没有输出,'bac'|sort
会导致Jekyll build失败。
(Jekyll文档中,sort有特别处理,区别于原本的Liquid filter。)
array的filters支持.
,string的则不支持。
文档也是这样写的没错,但为什么会有这种差异,似乎并没逻辑,
也没有讲解讨论,只以文档为准。
扩展一组
abc.[size] |
abc.['size'] |
abc.["size"] |
× | × | × |
匿名值,和数字一样,只支持|
一种写法
'abc'|size |
'abc'.size |
'abc'[size] |
'abc'['size'] |
'abc'["size"] |
3 | abc× | abc× | abc× | abc× |
join
abcdefg|join:',' ✓ |
abcdefg.join:',' × |
concat
abc,de,fg,hijk,lmn,abc,de,fg,hijk,lmn
slice
b
map
、、、、 自检.md、assets/css/style.scss、assets/minima-social-icons.liquid、2023-08-18-13-23-08.md、2023-08-19-10-50-29.md、2023-08-20-11-58-27.md、2023-08-20-13-53-03.md、2023-08-20-16-04-31.md、2023-08-21-04-00-40.md、2023-08-23-00-32-16.md、2023-08-23-05-11-57.md、2023-08-24-06-48-44.md、2023-09-06-04-33-44.md、2023-09-06-22-51-23.md、2023-09-09-15-46-57.md、2023-09-12-03-52-22.md、2023-09-12-14-55-40.md、2023-09-13-10-04-43.md、2023-09-14-12-45-41.md、2023-09-15-02-49-10.md、2023-09-16-11-32-55.md、2023-09-17-13-25-11.md、2023-09-18-13-05-06.md、2023-09-20-01-28-11.md、2023-09-20-13-33-22.md、2023-09-20-19-12-05.md、2023-09-23-15-37-23.md、2023-09-23-16-40-16.md、2023-09-24-17-42-53.md、2023-09-25-19-18-22.md、2023-09-25-23-21-45.md、2023-09-26-17-27-24.md、23-8-25-体征崇拜.md、实体增多.md、标记.md、README.md
1.31.41.51.6 | 1.3 | 2 |
1.31.41.51.6 | 1.3 | 1 |
if/unless
只支持“.”,不支持“|”,间接说明只支持get()
,不支持传参;
“contains”则是关键字,不加“.”也不加“|”。
if a.categories|size<=1 × |
if a.categories.size<=1 ✓ |
if a.slug|contains:':' × |
if a.slug contains':' ✓ |
abcmd
md
md× 1×
× ×
× ×
× ×
contains
if 'abcde' contains 'e'
tif 'abcde' contains 'f'
f
assign abcde='abcde'
if abcde contains'e'
tif abcde contains'f'
f
以下全部是错误语法,会产生错误结果,但不会报错
if abcde.contains'e'
fif abcde.contains'f'
fif abcde|contains'e'
tif abcde|contains'f'
tif abcde|contains:'e'
tif abcde|contains:'f'
t