Jekyll max摘录长度

Eth*_*han 2 liquid jekyll

我试图获取我的帖子的摘录,作为我页面上的描述元标记.有没有办法将摘录字符限制为156?

这是我目前的代码:

{{ page.excerpt | strip_html | strip_newlines}}
Run Code Online (Sandbox Code Playgroud)

mar*_*nuy 5

使用truncate过滤器:

{{ page.excerpt | strip_html | strip_newlines | truncate: 156 }}  
Run Code Online (Sandbox Code Playgroud)

  • 对于任何通过Google找到它的人,您可能还想了解`truncatewords`过滤器,该过滤器会根据字数而不是字符数截断。如果您不希望摘录以单词结尾结尾,那就太好了。https://shopify.github.io/liquid/filters/truncatewords/ (2认同)