【问题标题】:How can I get a longer automatic excerpt in Jekyll?如何在 Jekyll 中获得更长的自动摘录?
【发布时间】:2013-12-18 18:24:24
【问题描述】:

目前,我包括这样的摘录:

{{ post.excerpt | strip_html }}

但这似乎只给出了第一段。但我想得到固定数量的单词。

或者更好:我想定义最大字符数并获得这么多的单词

  • 字符数小于最大值
  • 多一个字会超过最大字符数

有没有办法用 Jekyll (1.3.1) 做到这一点?

编辑:<!-- more --> 不是答案!我认为摘录应该自动进行,我的帖子应该只包含绝对必要的标记。

【问题讨论】:

标签: jekyll liquid


【解决方案1】:

以下给出一个75字的自动摘录:

{{ post.content | strip_html | truncatewords:75 }}

【讨论】:

    【解决方案2】:

    其实<!-- more --> 就是答案。至少,它现在运行良好。

    1. 将此行添加到您的 _config.yml:

      excerpt_separator: "<!-- more -->"

    2. 然后将其添加到您网站中的每个帖子中:

      <!-- more -->

    希望它会有所帮助。

    【讨论】:

      猜你喜欢
      • 2013-10-23
      • 2018-04-10
      • 2018-02-14
      • 1970-01-01
      • 1970-01-01
      • 2023-03-06
      • 1970-01-01
      • 2013-05-01
      • 2017-03-24
      相关资源
      最近更新 更多