花了两个晚上的时间搭建好了这个博客。记录下过程:

  1. 参考sulv的建站教程,用他的代码生成了我的第一版博客。然后根据个人信息作了一些配置
  2. 通过docker搭建twikoo服务,提供了评论功能,不过目前docker运行在本地机器上,时不时就会关掉,将来换到云服务器上。
    不过我对twikoo不太满意,我预期中的评论应该能和github账号联动,而不是一个自定义的账号。
  3. 将博客部署到github page上,暂且先用着().github.io的域名,以后换成自己的。
  4. 利用github action,实现博客自动发布部署。
  5. 将评论替换为giscus,实现与github联动。
    根据个人信息配置好后,将script语句复制到/layouts/partials/comments.html中。
<!-- giscus -->
<div>
    <div id="tcomment"></div>

    <script src="https://giscus.app/client.js"
        data-repo=""  //填写自己的仓库地址
        data-repo-id="" //repoId
        data-category="Announcements" //评论类型,参照github的discussion
        data-category-id="DIC_kwDOIAW3Os4CReNg"
        data-mapping="url"
        data-strict="0"
        data-reactions-enabled="1"
        data-emit-metadata="0"
        data-input-position="top"
        data-theme="preferred_color_scheme"
        data-lang="zh-CN" //中文
        data-loading="lazy" //懒加载
        crossorigin="anonymous"
        async>
    </script>
</div>

以上语句可以在 gitcus中自动生成。 调用上述giscus代码的位置:layouts/_default/single.html

<article class="post-single">

  // 这里是默认的其他代码
  
  // giscus,一般只需要复制以下3行代码,加上其他代码是为了帮助读者确认代码添加的位置
  {{- if (.Param "comments") }}
    {{- partial "comments.html" . }}
  {{- end }}
</article>

参考

  1. Hugo博客搭建
  2. Hugo + GitHub Action,搭建你的博客自动发布系统
  3. gitcus