如何在博客回复中添加ref =“nofollow”并删除评论链接

时间:2016-06-19 17:05:39

标签: javascript blogger blogspot

我在我的博文中使用了seo分析工具http://www.seoptimer.com,发现我的评论删除链接是“dofollow”。现在,我如何在这些链接中添加“nofollow”。

我正在使用博主的嵌入式评论。

Page url:http://www.howbloggerz.com/2016/02/custom-stylish-search-boxes-blogger.html

评论脚本:

 <script type='text/javascript'>
(function() {
  var items = <data:post.commentJso/>;
  var msgs = <data:post.commentMsgs/>;
  var config = <data:post.commentConfig/>;

// <![CDATA[
  var cursor = null;
  if (items && items.length > 0) {
    cursor = parseInt(items[items.length - 1].timestamp) + 1;
  }

  var bodyFromEntry = function(entry) {
    if (entry.gd$extendedProperty) {
      for (var k in entry.gd$extendedProperty) {
        if (entry.gd$extendedProperty[k].name == 'blogger.contentRemoved') {
          return '<span class="deleted-comment">' + entry.content.$t + '</span>';
        }
      }
    }
    return entry.content.$t;
  }

  var parse = function(data) {
    cursor = null;
    var comments = [];
    if (data && data.feed && data.feed.entry) {
      for (var i = 0, entry; entry = data.feed.entry[i]; i++) {
        var comment = {};
        // comment ID, parsed out of the original id format
        var id = /blog-(\d+).post-(\d+)/.exec(entry.id.$t);
        comment.id = id ? id[2] : null;
        comment.body = bodyFromEntry(entry);
        comment.timestamp = Date.parse(entry.published.$t) + '';
        if (entry.author && entry.author.constructor === Array) {
          var auth = entry.author[0];
          if (auth) {
            comment.author = {
              name: (auth.name ? auth.name.$t : undefined),
              profileUrl: (auth.uri ? auth.uri.$t : undefined),
              avatarUrl: (auth.gd$image ? auth.gd$image.src : undefined)
            };
          }
        }
        if (entry.link) {
          if (entry.link[2]) {
            comment.link = comment.permalink = entry.link[2].href;
          }
          if (entry.link[3]) {
            var pid = /.*comments\/default\/(\d+)\?.*/.exec(entry.link[3].href);
            if (pid && pid[1]) {
              comment.parentId = pid[1];
            }
          }
        }
        comment.deleteclass = 'item-control blog-admin';
        if (entry.gd$extendedProperty) {
          for (var k in entry.gd$extendedProperty) {
            if (entry.gd$extendedProperty[k].name == 'blogger.itemClass') {
              comment.deleteclass += ' ' + entry.gd$extendedProperty[k].value;
            } else if (entry.gd$extendedProperty[k].name == 'blogger.displayTime') {
              comment.displayTime = entry.gd$extendedProperty[k].value;
            }
          }
        }
        comments.push(comment);
      }
    }
    return comments;
  };

  var paginator = function(callback) {
    if (hasMore()) {
      var url = config.feed + '?alt=json&v=2&orderby=published&reverse=false&max-results=200';
      if (cursor) {
        url += '&published-min=' + new Date(cursor).toISOString();
      }
      window.bloggercomments = function(data) {
        var parsed = parse(data);
        cursor = parsed.length < 50 ? null
            : parseInt(parsed[parsed.length - 1].timestamp) + 1
        callback(parsed);
        window.bloggercomments = null;
      }
      url += '&callback=bloggercomments';
      var script = document.createElement('script');
      script.type = 'text/javascript';
      script.src = url;
      document.getElementsByTagName('head')[0].appendChild(script);
    }
  };
  var hasMore = function() {
    return !!cursor;
  };
  var getMeta = function(key, comment) {
    if ('iswriter' == key) {
      var matches = !!comment.author
          && comment.author.name == config.authorName
          && comment.author.profileUrl == config.authorUrl;
      return matches ? 'true' : '';
    } else if ('deletelink' == key) {
      return config.baseUri + '/delete-comment.g?blogID='
           + config.blogId + '&postID=' + comment.id;
    } else if ('deleteclass' == key) {
      return comment.deleteclass;
    }
    return '';
  };

  var replybox = null;
  var replyUrlParts = null;
  var replyParent = undefined;

  var onReply = function(commentId, domId) {
    if (replybox == null) {
      // lazily cache replybox, and adjust to suit this style:
      replybox = document.getElementById('comment-editor');
      if (replybox != null) {
        replybox.height = '250px';
        replybox.style.display = 'unset';
        replyUrlParts = replybox.src.split('#');
      }
    }
    if (replybox && (commentId !== replyParent)) {
      document.getElementById(domId).insertBefore (document.getElementById ('threaded-comment-form'), null);
      replybox.src = replyUrlParts[0]
          + (commentId ? '&parentID=' + commentId : '')
          + '#' + replyUrlParts[1];
      replyParent = commentId;
    }
  };

  var hash = (window.location.hash || '#').substring(1);
  var startThread, targetComment;
  if (/^comment-form_/.test(hash)) {
    startThread = hash.substring('comment-form_'.length);
  } else if (/^c[0-9]+$/.test(hash)) {
    targetComment = hash.substring(1);
  }

  // Configure commenting API:
  var configJso = {
    'maxDepth': config.maxThreadDepth
  };
  var provider = {
    'id': config.postId,
    'data': items,
    'loadNext': paginator,
    'hasMore': hasMore,
    'getMeta': getMeta,
    'onReply': onReply,
    'rendered': true,
    'initComment': targetComment,
    'initReplyThread': startThread,
    'config': configJso,
    'messages': msgs
  };

  var render = function() {
    if (window.goog && window.goog.comments) {
      var holder = document.getElementById('comment-holder');
      window.goog.comments.render(holder, provider);
    }
  };

  // render now, or queue to render when library loads:
  if (window.goog && window.goog.comments) {
    render();
  } else {
    window.goog = window.goog || {};
    window.goog.comments = window.goog.comments || {};
    window.goog.comments.loadQueue = window.goog.comments.loadQueue || [];
    window.goog.comments.loadQueue.push(render);
  }
})();

//]]&gt;   

1 个答案:

答案 0 :(得分:0)

您必须在rel="nofollow"代码中添加<a>属性。

这很简单

<a rel="nofollow" href="link here">My Link</a>

专门针对博主

  • 转到模板&gt;编辑HTML&gt;继续。
  • 点击展开小工具模板。
  • 现在按Ctrl + f。

    搜索此代码

    EXPR:HREF =”数据:post.createlinkurl”

现在在上面的代码之后添加rel=”external nofollow”

expr:href='data:post.createlinkurl' rel="external nofollow"

nofollow属性将显示在您博客的评论中。

使用nofollow添加所有外部链接

  • 转到Blogger信息中心&gt;&gt;模板。
  • 点击“编辑HTML”按钮。
  • 按ctrl + f找到标签并输入 搜索框。

现在在标记上方添加以下代码:

<script src='http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js' type='text/javascript'></script>
<script type='text/javascript'>
    var a = $(this);
    var href = a.attr('href');
    $(document).ready(function() {
        $("a[href^='http://']").each(function() {
            if (this.href.indexOf(location.hostname) == -1) {
                $(this).attr('target', '_blank');
                $(this).attr('title', 'Click to open in a new window');
                $(this).attr('rel', 'nofollow');
            }
        });
        $("a[href^='https://']").each(function() {
            if (this.href.indexOf(location.hostname) == -1) {
                $(this).attr('target', '_blank');
                $(this).attr('title', 'Click to open in a new window');
                $(this).attr('rel', 'nofollow');
            }
        });
    });
</script>