hexo-html-truncate
-- A Hexo plugin to truncate html by only counting word filtering out html tags
Install
npm install hexo-html-truncate --save
Options
Default Options
{
byWords: false,
stripTags: false,
ellipsis: '...',
decodeEntities: false,
keepWhitespaces: false,
excludes: '',
reserveLastWord: false,
keepWhitespaces: false
}
Usage
htmlTruncate(content, length, options);
Swig
<div class="content">
{{ htmlTruncate(post.content, 100, {
ellipsis: '...',
excludes: ['img'],
keepWhitespaces: true,
reserveLastWord: true
}) }}
</div>
Ejs
<div class="content">
<%- htmlTruncate(post.content, 100, {
ellipsis: '...',
excludes: ['img'],
keepWhitespaces: true,
reserveLastWord: true
}) %>
</div>
Jade
span.post-count= htmlTruncate(post.content, 100, {
ellipsis: '...',
excludes: ['img'],
keepWhitespaces: true,
reserveLastWord: true
})
License
MIT
Reference/Source
Base on the package mehwww/vue-sticky-directive, this package just compiled the package into a hexo plugin for easier use in hexo.