【问题标题】:Jekyll max excerpt lengthJekyll 最大摘录长度
【发布时间】:2018-04-10 07:12:55
【问题描述】:

我正在尝试摘录我的帖子作为我页面上的描述元标记。有什么办法可以将摘录字符限制为 156 个?

这是我当前的代码:

{{ page.excerpt | strip_html | strip_newlines}}

【问题讨论】:

    标签: jekyll liquid


    【解决方案1】:

    使用truncate 过滤器:

    {{ page.excerpt | strip_html | strip_newlines | truncate: 156 }}  
    

    【讨论】:

    • 对于通过 Google 找到此内容的任何人,您可能还想了解 truncatewords 过滤器,它按字数而不是字符数截断。如果你不希望你的摘录在一个单词的中间结束,那就太好了。 shopify.github.io/liquid/filters/truncatewords
    猜你喜欢
    • 2016-05-06
    • 1970-01-01
    • 2013-12-18
    • 2016-06-12
    • 2011-05-04
    • 1970-01-01
    • 1970-01-01
    • 2015-07-18
    相关资源
    最近更新 更多