Cloudflare Pages|评论系统|图床搭建
Table of Contents
Cloudflare Pages#
之前用的是github pages,我本来也不需要担心加载速度,其实用起来没什么问题。但毕竟必须挂出一个公开的仓库,总感觉有点别扭
刚好有cloudflare的域名,所以干脆移到一起,更加方便了
设置很简单,在cloudflare pages的界面选择新建,授权连接自己的github私有仓库。只需在最后的环境变量(高级)中,填写hugo版本:
变量名称 | 值 |
---|---|
HUGO_VERSION | 0.129.0 (填写最新版本就行了) |
每次对私有仓库的git push,都会自动进行部署。每次重新git clone都需要加载主题
# 第一次
git submodule add -f https://github.com/panr/hugo-theme-terminal.git themes/terminal
# 重新加载
git submodule update --init --recursive
# 更新
git submodule update --remote --merge
Giscus评论系统#
对比了很多第三方评论系统,考虑到实在不想花钱买服务器,且根本没有人会来评论,最后还是选择了基于github discussion的Giscus
首先,在giscus.app里填入自己的设定,映射关系选择pathname
,分类选择Announcements
,得到以下的script标签,
将其保存为"\layouts\partials\comments.html"
:
<script src="https://giscus.app/client.js"
data-repo="szkm330/comments"
data-repo-id="R_xxxxxxxxxx"
data-category="Announcements"
data-category-id="DIC_xxxxxxxxx"
data-mapping="pathname"
data-strict="0"
data-reactions-enabled="0"
data-emit-metadata="0"
data-input-position="top"
data-theme="light"
data-lang="en"
crossorigin="anonymous"
async>
</script>
博客的config也需要添加同样的内容:
comments = true
[params.commentsParams]
repo = "szkm330/comments"
repoId = "R_xxxxxxxxxx"
category = "Announcements"
categoryId = "DIC_xxxxxxxx"
mapping = "pathname"
reactionsEnabled = 0
emitMetadata = 0
inputPosition = "top"
lang = "en"
cloudflare R2图床搭建#
流程很简单,不多说明。开通 R2 服务,创建存储桶,然后绑一个自定义域名(如:img.example.com
)
主流应该是通过第三方工具进行图片整理上传,但我懒得弄了,它网页端自带的也能凑合用。具体使用流程为:
- 使用TinyPNG将图片压缩为webp格式
- 上传至cloudflare的R2存储桶,得到图片地址
最后,以一张图片结尾吧!
Licensed under CC BY-NC-SA 4.0