为hexo搭建isso评论系统

Isso评论系统

Isso是什么

Isso是类似于Disqus的轻量级评论服务器。它允许匿名评论,保持身份并且易于管理。它使用JavaScript和跨域资源共享来轻松集成到(静态)网站。

为什么我选择isso

在重新部署我的hexo博客时,发现next主题在8.1.0版本中移除了对我原来使用的评论系统Valine的支持,理由是安全性问题,因此需要更换另一个评论系统。在评论系统的选择中,我认为能够让读者方便留言是最重要的,因此需要科学上网的、需要注册账号的都被我排除在外,从而Isso成为了首要选择。

服务端部署isso系统

安装

Isso的安装有多种方法,包括从各Linux发行版的包管理器中安装、使用pip安装、自行克隆Isso仓库编译安装等,详情请见Isso 安装指南,个人建议使用pip。

Isso-cn的配置方法基本一致。

# Debian/Ubuntu
sudo apt install isso

# pip
pip install isso

Isso配置

在没有指定配置文件的情况下,Isso会读取/etc/isso.conf作为默认配置文件运行。

[general]
; 确保Isso进程对dbpath指向的db文件有读写权力
dbpath = /var/lib/isso/comments.db
; 需要添加Isso评论系统的网站地址(可以是ip也可以是网址)
host = https://tech.tu5039.cn/
; 本地监听地址,之后客户端的请求需要发送到这个地址
[server]
listen = http://0.0.0.0:1234/

以上配置可以满足运行Isso的最低要求,如果需要更多的功能可以查看官方文档

另外,每个配置文件对应一个网站的评论系统,也就是说,如果需要同时为多个网站提供服务的话,应当有多个使用不同配置文件的Isso进程,官网推荐使用gunicorn来进行管理,但我没有成功,如果有成功的大佬,欢迎指点。

服务器配置

在部署的时候,发现如果访问的是https网站,则非https的js请求会被屏蔽,因此我们需要为Isso添加一个安全证书。

具体步骤为:

  1. 申请一个域名的安全证书,如isso.tu5039.cn
  2. 使用nginx(或Apache)作为http服务器并将步骤1中的域名转发到Isso的监听端口,本文使用nginx,证书部署以及nginx反向代理不再展开

客户端配置

如果只需普通使用,在next配置文件里启用Isso评论系统即可

comments:
  active: isso
# ......
isso: https://tech.tu5039.cn//isso/ # Your isso server domain

修改hexo next主题

但有时客户端也需要更多的配置,因此找到与生成Isso评论区相关的文件再进行修改即可。

首先说明next主题中布局模板文件是njk文件,查找Isso对应的njk,可以得知需要修改的js文件next/source/js/third-party/comments/isso.js

{# isso.njk #}
{{ next_data('isso', theme.isso) }}
{{ next_js('third-party/comments/isso.js') }}
// isso.js
/* global NexT, CONFIG */

document.addEventListener('page:loaded', () => {
  if (!CONFIG.page.comments) return;

  NexT.utils.loadComments('#isso-thread')
    .then(() => NexT.utils.getScript(`${CONFIG.isso}js/embed.min.js`, {
      attributes: {
        dataset: {
          isso: `${CONFIG.isso}`,
        }
      },
      parentNode: document.querySelector('#isso-thread')
    }));
});

可以很快看出next配置文件中的isso属性对应的就是js文件里的 ${CONFIG.isso} ,因此如果想加入其他的Isso客户端配置项,只需要同时修改next配置文件isso.js两个文件即可。示例如下:

# _config.next.yml
isso: 
  url: https://tech.tu5039.cn//isso/ # Your isso server domain
  lang: zh # Set language
  # Set to true when spam guard is configured with reply-to-self = true.
  reply_to_self: "false" 
  # Set to true when spam guard is configured with require-author = true.
  require_author: "false" 
  # Set to true when spam guard is configured with require-email = true.
  require_email: "false" 
  # Set to true when reply notifications is configured with reply-notifications = true.
  reply_notifications: "false" 
  # Number of top level (or nested) comments to show by default. If some comments are not shown, an “X Hidden” link is shown.
  # Set to “inf” to show all, or “0” to hide all.
  max_comments_top: "10"
  max_comments_nested: "5"
  # Number of comments to reveal on clicking the “X Hidden” link.
  reveal_on_click: "5"
  # Enable or disable avatar generation.
  avatar: "true"
  # Set avatar background color. Any valid CSS color will do.
  avatar_bg: "#f0f0f0"
  # Set avatar foreground color. Up to 8 colors are possible. 
  # The default color scheme is based in this color palette. 
  # Multiple colors must be separated by space. 
  # If you use less than eight colors and not a multiple of 2, the color distribution is not even.
  avatar_fg: "#9abf88 #5698c4 #e279a3 #9163b6 ..."
  # Enable or disable voting feature on the client side.
  vote: "true"
  # List of vote levels used to customize comment appearance based on score. 
  # Provide a comma-separated values (eg. “0,5,10,25,100”) or a JSON array (eg. “[-5,5,15]”).
  vote_levels: ""
  # Enable or disable the addition of a link to the feed for the comment thread. 
  # The link will only be valid if the appropriate setting, in [rss] section, is also enabled server-side.
  feed: "false"
// isso.js
/* global NexT, CONFIG */

document.addEventListener('page:loaded', () => {
  if (!CONFIG.page.comments) return;

  NexT.utils.loadComments('#isso-thread')
    .then(() => NexT.utils.getScript(`${CONFIG.isso.url}js/embed.min.js`, {
      attributes: {
        dataset: {
          isso: `${CONFIG.isso.url}`,
          issoLang: `${CONFIG.isso.lang }`,
          issoReplyToSelf: `${CONFIG.isso.reply_to_self }`,
          issoRequireAuthor: `${CONFIG.isso.require_author }`,
          issoRequireEmail: `${CONFIG.isso.require_email }`,
          issoReplyNotifications: `${CONFIG.isso.reply_notifications}`,
          issoMaxCommentsTop: `${CONFIG.isso.max_comments_top }`,
          issoMaxCommentsNested: `${CONFIG.isso.max_comments_nested }`,
          issoRevealOnClick: `${CONFIG.isso.reveal_on_click }`,
          issoAvatar: `${CONFIG.isso.avatar }`,
          issoAvatarBg: `${CONFIG.isso.avatar_bg }`,
          issoAvatarFg: `${CONFIG.isso.avatar_fg }`,
          issoVote: `${CONFIG.isso.vote }`,
          issoVoteLevels: `${CONFIG.isso.vote_levels }`,
          issoFeed: `${CONFIG.isso.feed }`
        }
      },
      parentNode: document.querySelector('#isso-thread')
    }));
});

本文首发于为hexo搭建isso评论系统

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
你想了解如何使用 Hexo 搭建个人博客,是吗?我可以为你提供一些基本的指导。首先,你需要按照以下步骤进行操作: 1. 安装Node.js:Hexo 是基于 Node.js 的静态网站生成器,所以你需要先安装 Node.js。你可以在 Node.js 官方网站上下载适合你操作系统的安装包,并按照指示进行安装。 2. 安装Hexo:打开命令行终端,运行以下命令来安装 Hexo: ``` npm install -g hexo-cli ``` 这将全局安装 Hexo 命令行工具。 3. 初始化博客:选择一个合适的目录作为你的博客根目录,并在终端中进入该目录。然后运行以下命令来初始化博客: ``` hexo init myblog cd myblog npm install ``` 这将创建一个名为 "myblog" 的新目录,并在其中初始化 Hexo。 4. 配置博客:在博客根目录中,找到名为 `_config.yml` 的文件,并使用文本编辑器打开它。在这个文件中,你可以配置博客的各种设置,比如标题、描述、作者等。根据你的需求进行相应的修改。 5. 创建新文章:使用以下命令来创建一个新的文章: ``` hexo new "My First Post" ``` 这将在 `source/_posts` 目录中创建一个名为 "my-first-post.md" 的 Markdown 文件。你可以使用 Markdown 语法来撰写文章内容。 6. 预览博客:运行以下命令来启动本地服务器,并预览你的博客: ``` hexo server ``` 然后在浏览器中访问 `http://localhost:4000`,你将看到你的博客的预览页面。 7. 部署博客:当你完成了博客的撰写和调试,可以使用以下命令来生成静态文件并部署到你的博客托管平台: ``` hexo generate hexo deploy ``` 这将生成一个名为 "public" 的目录,其中包含了你的博客的静态文件。你可以将这些文件上传到你选择的托管平台上,如 GitHub Pages、Netlify 等。 这些是使用 Hexo 搭建个人博客的基本步骤。当然,在实际使用过程中,你还可以根据需要安装主题、插件等来增强博客的功能和外观。希望这些信息对你有所帮助!如果你有任何进一步的问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值