安装

wget https://github.com/umputun/remark42/releases/download/v1.11.3/remark42.linux-amd64.tar.gz -O remark42.linux-amd64.tar.gz
tar xzf remark42.linux-amd64.tar.gz
mv remark42.linux-amd64 /usr/local/bin

添加用户设置权限

useradd -r remark42
mkdir -m 770 /var/www/remark42
chown :remark42 /var/www/remark42
mkdir -m 770 /etc/remark42
chown :remark42 /etc/remark42

设置配置文件/启动

nano /etc/remark42/remark42.conf

REMARK_URL=https://comment.techlayman.com
SECRET=some_secret_key_phrase_1234
SITE=techlayman
AUTH_ANON=false
EMOJI=true
AUTH_GITHUB_CID=xxx
AUTH_GITHUB_CSEC=xxx
nano /etc/systemd/system/remark42.service

[Unit]
Description=remark42 comment engine
After=network.target

[Service]
User=remark42
Group=remark42
EnvironmentFile=/etc/remark42/remark42.conf
WorkingDirectory=/var/www/remark42
Restart=always
RestartSec=5
ExecStart=/usr/local/bin/remark42.linux-amd64 server

[Install]
WantedBy=multi-user.target
systemctl enable --now remark42

Hugo模板修改

comments.html模板

nano layouts/partials/comments.html

{{- with .Site.Params.comments.remark42 -}}
<div id="remark42"></div>
<script>
  var remark_config = {
      host: '{{ .host }}',
      site_id: '{{ .site }}',
      components: ['embed'],
      url: '{{ $.Permalink }}',
      page_title: '{{ $.Title }}',
      max_shown_comments: 20,
      locale: 'zh',
      no_footer: 'true'
  };

  !(function (e, n) {
    for (var o = 0; o < e.length; o++) {
      var r = n.createElement("script"),
        c = ".js",
        d = n.head || n.body;
      "noModule" in r ? ((r.type = "module"), (c = ".mjs")) : (r.async = !0),
        (r.defer = !0),
        (r.src = remark_config.host + "/web/" + e[o] + c),
        d.appendChild(r);
    }
  })(remark_config.components || ["embed"], document);

  window.addEventListener('onColorSchemeChange', (e) => {
      window.REMARK42.changeTheme(e.detail);
  })
</script>

{{- end -}}

config.toml文件

nano config.toml

[params]
  comments:
    enabled: true
    provider: remark42
    remark42:
      host: "https://comment.techlayman.com"
      site: "techlayman"

修改Caddy配置文件

nano /etc/caddy/Caddyfile

comment.techlayman.com {
    @comments {
        host comment.techlayman.com
    }
    reverse_proxy @comments localhost:8080
}