热门搜索 :
考研考公
您的当前位置:首页正文

Jekyll搭建博客并添加百度统计

来源:东饰资讯网

自己的是在gitpage上用Jekyll搭建起来的,使用的是。搭建以后一直是在github上build的,也没有添加点击统计的工具。下面介绍一下自己完成这本地build和添加百度统计的过程和遇到的问题。

可以在我的博客交流更多相关内容。


添加百度统计

<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = 
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>

需要将这段代码添加到网站全部页面的head标签前。对于Jekyll的网站来说可以通过以下三个步骤来实现:

  • 修改_config.yml,加入
baidu-analysis: xxxxxxxxxxxxxxxxxxxxxxxxxxx
  • 在_include中新建文件baidu-anaylysis.html加入以下代码
<script>
  var _hmt = _hmt || [];
  (function() {
    var hm = document.createElement("script");
    hm.src =  site.baidu-analyisis }}";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
  })();
</script>
  • 在博客的入口网页中添加
{% include baidu-analysis.html %}

Jekyll的入口一般在 _layouts/default.html中。我的模版因为将header统一抽取了出来,加在了_includes/head.html中。

  • 在百度统计的网站中心tab中检查首页代码状态,显示代码安装正确,就成功了。

本地build Jekyll

gem install bundler
bundle install
bundle exec jekyll serve

注意在config_yml中不能有tab,否则会提示‘found character that cannot start any token while scanning for the next token at line’的错误。

Top