西庐草堂

姑妄言之姑听之,豆棚瓜架雨如丝,料应厌作人间语,爱听秋坟鬼唱诗。

0%

Octopress中Disqus设置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# hexoblog

1. hexo init [folder]

2. hexo new [layout] <title>

3. hexo generate
-d
-w
-b
-f
-c
4. hexo publish [layout] <filename>

5. hexo server

6. hexo deploy

1
2
3
4

# 配置用户名和邮箱
git config --global user.name "github 用户名"
git config --global user.email "github 注册邮箱"
1
2
# 生成 ssh 密钥
ssh-keygen -t rsa -C "github 注册邮箱"

一般执行上述命令之后,会生成 id_rsa 和 id_rsa.pub 两个文件,前者是我们私有的,而后者则是对外开放的。接着找到生成的 .ssh 的文件夹中的 id_rsa.pub 密钥,将内容复制;
然后打开 GitHub-Settings-SSH and GPG Keys 页面,创建一个新的 SSH key,填写 Title 和 Key,Title 可以随意,而 Key 的内容则是我们刚才复制的 id_rsa.pub 中的内容,最后点击 Add SSH key 即可;

– 让 disqus显示出来

特意为Disqus写一篇,是因为过程中出现了错误,或者说我没有理解透别人说的意思。

网上大多数的教程很简单,说是在Disqus注册个账号,然后把 short_name 写入 _config.yml中,我是菜鸟,写入了还是不能显示出来。

就是上图中画红色圈方框的部分没显示。

擦!
连续查了两天资料,终于搞定。

  1. disqus注册时,Shortname 随意写,Website Name 随意写, Website URL: 写入你的网站地址,如果你使用的github,那就写入你的Page Site: ***.github.com

  2. 如果还是出不来,请检查这两个文件。 /Source/_layout/page.html 和 /Source/_layout/post.html, 查看这部分:

    1
    2
    3
    4
       <section id="comment">  
    <h1 class="title">Comments</h1>
    <div id="disqus_thread" aria-live="polite">{% include post/disqus_thread.html %} </div>
    </section>

然后查看 _includes/post/disqus_thread.html 这个里面的内容,如果仅仅是下面这个部分,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
    <noscript>Please enable JavaScript to view the <a href="http://disqus.com/? ref_noscript">comments powered by Disqus.</a></noscript>
```
那就说明,该修改 section 这部分代码了。

查看 _includes/disqus.html 文件,查看源码,如果如下:
```javascript
{% comment %} Load script if disquss comments are enabled and `page.comments`
is either empty (index) or set to true {% endcomment %}
{% if site.disqus_short_name and page.comments != false %}
<script type="text/javascript">
var disqus_shortname = '{{ site.disqus_short_name }}';
{% if page.comments == true %}
{% comment %} `page.comments` can be only be set to true on pages/posts, so we embed the comments here. {% endcomment %}
// var disqus_developer = 1;
var disqus_identifier = '{{ site.url }}{{ page.url }}';
var disqus_url = '{{ site.url }}{{ page.url }}';
var disqus_script = 'embed.js';
{% else %}
{% comment %} As `page.comments` is empty, we must be on the index page. {% endcomment %}
var disqus_script = 'count.js';
{% endif %}
(function () {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = 'http://' + disqus_shortname + '.disqus.com/' + disqus_script;
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
}());
</script>
{% endif %}

请修改 section 中的代码为:

1
2
3
4
   <section id="comment">
<h1 class="title">Comments</h1>
<div id="disqus_thread" aria-live="polite">{% include disqus.html %} </div>
</section>

然后 rake generate ; rake deploy 查看页面了。


欢迎关注我的其它发布渠道