GitHub-Hexo-Blog 集成Gitalk評論插件


本文)末尾可查看先查看效果:

1. 新建New OAuth App

在github中,Settings / Develpoer settings OAuth Apps / New OAuth App
i

bolg-comments
https://github.com/SuperTrampAI
bolg-comments gitalk
https://supertrampai.com
分別在對應的欄目內填入相對應的內容
注意:在Authorization callback URL 中,不應該加上“/”

2. 創建github倉庫,用來放置評論的文本

在你的github中,新建repository,命名如下:blog-comments (可替換)

下圖為bolg架構
i.png

總共需要操作的幾個文件,加一個_config.yml文件

3. 新建gitalk.swig

文件目錄:themes\hexo-theme-next-master\layout_third-party\comments
文件內容如下:

{% if [page.comments](http://page.comments/) && theme.gitalk.enable %}
<link rel="stylesheet" href="[https://unpkg.com/gitalk/dist/gitalk.css](https://unpkg.com/gitalk/dist/gitalk.css)">
<script src="[https://unpkg.com/gitalk/dist/gitalk.min.js](https://unpkg.com/gitalk/dist/gitalk.min.js)"></script>
   <script type="text/javascript">
        var gitalk = new Gitalk({
          clientID: '{{ theme.gitalk.clientID }}',
          clientSecret: '{{ theme.gitalk.clientSecret }}',
          repo: '{{ theme.gitalk.repo }}',
          owner: '{{ theme.gitalk.githubID }}',
          admin: ['{{ theme.gitalk.adminUser }}'],
          id: location.pathname,
          distractionFreeMode: '{{ theme.gitalk.distractionFreeMode }}'
        })
        gitalk.render('gitalk-container')
       </script>
{% endif %}

4. 修改index.swig

在gitalk.swig的同級目錄下找到index.swig
在文件末尾加上:

{% include 'gitalk.swig' %}

如果你的gitalk.swig文件不是采取的如上命名,自行替換

5. 修改comments.swig

目錄:themes\hexo-theme-next-master\layout_partials\comments.swig
在如下目錄的最后一個if代碼塊內加入如下代碼:

{% elseif theme.gitalk.enable %}
<div id="gitalk-container"></div>

此處划重點!!!!代碼塊必須放入,如圖片所示位置!
i.png

6. 修改_config.yml

在themes\hexo-theme-next-master_config.yml如下位置加入代碼塊:

gitalk:
  enable: true
  githubID: SuperTrampAI  # 你的githubId
  repo: blog-comments # 新建的repository名
  clientID: # 申請的OAuth AppID
  clientSecret:  # 申請的OAuth AppID
  adminUser: SuperTrampAI # 
  distractionFreeMode: true

到此結束,可以在本文最后看到效果


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM