惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Microsoft Azure Blog
Microsoft Azure Blog
Cloudbric
Cloudbric
I
InfoQ
V
V2EX
博客园_首页
The Register - Security
The Register - Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
S
Secure Thoughts
Vercel News
Vercel News
Forbes - Security
Forbes - Security
云风的 BLOG
云风的 BLOG
PCI Perspectives
PCI Perspectives
L
LINUX DO - 最新话题
D
DataBreaches.Net
H
Hacker News: Front Page
Application and Cybersecurity Blog
Application and Cybersecurity Blog
B
Blog RSS Feed
A
About on SuperTechFans
N
News and Events Feed by Topic
Apple Machine Learning Research
Apple Machine Learning Research
Help Net Security
Help Net Security
Attack and Defense Labs
Attack and Defense Labs
N
Netflix TechBlog - Medium
Spread Privacy
Spread Privacy
F
Full Disclosure
Recorded Future
Recorded Future
AWS News Blog
AWS News Blog
博客园 - 【当耐特】
The Cloudflare Blog
T
Threatpost
T
Tor Project blog
Google DeepMind News
Google DeepMind News
C
CXSECURITY Database RSS Feed - CXSecurity.com
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recent Announcements
Recent Announcements
M
MIT News - Artificial intelligence
A
Arctic Wolf
C
Check Point Blog
Stack Overflow Blog
Stack Overflow Blog
T
Threat Research - Cisco Blogs
Security Archives - TechRepublic
Security Archives - TechRepublic
Hacker News - Newest:
Hacker News - Newest: "LLM"
WordPress大学
WordPress大学
Cyberwarzone
Cyberwarzone
小众软件
小众软件
C
Cyber Attacks, Cyber Crime and Cyber Security
P
Proofpoint News Feed
Security Latest
Security Latest
The Last Watchdog
The Last Watchdog

空白Koobai

唠叨 - 2026-05-10 10:45 唠叨 - 2026-05-08 23:34 唠叨 - 2026-05-08 15:55 唠叨 - 2026-05-07 14:38 唠叨 - 2026-05-06 11:47 唠叨 - 2026-04-30 14:40 唠叨 - 2026-04-30 12:51 唠叨 - 2026-04-22 12:46 唠叨 - 2026-04-18 09:35 唠叨 - 2026-04-16 12:24 唠叨 - 2026-04-12 10:47 唠叨 - 2026-04-06 12:25 唠叨 - 2026-04-03 19:57 唠叨 - 2026-04-02 22:38 唠叨 - 2026-04-01 23:23 唠叨 - 2026-03-31 14:08 唠叨 - 2026-03-28 16:43 唠叨 - 2026-03-28 09:39 唠叨 - 2026-03-27 11:10 唠叨 - 2026-03-25 11:48 唠叨 - 2026-03-24 13:12 唠叨 - 2026-03-21 16:55 唠叨 - 2026-03-20 11:48 罢免小区业委会之后续 反角度之博客用户体验不能做的 N 件事 唠叨 - 2026-03-16 13:10 唠叨 - 2026-03-13 12:46 唠叨 - 2026-03-11 19:25 唠叨 - 2026-03-07 20:21 唠叨 - 2026-03-04 13:45 唠叨 - 2026-02-25 23:14 唠叨 - 2026-02-25 18:16 唠叨 - 2026-02-23 16:11 唠叨 - 2026-02-21 16:21 唠叨 - 2026-02-05 09:19 唠叨 - 2026-02-04 20:18 唠叨 - 2026-01-29 13:03 唠叨 - 2026-01-27 15:40 Hugo 通过 Github 自动推送到宝塔 (2026 年版备忘) 唠叨 - 2026-01-24 15:55 唠叨 - 2026-01-24 15:38 2025 关键词 唠叨 - 2025-06-22 22:07 唠叨 - 2025-06-10 17:31 唠叨 - 2025-05-14 22:04 唠叨 - 2025-04-16 22:06 唠叨 - 2025-04-09 10:28 唠叨 - 2025-04-07 22:09 唠叨 - 2025-03-22 11:30 唠叨 - 2025-01-29 23:14 唠叨 - 2025-01-21 19:30 唠叨 - 2025-01-10 19:39 唠叨 - 2025-01-09 13:57 罢免小区业委会 唠叨 - 2024-12-20 09:48 唠叨 - 2024-12-19 14:46 唠叨 - 2024-12-19 09:37 唠叨 - 2024-12-18 22:04 唠叨 - 2024-12-17 19:01 唠叨 - 2024-12-11 10:32 唠叨 - 2024-12-07 15:47 唠叨 - 2024-11-27 18:15 唠叨 - 2024-11-16 12:45 唠叨 - 2024-11-13 16:14 唠叨 - 2024-09-29 11:51 唠叨 - 2024-09-26 20:24 唠叨 - 2024-09-20 18:13 从 iOS 更换到 Android 会有不适吗? 唠叨 - 2024-09-17 11:21 唠叨 - 2024-09-14 20:10 唠叨 - 2024-09-04 20:51 唠叨 - 2024-09-02 20:17 唠叨 - 2024-08-08 14:19 唠叨 - 2024-08-07 16:45 唠叨 - 2024-07-27 23:21 唠叨 - 2024-07-09 23:37 唠叨 - 2024-06-15 10:43 唠叨 - 2024-06-01 23:03 唠叨 - 2024-05-31 10:06 五一假期之登高望远 以后如果小米做汽车了,也可以买小米汽车 唠叨 - 2024-03-25 14:05 唠叨 - 2024-03-23 15:26 唠叨 - 2024-03-20 21:06 自行车给自己带来了什么情绪价值爽点 唠叨 - 2024-02-28 15:44 HUGO 折腾随记之热力图 / 段落导航 唠叨 - 2024-02-21 21:00 唠叨 - 2024-02-18 19:38 唠叨 - 2024-02-17 16:24 这个春节有什么不一样 唠叨 - 2024-02-16 11:35 唠叨 - 2024-02-15 14:56 唠叨 - 2024-02-14 18:30 唠叨 - 2024-02-03 20:23 HUGO 外链跳转到中间页 唠叨 - 2024-01-31 20:20 折腾博客更像是自己的精神鸦片 唠叨 - 2024-01-29 16:21 唠叨 - 2024-01-27 10:54
Github 自动构建 Hugo, 并通过 Webhook 同步到宝塔指定目录
2023-02-20 · via 空白Koobai

(2024.01.19晚更新) 折腾博客的乐趣就是不停的折腾,一个评论插件就搞来搞去的,为此还特意买了轻量服务器,索性也把 Hugo 搬过去。只是原先自动同步到腾讯 COS 就不可用,而且域名还指定了境外访问路径,导致更新博客的流程变得非常复杂。最终通过 Google,总算解决:本地提交 hugo 源码到 Github,自动触发构建并同步到宝塔指定的网站目录。

部署步骤流程记录下:

1. 在 Github 的 Hugo 源码仓库根目录,新建".github/workflows/xxx.yml 文件,复制以下代码。作用:借助 Github Action 实现自动构建,并同步到另外一个仓库。其中 “PERSONAL_TOKEN” 为另外仓库的访问密钥;“external_repository” 为另外仓库地址。

name: Githubblog

on:
  workflow_dispatch:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          submodules: true
          fetch-depth: 0

      - name: Setup Hugo
        uses: peaceiris/actions-hugo@v2
        with:
          hugo-version: 'latest'
          extended: true

      - name: Build
        run: hugo --minify

      - name: Deploy
        uses: peaceiris/actions-gh-pages@v3
        with:
          personal_token: ${{ secrets.PERSONAL_TOKEN }}
          external_repository: koobai/koobai.github.io
          publish_dir: ./public

2. 打开宝塔面板,终端生成 git 公钥

# 安装 Git
yum -y install git

# Git全局配置和单个仓库的用户名邮箱配置
git config --global user.name  "username"
git config --global user.email  "[email protected]"

# 生成git公钥用于自动拉取(一路回车)
ssh-keygen -t rsa -C "你的@email.com"

# 查看git公钥
cat ~/.ssh/id_rsa.pub

3. 添加公钥到到 Github:头像–Settings–SSH and GPG keys–New SSH key

4. 打开宝塔面板商店,安装 WebHook 插件–添加执行脚本 (复制以下代码)。其中"gitHttp 为需同步的 github 仓库地址",“gh-pages"为仓库分支名称。

cd 网站目录
git config pull.rebase true
git pull
echo Onion Site Updated! $(TZ=UTC-8 date +"%Y-%m-%d"" ""%T")
echo ======================================================

以下代码已过时,暂不使用。

#!/bin/bash
echo ""
#输出当前时间
date --date='0 days ago' "+%Y-%m-%d %H:%M:%S"
echo "Start"
#git分支名称
branch="gh-pages"
#git项目路径
gitPath="/www/wwwroot/$1"
#git 仓库地址
gitHttp="[email protected]:koobai/koobai.github.io.git"
echo "Web站点路径:$gitPath"
#判断项目路径是否存在
if [ -d "$gitPath" ]; then
        cd $gitPath
        #判断是否存在git目录
        if [ ! -d ".git" ]; then
                echo "在该目录下克隆 git"
                sudo git clone $gitHttp gittemp
                sudo mv gittemp/.git .
                sudo rm -rf gittemp
        fi
        echo "拉取最新的项目文件"
        #sudo git reset --hard origin/$branch
        git remote add origin $gitHttp
        git branch --set-upstream-to=origin/$branch $branch
        sudo git reset --hard origin/$branch
        sudo git pull $gitHttp  2>&1
        echo "设置目录权限"
        sudo chown -R www:www $gitPath
        echo "End"
        exit
else
        echo "该项目路径不存在"
                echo "新建项目目录"
        mkdir $gitPath
        cd $gitPath
        #判断是否存在git目录
        if [ ! -d ".git" ]; then
                echo "在该目录下克隆 git"
                sudo git clone $gitHttp gittemp
                sudo mv gittemp/.git .
                sudo rm -rf gittemp
        fi
        echo "拉取最新的项目文件"
        #sudo git reset --hard origin/$branch
        sudo git pull gitHttp 2>&1
        echo "设置目录权限"
        sudo chown -R www:www $gitPath
        echo "End"
        exit
fi

5. 查看 WebHook 插件密钥,复制密钥地址。添加到 Github 需同步的仓库–Settings–Webhooks–Add webhook。其中 Content type 选择 application/json。

格式如:https://面板地址:面板端口/hook?access_key=密钥&param=需同步到的目录名称

6. 初始化宝塔网站目录

在宝塔终端执行:

cd 网站目录
git clone --depth 1 https://ghgo.top/https://github.com/koobai/koobai.github.io --single-branch .
git clone --depth 1 --branch main https://ghgo.top/https://github.com/koobai/koobai.github.io .

解释上面意思:--depth 1 只克隆最新的一次提交。mirror.ghproxy.com为github加速地址,koobai为github用户名,koobai.github.io为仓库名。最后 . 为当前目录。
--single-branch 克隆一个分支。或 --branch main 克隆 main 分支。

以下代码已过时,暂不使用。

cd 网站目录

# 初始化git 执行
git init

# 连接远程仓库
git remote add origin [email protected]:yourName/repositoryname.git

# 拉取想要的分支代码(gh-pages分支名称)
git pull origin gh-pages

# 等待完成

至此,步骤全部完成。当本地提交新文件到 Github hugo 源码 main 分支,就会自动触发(hugo 生成静态文件——同步到另一个仓库——同步到宝塔网站指定目录)。如果域名指定境外访问路径是 vercel 或 cloudflare 服务,当 hugo 源码更新的时候也会自动触发构建更新。

题外: 由于使用了轻量服务器,原先备案过的域名也需要重新接入备案。整个流程下来发现,现在备案审核速度是相当的快,必须点个赞。周一提交服务商,周二服务商提交管理局,周三审核通过。周三上午提交公安网安,下午审核通过。