GeekaholicLin / hexo-theme-ylion

:blush: 说不定是一个让你感到惊喜的hexo主题 :beers: :candy:
http://blog.geekaholic.cn
MIT License
120 stars 30 forks source link

请问有没有计划支持valine评论 #55

Open MonoLogueChi opened 4 years ago

MonoLogueChi commented 4 years ago

请问有没有计划支持valine,如果没有计划,我就打算自己搞了

MonoLogueChi commented 4 years ago

简单加了一个,但是不知道怎么做才能更好的切合主题

comments.ejs

<% if(theme.duoshuo_shortname && theme.duoshuo_shortname.length > 0){ %>
<%- partial('_thirdParty/duoshuo') %>
<% } else if(theme.disqus_shortname && theme.disqus_shortname.length > 0){ %>
<%- partial('_thirdParty/disqus') %>
<% } else if(theme.gitalk.enable){ %>
<script>
  gitalk.render("comments");
</script>
<% } else if(theme.valine.enable){ %>
<%- partial('_thirdParty/valine') %>
<% } %>

valine.ejs

<script>
    function loadScript(e,t){d=document,o=d.createElement("script"),s=d.getElementsByTagName("head")[0].appendChild(o),o.setAttribute("src",e),t&&o.addEventListener("load",function(e){t(e)}),s.parentNode.insertBefore(o,s)}
    loadScript('https://cdn.jsdelivr.net/npm/valine/dist/Valine.min.js',function(){
        new Valine({
            el: '#comments',
            notify: <%= theme.valine.notify %>,
            verify: <%= theme.valine.verify %>,
            appId: '<%= theme.valine.appid %>',
            appKey: '<%= theme.valine.appkey %>',
            placeholder: '<%= theme.valine.placeholder %>',
            avatar: '<%= theme.valine.avatar %>',
            avatar_cdn: '<%= theme.valine.avatar_cdn %>',
            pageSize: <%= theme.valine.pageSize %>,
            visitor: <%= theme.valine.visitor %>,
            recordIP: <%= theme.valine.recordIP %>,
            serverURLs: '<%= theme.valine.serverURLs %>'
        });
        if(window.location.hash){
          var checkExist = setInterval(function() {
            if (document.getElementById(window.location.hash.replace("#",""))) {
              location.href = window.location.hash;
              clearInterval(checkExist);
            }
          }, 250);
        }
    });
</script>

_config.yml

valine:
  enable: true
  appid: 'xxxxxxx' #Leancloud应用的appId
  appkey: 'xxxxxxx' #Leancloud应用的appId
  verify: false #验证码
  notify: false #评论回复提醒
  avatar: '' #评论列表头像样式:''/mm/identicon/monsterid/wavatar/retro/hide
  avatar_cdn: 'https://sdn.geekzu.org/avatar/' #头像CDN
  placeholder: '友情提醒,留下正确的邮箱地址可以第一时间获取评论反馈' #评论框占位符
  pageSize: 12 #评论分页
  visitor: true #阅读统计
  recordIP: true #记录IP
  serverURLs: 

valine和leancloud统计会有冲突,正在想办法解决,用valine自带的统计代理leancloud统计,应该可以解决。