【问题标题】:'data:post-snippet' truncation in blogger博客中的“数据:post-snippet”截断
【发布时间】:2015-03-29 02:47:03
【问题描述】:

假设我在 Blogger 上写了这样一篇文章: abc def ghi

jkl mno pqr stu vwxyz

我希望 Blogger 仅将其 data:post.sn-p 设置为“abc def ghi”,而不是从 a 到 z 列出(让 Blogger 知道在读取令牌时停止:具有类“pls-”的 div排除-从-sn-p')。我该怎么做?

【问题讨论】:

  • 在不说明原因的情况下投反对票... sigh

标签: html post blogger code-snippets truncate


【解决方案1】:

我在这里找到了帮助 https://productforums.google.com/forum/#!topic/blogger/X9LxrjXnb2s

仍然需要稍微调整一下,但它可以工作。想把它贴出来帮助和我有类似问题的人。

这是我的代码。在</head>之前,添加:

<script type='text/javascript'> //<![CDATA[ function stopIfFound(strx,token){ var theLocation = strx.indexOf(token); if(theLocation!=-1){ strx = strx.substr(0,theLocation); } return strx; } function removeHtmlTag(strx, chop){ strx = stopIfFound(strx,'<div class="pls-exclude-from-snippet">'); if(strx.indexOf("<")!=-1){ var snippet = strx.split("<"); for(var i=0;i<snippet.length;i++){ if(snippet[i].indexOf(">")!=-1){ snippet[i] = snippet[i].substring(snippet[i].indexOf(">")+1,snippet[i].length); } } strx = snippet.join(""); } chop = (chop < strx.length-1) ? chop : strx.length-2; while(strx.charAt(chop-1)!=' ' && strx.indexOf(' ',chop)!=-1) chop++; strx = strx.substring(0,chop-1); return strx+'...'; } function createSnippet(pID){ var div = document.getElementById(pID); var summ = snippet_count; var summary = '<div class="snippets">' + removeHtmlTag(div.innerHTML,summ) + '</div>'; div.innerHTML = summary; } //]]> </script>

找到&lt;data:post.snippet/&gt;,在

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

替换为

<div expr:id='&quot;summary&quot; + data:post.id'><data:post.body/></div>
<script type='text/javascript'>createSnippet(&quot;summary<data:post.id/>&quot;);  
  </script>

【讨论】:

    【解决方案2】:

    您可以尝试限制字符的长度。

    使用这个语法:

    <b:eval expr='snippet(data:post.body, {length: 150})' />
    

    150 是长度。您可以将其更改为您想要的任何数字。

    查看我的个人博客change snippet length on Blogger without Javascript 以查看更多示例。

    【讨论】:

    • 欢迎来到Stack Overflow!您的答案似乎与该网站有关联。虽然我们感谢您的回答,但我们的政策要求您披露您的隶属关系。您介意将其添加到您的答案中吗?谢谢
    • 我已经添加了。我做对了吗?或者我需要删除链接?
    • 是的。干得好。如果您包含从属关系的披露,您可以在您的答案中包含指向您自己网站的链接。干杯!
    猜你喜欢
    • 2020-11-22
    • 1970-01-01
    • 1970-01-01
    • 2021-09-17
    • 2017-01-27
    • 2011-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多