【发布时间】:2017-08-05 13:15:22
【问题描述】:
我正在尝试截断post.excerpt。
实际代码是<%- post.excerpt || post.content%>
上面显示了一篇博文的所有介绍文本。
现在我想将介绍文本截断为 25 个字符的长度。
截断代码如本例所示:
<%- truncate('And they found that many people were sleeping better.', {length: 25, omission: '... (continued)'}) %>`
现在结合起来,我想出了:
<%- truncate((post.excerpt), {length: 25, omission: '... (continued)'}) || post.content%>
但这不起作用,如何根据我的需要进行截断?
完整代码在这里...
<section class="article typo">
<%- post.excerpt || post.content %>
<% if (post.excerpt) { %>
<div class="readmore">
<a href="<%- url_for(post.path) %>">Read More</a>
</div>
<% } %>
【问题讨论】:
-
截断 Markdown 比计算字符复杂得多。请参阅Markdown: how to show a preview (such as the first N words),了解获得有意义结果所需步骤的与语言无关的细分。