【发布时间】:2014-10-26 21:35:56
【问题描述】:
这是我目前用来查看博客文章是否超过 120 字的代码 sn-p。如果为真,请截断内容并在帖子底部添加“阅读更多”链接。
<div class="blogs">
{% for post in site.posts %}
<article class="post">
<h3><a href="{{ site.baseurl }}/{{ site.blogs }}{{ post.title }}">{{ post.title }}</a></h3>
{% assign wordCount = {{ post.content | size }} %}
{% if wordCount > 120 %}
<div class="entry">
{{ post.content | truncatewords:120}}
</div>
<a href="{{ site.baseurl }}{{ post.url}}" class="read-more">Read More</a>
{% else %}
{{ post.content }}
{% endif %}
</article>
{% endfor %}
</div>
当我提交此操作时,我收到一封来自 GitHub 的电子邮件,说构建时出现页面错误,并且没有打印出任何其他内容。
我猜这与{{ post.content }} 无法过滤掉大小有关,所以我被卡住了。
如何获取单个博客文章的字数,以便截断一些超过 120 字的文章?提前致谢。
【问题讨论】:
标签: html github jekyll liquid github-pages