【问题标题】:Get the read time for a specific post in Jekyll Pages from home page/ any other page从主页/任何其他页面获取 Jekyll Pages 中特定帖子的阅读时间
【发布时间】:2020-06-18 19:17:07
【问题描述】:

我是 Liquid 和 Jekyll 的新手,使用下面的代码来计算帖子页面上的帖子阅读时间。但是我应该如何计算主页或任何其他页面上的阅读时间以将其显示在帖子标题下方?

当我也在主页上使用相同的代码时,我会在主页和特定帖子中获得不同的阅读时间。

我想我无法获取该帖子的上下文来计算其他页面上的字数。请提出建议。

<span class="reading-time" title="Estimated read time">
  {% assign words = content | number_of_words %}
  {% if words < 360 %}
    1 min
  {% else %}
    {{ words | divided_by:180 }} mins
  {% endif %}
</span>

【问题讨论】:

    标签: jekyll github-pages liquid jekyll-theme


    【解决方案1】:

    这可能是因为在主页上,您也有一些 HTML 格式的页面。

    严格来说,您确实应该在计算字数之前从内容中去除 HTML,以获得准确的阅读时间。

    因此,使用strip_html filter 可能是一个解决方案:

    {% assign words = content | strip_html | number_of_words %}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-17
      • 2021-07-27
      • 1970-01-01
      • 2013-01-06
      • 1970-01-01
      • 2016-01-27
      • 2017-08-28
      相关资源
      最近更新 更多