【问题标题】:Truncate a post.excerpt截断post.excerpt
【发布时间】: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>
    <% } %>

【问题讨论】:

标签: html markdown ejs hexo


【解决方案1】:

不是将内容截断为摘录, 试试这个

 `<section class="article typo">
      <%- post.content | truncatewords: 25 %>
      <div class="readmore">
      <a href="<%- url_for(post.path) %>">Read More</a>
    </div>
    <% } %>`

【讨论】:

猜你喜欢
  • 2023-03-13
  • 2012-06-02
  • 2016-07-15
  • 2023-03-31
  • 2018-10-12
  • 2018-06-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多