Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
502 views
in Technique[技术] by (71.8m points)

javascript - How to increase character lengh in blogger snippet instead of using limited length, 'data:post.snippet'?

I'm currently using 'data:post.snippet' for blogger mobile snippet.

<div class='post-body' style='color:black;'>
  <b:if cond='data:post.snippet'><data:post.snippet/></b:if>
</div>

But its character length(140) is too low, and it doesn't give a line break between the headings and paragraphs. When there's a heading at the very start line break is necessary. Can someone please suggest me a javascript code to replace above code to overcome those two issues.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can utilize the data:post.longSnippet data tag which has the limit of upto 300-400 character

<div class='post-body' style='color:black;'>
    <b:if cond='data:post.snippet'><data:post.longSnippet/></b:if>
</div>

Otherwise, if you want to control the exact amount of text that you want to be visible in the snippet, then you can utilize the newly launched operator in the 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...