hexo搭建博客教程04
Jan 3 , 2017

6、搜索

本文是使用本地搜索
首先要先生成索引数据,然后在_config.yml中配置
1
2
3
4
5
6
//生成索引数据
npm install hexo-generator-search --save
//_config.yml
search:
path: search.xml
field: post
在页面添加搜索按钮及搜索结果页面
添加搜索函数及搜索按钮触发事件,搜索函数来源于HaHack

7、评论

评论用的比较多的是disqus多说,不过disqus需要翻墙才能使用

多说评论

注册多说账号,创建站点,填写信息
多说域名即为shortname,
创建完成后在页面添加多说代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<!-- 多说评论框 start -->
<div class="ds-thread" data-thread-key="<%= key %>" data-title="<%= title %>" data-url="<%= url %>"></div>
<!-- 多说评论框 end -->
<!-- 多说公共JS代码 start (一个网页只需插入一次) -->
<script type="text/javascript">
var duoshuoQuery = {short_name:"shortname"};
(function() {
var ds = document.createElement('script');
ds.type = 'text/javascript';ds.async = true;
ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
ds.charset = 'UTF-8';
(document.getElementsByTagName('head')[0]
|| document.getElementsByTagName('body')[0]).appendChild(ds);
})();
</script>
<!-- 多说公共JS代码 end -->
如果不想设置多说评论的开关,可以忽略一下内容
在_config.yml中设置多说开关,在评论位置添加开关判断
1
2
3
4
5
6
7
8
//_config.yml
duoshuo:
on: true
domain: #shortname
//评论判断
<% if(theme.duoshuo.on) { %>
显示多说评论
<% } %>

disqus评论

注册disqus账号,点击GET STARTED->I want to install Disqus on my site
创建一个新的站点,这里的Website Name就是shortname,创建后无法修改,创建完成后添加disqus代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<div id="disqus_thread"></div>
<script>
/**
* RECOMMENDED CONFIGURATION VARIABLES: EDIT AND UNCOMMENT THE SECTION BELOW TO INSERT DYNAMIC VALUES FROM YOUR PLATFORM OR CMS.
* LEARN WHY DEFINING THESE VARIABLES IS IMPORTANT: https://disqus.com/admin/universalcode/#configuration-variables*/
/*
var disqus_config = function () {
this.page.url = PAGE_URL; // Replace PAGE_URL with your page's canonical URL variable
this.page.identifier = PAGE_IDENTIFIER; // Replace PAGE_IDENTIFIER with your page's unique identifier variable
};
*/
(function() { // DON'T EDIT BELOW THIS LINE
var d = document, s = d.createElement('script');
s.src = '//shortname.disqus.com/embed.js';
s.setAttribute('data-timestamp', +new Date());
(d.head || d.body).appendChild(s);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<script id="dsq-count-scr" src="//shortname.disqus.com/count.js" async></script>
如果不想设置disqus评论的开关,可以忽略一下内容
在_config.yml中设置disqus开关,在评论位置添加开关判断
1
2
3
4
5
6
7
8
//_config.yml
disqus:
on: true
shortname: shortname
//评论判断
<% if(theme.disqus.on) { %>
显示disqus评论
<% } %>

PREVIOUS NEXT
 |