From 7dad54d7987edd98f6793a31d12da0f4b2b3f081 Mon Sep 17 00:00:00 2001 From: Vaica <94612053+zqlit@users.noreply.github.com> Date: Sun, 1 Feb 2026 13:42:02 +0800 Subject: [PATCH] =?UTF-8?q?fixed=20=20=E9=83=A8=E7=BD=B2=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/{upy.yml => deploy.yml} | 8 +- .../2026/2026-01-31-Artalk接入AI摘要/index.md | 2 +- .../index.md | 2 +- .../2026-02-02-hugo-deploy-edgeone/index.md | 110 ++++++++++++++++++ scripts/deploy_edgeone.sh | 29 +++++ 5 files changed, 147 insertions(+), 4 deletions(-) rename .github/workflows/{upy.yml => deploy.yml} (95%) create mode 100644 content/post/2026/2026-02-02-hugo-deploy-edgeone/index.md create mode 100644 scripts/deploy_edgeone.sh diff --git a/.github/workflows/upy.yml b/.github/workflows/deploy.yml similarity index 95% rename from .github/workflows/upy.yml rename to .github/workflows/deploy.yml index 8ea40f8d..c49ab126 100644 --- a/.github/workflows/upy.yml +++ b/.github/workflows/deploy.yml @@ -1,4 +1,4 @@ -name: Deploy to UpYun +name: Deploy to Production on: push: @@ -77,7 +77,11 @@ jobs: run: rm -rf public && hugo --minify - name: Deploy to EdgeOne Pages - run: npx edgeone pages deploy ./public -n hugo-blog -t ${{ secrets.EDGEONE_API_TOKEN }} + env: + EDGEONE_API_TOKEN: ${{ secrets.EDGEONE_API_TOKEN }} + run: | + chmod +x scripts/deploy_edgeone.sh + ./scripts/deploy_edgeone.sh hugo-blog ./public - name: Debug Environment Variables run: | diff --git a/content/post/2026/2026-01-31-Artalk接入AI摘要/index.md b/content/post/2026/2026-01-31-Artalk接入AI摘要/index.md index 114cacab..537324b7 100644 --- a/content/post/2026/2026-01-31-Artalk接入AI摘要/index.md +++ b/content/post/2026/2026-01-31-Artalk接入AI摘要/index.md @@ -1,6 +1,6 @@ --- title: Artalk评论区接入AI摘要的尝试 -date: 2026-01-31T13:20:00.000Z +date: 2026-01-31T09:00:00+08:00 draft: false categories: - 尝试 diff --git a/content/post/2026/2026-02-01-博客友链实时健康监测方案/index.md b/content/post/2026/2026-02-01-博客友链实时健康监测方案/index.md index eec0293b..b32cd01a 100644 --- a/content/post/2026/2026-02-01-博客友链实时健康监测方案/index.md +++ b/content/post/2026/2026-02-01-博客友链实时健康监测方案/index.md @@ -1,6 +1,6 @@ --- title: 博客友链实时健康监测方案 -date: 2026-02-01T02:00:00.000Z +date: 2026-02-01T09:00:00+08:00 draft: false categories: - 技术 diff --git a/content/post/2026/2026-02-02-hugo-deploy-edgeone/index.md b/content/post/2026/2026-02-02-hugo-deploy-edgeone/index.md new file mode 100644 index 00000000..a7057b82 --- /dev/null +++ b/content/post/2026/2026-02-02-hugo-deploy-edgeone/index.md @@ -0,0 +1,110 @@ +--- +title: Hugo博客部署腾讯云EdgeOne Pages的尝试 +date: 2026-02-02T09:00:00+08:00 +draft: false +categories: + - 尝试 + - 技术 +tags: + - Hugo + - EdgeOne + - CI/CD +--- + +最近看到不少博友都在推荐腾讯云的 EdgeOne Pages,说是访问速度挺快,而且对个人博客这种静态站点很友好。想着自己这个小站平时也没少折腾,既然有更好的选择,那就试试看呗。 + +其实我对于运维这些也不是特别精通,就是喜欢捣鼓。这次迁移过程虽然遇到了一点小插曲,但好在最后都解决了。顺便把过程记录下来,给同样用 Hugo 搭建博客的朋友们做个参考。 + +## 为什么要换? + +其实原来的部署方式也能用,但作为一个把博客当成"电子宠物"养的人,总想给来访的朋友们提供更好的体验。EdgeOne 主打的就是边缘加速,直白点说就是能让国内的朋友打开博客更快一点。而且它给的免费额度对于我们这种个人博客来说完全够用了。 + +## 遇到的一个小插曲 + +刚开始在 GitHub Actions 上自动部署的时候,总是提示空间不足: + +```text +Error: No space left on device +``` + +这就很尴尬了。后来发现是我以前上传图片太随意了,很多高清原图把空间占满了。于是先用脚本把图片都压缩成了 WebP 格式,给仓库"瘦身"了一下,这才顺利进行下一步。这也提醒我,平时维护博客还是要注意一下资源管理呀。 + +## 编写部署脚本 + +为了让部署过程更稳定,也方便以后自己在本地测试,我没有直接把一堆命令写在 GitHub 的配置里,而是专门写了一个小脚本。 + +虽然我代码写得一般,但加上注释后应该还是挺好懂的。这里把完整代码贴出来,大家如果有需要可以直接拿去用: + +**`scripts/deploy_edgeone.sh`** + +```bash +#!/bin/bash + +# EdgeOne Pages 部署脚本 + +# 1. 检查必要的环境变量 +# 如果没有配置 API Token,就直接报错退出,防止后面瞎忙活 +if [ -z "$EDGEONE_API_TOKEN" ]; then + echo "Error: EDGEONE_API_TOKEN is not set." + exit 1 +fi + +# 2. 设置默认值 +# 如果没传参数,就用默认的 "hugo-blog" 作为项目名 +PROJECT_NAME=${1:-"hugo-blog"} +# 默认发布当前目录下的 public 文件夹 +BUILD_DIR=${2:-"./public"} + +echo "正在部署到 EdgeOne Pages..." +echo "项目名称: $PROJECT_NAME" +echo "发布目录: $BUILD_DIR" + +# 3. 执行部署命令 +# 这里用 npx 来运行,这样就不用在电脑上专门安装 edgeone 的命令行工具了 +# 也不用担心版本不兼容的问题,挺方便的 +npx edgeone pages deploy "$BUILD_DIR" -n "$PROJECT_NAME" -t "$EDGEONE_API_TOKEN" + +# 4. 检查是否成功 +# $? 代表上一个命令的退出状态,0 表示成功 +if [ $? -eq 0 ]; then + echo "太棒了,部署成功!" +else + echo "哎呀,部署失败了,快去检查一下日志吧。" + exit 1 +fi +``` + +## 配置自动化流程 + +脚本写好了,最后一步就是告诉 GitHub Actions 每次我更新文章时自动运行这个脚本。 + +在 `.github/workflows/deploy.yml` 文件里,我是这样配置的: + +```yaml + # ... 前面的构建步骤省略了 ... + + # 构建生成静态文件 + - name: Build + run: rm -rf public && hugo --minify + + # 部署到 EdgeOne Pages + - name: Deploy to EdgeOne Pages + env: + # 这个 Token 记得去 GitHub 仓库的 Settings -> Secrets 里配好哦 + EDGEONE_API_TOKEN: ${{ secrets.EDGEONE_API_TOKEN }} + run: | + # 给脚本加上可执行权限,不然运行不了 + chmod +x scripts/deploy_edgeone.sh + # 执行脚本,传入项目名和目录 + ./scripts/deploy_edgeone.sh hugo-blog ./public + + # ... 后面的步骤 ... +``` + +## 小结 + +看着 GitHub Actions 里的绿色对号亮起,心里还是挺舒坦的。现在博客访问起来感觉确实顺滑了一些。 + +折腾博客的乐趣大概就在这里吧,虽然过程中会遇到各种奇奇怪怪的问题,但解决问题后的那份满足感,还有能和博友们分享经验的快乐,是什么都比不了的。 + +如果你的博客也想试试 EdgeOne,希望这篇文章能帮到你。有问题欢迎在评论区留言,我们一起交流~ diff --git a/scripts/deploy_edgeone.sh b/scripts/deploy_edgeone.sh new file mode 100644 index 00000000..b7553cd0 --- /dev/null +++ b/scripts/deploy_edgeone.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# EdgeOne Pages Deployment Script + +# 1. Verify required environment variables +if [ -z "$EDGEONE_API_TOKEN" ]; then + echo "Error: EDGEONE_API_TOKEN is not set." + exit 1 +fi + +# 2. Set default values if not provided +PROJECT_NAME=${1:-"hugo-blog"} +BUILD_DIR=${2:-"./public"} + +echo "Deploying to EdgeOne Pages..." +echo "Project: $PROJECT_NAME" +echo "Directory: $BUILD_DIR" + +# 3. Execute deployment command +# We use npx to run the edgeone CLI without global installation +npx edgeone pages deploy "$BUILD_DIR" -n "$PROJECT_NAME" -t "$EDGEONE_API_TOKEN" + +# 4. Check exit code +if [ $? -eq 0 ]; then + echo "Deployment successful!" +else + echo "Deployment failed!" + exit 1 +fi