我目前正在使用“data:post.snippet”作为博客移动代码片段。
<div class='post-body' style='color:black;'>
<b:if cond='data:post.snippet'><data:post.snippet/></b:if>
</div>
但是它的字符长度(140)太低了,标题和段落之间没有换行符。当在最开始有一个标题时,换行符是必要的。有人可以向我推荐一个 javascript 代码来替换上面的代码以解决这两个问题。
最佳答案
您可以使用 data:post.longSnippet
数据标签,它有 300-400 个字符的限制
<div class='post-body' style='color:black;'>
<b:if cond='data:post.snippet'><data:post.longSnippet/></b:if>
</div>
否则,如果您想控制要在代码段中显示的文本的确切数量,则可以在 new themes 中使用新推出的运算符。
<div class='post-body' style='color:black;'>
<b:eval expr='snippet(data:post.body, {length: 450, links: false})' />
</div>
snippet(string, options)
Produces a short snippet from an HTML string.
options: Object specifying the snippeting options, which are:
links: boolean for whether to preserve anchors/links in the snippet. Defaults to true.
linebreaks: boolean for whether to preserve linebreaks (tags) in the snippet. Defaults to true.
ellipsis: boolean for whether to append an ellipsis (…) to the end of the snippet. Defaults to true.
length: Number specifying the maximum length of the snippet.
关于javascript - 如何增加博客片段中的字符长度而不是使用有限的长度 'data:post.snippet' ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34963026/