解决Octopress访问慢和一些设置问题

When我刚搭建好Octopress的时候,O(∩_∩)O~心情挺好的,感觉棒棒哒。

And我点击Command+R刷新页面的时候,尼玛我脸都绿了。。。。由于GFW的原因,造成页面load很慢,从Console窗口可以看出主要就是Google的各种服务被墙了。。。

What the hell!

==================================================================== 好吧,结素,开始正题!

内容来自各大大的blog,由破船之家技术小黑屋

1、初级问题

首先打开:_config.yml

我一狠心将Github,Twitter,Google +1, Google Plus, Pinboard, Delicious, Disqus, Google analytics, Facebook一律封杀了......艾玛,好残忍⇀ ⇀

全部前面加#注释了

2、关键问题

Octopress很多依赖于Google的库和资源,So,google拜拜~~~~(>_<)~~~~

对于使用Google Analytics来说,加在ga.js这个文件简直是要命的慢,这里我使用自己存放在七牛CDN上的js.http://droidyue-tools.qiniudn.com/ga.js 已验证,完全可以正常收集数据。 参考如下,修改source/_includes/google_analytics.html

1
2
3
4
5
6
7
8
 __gaq.push(['_trackPageview']);

 (function() {
 var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
 ga.src='http://droidyue-tools.qiniudn.com/ga.js';
 var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
 })();
   </script>

解决fonts.googleapis.com蜗牛慢

这里我们使用数字公司提供的Google Fonts大陆解决方案,使用fonts.useso.com替换fonts.googleapis.com
修改文件/source/_includes/custom/head.html

1
2
3
 <!--Fonts from Google"s Web font directory at http://google.com/webfonts -->
<link href="http://fonts.useso.com/css?family=PT+Serif:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
<link href="http://fonts.useso.com/css?family=PT+Sans:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">

解决ajax.googleapis.com慢的问题

修改source/_includes/head.html

1
2
3
4
5
6
   <link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
   <link href="/atom.xml" rel="alternate" title="技术小黑屋" type="application/atom+xml">
   <script src="/javascripts/modernizr-2.0.js"></script>
   <script src="//ajax.useso.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
   <script>!window.jQuery && document.write(unescape('%3Cscript src="./javascripts/lib/jquery.min.js"%3E%3C/script%3E'))</script>
   <script src="/javascripts/octopress.js" type="text/javascript"></script>

好了,到此的话就可以了,基本上访问慢得问题解决了,现在我们来添加评论功能,评论我们用< a href="http://duoshuo.com/">多说

添加评论

进入多说官网,注册账号

在_config.yml文件添加

1
2
3
# duoshuo comments
duoshuo_comments: true
duoshuo_short_name: yourname

source/_layouts/post.html中添加多说评论模块

1
2
3
4
5
6
{% if site.duoshuo_short_name and site.duoshuo_comments == true and page.comments == true %}
  <section>
    <h1>Comments</h1>
    <div id="comments" aria-live="polite">{% include post/duoshuo1.html %}</div>
  </section>
{% endif %}

创建source/_includes/post/duoshuo.html,并填入如下内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14

<!-- Duoshuo Comment BEGIN -->
<div class="ds-thread"></div>
<script type="text/javascript">
  var duoshuoQuery = {short_name:"beyondvincent"};
  (function() {
    var ds = document.createElement('script');
    ds.type = 'text/javascript';ds.async = true;
    ds.src = 'http://static.duoshuo.com/embed.js';
    ds.charset = 'UTF-8';
    (document.getElementsByTagName('head')[0] 
    || document.getElementsByTagName('body')[0]).appendChild(ds);
  })();
</script>
<!-- Duoshuo Comment END -->

发布到站点

1
2
3
4
5

$ rake generate
$ git add .
$ git commit -am "添加多说评论" 
$ git push origin source
$ rake deploy

百度统计

从百度统计获取脚本,然后添加到文件source/_includes/after_footer.html文件