自己的這個博客是在gitpage上用Jekyll搭建起來的,使用的是這個模版。搭建以后一直是在github上build的,也沒有添加點擊統(tǒng)計的工具。下面介紹一下自己完成這本地build和添加百度統(tǒng)計的過程和遇到的問題。
可以在我的博客http://haiyangjiajian.com/交流更多相關(guān)內(nèi)容。
添加百度統(tǒng)計
現(xiàn)在有很多站長工具可以統(tǒng)計網(wǎng)站的點擊量。添加方式大同小異。我添加的是百度統(tǒng)計。注冊添加后,會得到如下一段javaScript:
<script>
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "http://hm.baidu.com/hm.js?xxxxxxxxxxxxxxxxxxxxxxxxxxx";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script>
需要將這段代碼添加到網(wǎng)站全部頁面的head標(biāo)簽前。對于Jekyll的網(wǎng)站來說可以通過以下三個步驟來實現(xiàn):
- 修改_config.yml,加入
baidu-analysis: xxxxxxxxxxxxxxxxxxxxxxxxxxx
- 在_include中新建文件baidu-anaylysis.html加入以下代碼
<script>
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "http://hm.baidu.com/hm.js?{{ site.baidu-analyisis }}";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script>
- 在博客的入口網(wǎng)頁中添加
{% include baidu-analysis.html %}
Jekyll的入口一般在 _layouts/default.html中。我的模版因為將header統(tǒng)一抽取了出來,加在了_includes/head.html中。
- 在百度統(tǒng)計的網(wǎng)站中心tab中檢查首頁代碼狀態(tài),顯示代碼安裝正確,就成功了。
本地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’的錯誤。
本地server啟動后可以在http://localhost:4000/ 訪問