Linking

Capturing Life & Tech

  • 主页
  • 随笔
  • 关于我
所有文章 外链

Linking

Capturing Life & Tech

  • 主页
  • 随笔
  • 关于我

博客留言系统更新为Gitalk

阅读数:次 2018-01-06
字数统计: 651字   |   阅读时长≈ 3分

目录

  1. 原由
  2. 官网
  3. ejs版步骤
  4. 问题
  5. 优化
  6. 参考

1. 原由

之前用友言评论,最近打开发现gg了;刚好看到有道友发的有关Gitalk评论功能。基于GitHub的issue和Preact,GitHub大法好,果断采用啊。于是,这个改版列入了周末计划。

2. 官网

https://github.com/gitalk/gitalk/blob/master/readme-cn.md

3. ejs版步骤

1.Github上新建一个仓库,命名如blog_comment。

2.创建OAuth Application,链接

1
2
3
Application name: 第一步建立的仓库名`blog_comment`
Homepage URL: https://yourgithubname.gitbub.io/
Authorization callback URL: https://yourgithubname.gitbub.io/

3.theme目录下的config中加入

1
2
3
4
5
6
7
8
9
10
# Gitalk 
gitalk:
enable: true #用来做启用判断可以不用
clientID: 'clientID' #OAuth Application
clientSecret: 'clientID' #OAuth Application
repo: blog_comment仓库 #刚创建blog_comment用于gitalk Issue的仓库名称
owner: username #github用户名
admin: username
distractionFreeMode: true # 类似于Facebook的阴影效果
labels: ['Gitalk'] # 用于生成Issue的标签

发现网上的基本上没有基于Hexo-Theme-Yilia的教程,只能看着其他模版,来改写语法的不同了。

4.gitalk.ejs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<% if(theme.gitalk.enable) {%>
<% if(theme.gitalk.distractionFreeMode) {%>
<link rel="stylesheet" href="/gitalk/gitalk.css">
<script src="/gitalk/gitalk.min.js"></script>
<script type="text/javascript">
var gitalk = new Gitalk({
id: location.pathname,
clientID: '<%- theme.gitalk.clientID %>',
clientSecret: '<%- theme.gitalk.clientSecret %>',
repo: '<%- theme.gitalk.repo %>',
owner: '<%- theme.gitalk.owner %>',
admin: '<%- theme.gitalk.admin %>',
distractionFreeMode: '<%- theme.gitalk.distractionFreeMode %>',
})
gitalk.render('gitalk-container')
</script>
<% } %>
<% } %>

4. 问题

替换过程中遇到问题。

1.Error: not found

  • 仓库未建立或名称错误
  • 语法改写错误,没获取clientID,可查看redirectURL是否包含正确的clientID

我的问题是语法错误,ejs和swig语法区别。

2.未授权

未建立Oauth Apps,入口

clientID未获取,可能是上面的错误。

3.issue不存在

初始化issue;对应的id,唯一标示。

id是location.url还是location.pathname,可以在console调试。

在comment仓库中,创建对应的issue;label必须设置成id对应的,且中文paathname的label太长。

一个文章一个issue。

比较麻烦,可否脚本自动化?==已支持自动化。

5. 优化

1.加载速度

将Gitalk的js和css拿到本地,放置在resource/gitalk目录下。引用方式如下:

1
2
<link rel="stylesheet" href="/gitalk/gitalk.css">
<script src="/gitalk/gitalk.min.js"></script>

2.css优化

1
2
3
4
5
6
7
# 加入margin值
.gt-container {
-webkit-box-sizing: border-box;
box-sizing: border-box;
font-size: 16px;
margin: 0 30px;
}

6. 参考

  • http://zhangchenghui.cn/2017/11/28/Gitalk/
  • https://www.jianshu.com/p/9be29ed2f4b7
  • 本文作者: Linking
  • 本文链接: https://linking.fun/2018/01/06/comment-sys-with-gitalk/
  • 版权声明: 版权所有,转载请注明出处!
  • blog
  • Gitalk
  • CS

扫一扫,分享到微信

微信好友城市分布分析
朱赟的技术管理课第一周笔记
  1. 1. 目录
    1. 1.1. 1. 原由
    2. 1.2. 2. 官网
    3. 1.3. 3. ejs版步骤
    4. 1.4. 4. 问题
    5. 1.5. 5. 优化
    6. 1.6. 6. 参考
© 2015-2026 Linking
GitHub:hexo-theme-yilia-plus by Litten
本站总访问量次 | 本站访客数人
  • 所有文章
  • 外链

tag:

  • weather
  • 需求
  • essay
  • basketball
  • olympic
  • nginx
  • APPScan
  • SQl盲注
  • xss
  • Ajax
  • ajax
  • ai
  • agent
  • openclaw
  • ccf
  • Nginx
  • HTML5
  • html5
  • hmtl5
  • sse
  • JavaScriptCore
  • Oracle
  • operation
  • Linux
  • deploy
  • Mac Office
  • markdown
  • ListView
  • GridView
  • MySQL
  • 慢查询
  • mongodb
  • 转置
  • thought
  • network
  • ubuntu
  • NetworkManager
  • RFKill
  • Netplan
  • avatar
  • cocoa
  • blog
  • Gitalk
  • container
  • macvlan
  • docker
  • oracle
  • cookie
  • patch
  • gitea
  • git
  • iOS
  • https
  • 多线程
  • bundle
  • 兼容性
  • HTTP
  • 绘图
  • cs
  • java
  • 效率
  • 快捷键
  • route
  • nodejs
  • pip
  • arcgis
  • arcgis 建模
  • 标识
  • redis
  • read
  • bookList
  • running
  • showdoc
  • disk
  • unit-test
  • D.Wade
  • thoughts
  • duoduo
  • Python
  • python
  • tomcat
  • 读书节
  • session
  • jdk
  • war
  • 加班
  • Android onclick事件监听
  • 正则
  • 手机品牌匹配
  • ntp
  • OpenLayers
  • Geoserver
  • wechat
  • 微信公众号
  • 爬虫
  • WeChat
  • 张靓颖
  • 动漫
  • vpn
  • PPT
  • MarkDown
  • plan
  • 朱赟
  • 极客时间专栏
  • 极客邦
  • 模块化
  • MVC
  • excel
  • NBA
  • kobe
  • team
  • crawler
  • 进度条
  • ssl
  • book
  • anti-stealing-link
  • Agentic Engineering
  • Vibe Coding
  • Software 3.0
  • Andrej Karpathy
  • LLM
  • Programming

    缺失模块。
    1、请确保node版本大于6.2
    2、在博客根目录(注意不是yilia-plus根目录)执行以下命令:
    npm i hexo-generator-json-content --save

    3、在根目录_config.yml里添加配置:

      jsonContent:
        meta: false
        pages: false
        posts:
          title: true
          date: true
          path: true
          text: false
          raw: false
          content: false
          slug: false
          updated: false
          comments: false
          link: false
          permalink: false
          excerpt: false
          categories: false
          tags: true
    

  • GitHub Trending
  • OpenAI ChatGPT
  • Gitee码云
  • 简书
  • CSDN