经过10次测试:test123456789/10/,终于在github远程部署成功,此为记录。
由于经常往返鹿特丹-阿姆,在火车上的时光难免想写点东西。但是博客本地部署在家里的电脑上,写起来难免觉得别扭,了解到github可以自动进行部署,于是说干就干:
参考资料:
[1] https://isedu.top/index.php/archives/144/
[2] Claude 3.7 sonnet
[3] Manus
最难搞定的点 Troubleshooting
- github workflow的设置:需要生成一个public key和private key 分别放在github page 和private repo;
- Make sure your GitHub Pages repository is configured to deploy from the correct branch: 这个太容易忽略了,导致需要pull request,其实直接就可以merge到github page;
- If you’re using custom themes or plugins, ensure they’re properly included in your repository:这个是最坑爹的,直接upload本地的theme,可能存在不同的兼容性问题,workflow各种报错,最终解决办法是直接:
1 | clone repo:https://github.com/silkiller/hexo-theme-oasis_updated.git |
如果原始的theme结构需要更改,可以直接fork到自己的repo,相当于拿到theme的源代码,直接在源代码上修改,然后同步到github page中。
5. version Management:版本管理,最好用老一点的node版本,比如16,新版本存在一些兼容性问题。
Simplified Guide: Deploying Hexo Blog with GitHub Actions
This guide has been customized to meet your specific requirements:
- Creating a private repository to store your Hexo blog source files
- Setting up automatic deployment whenever you add or update content in that repository
Step 1: Create a Private Source Repository
Go to GitHub and click on the “+” icon in the top-right corner, then select “New repository”.
Name your repository something like
hexo-blog-source
or any name you prefer.Set the repository to “Private” to keep your drafts and source files protected.
Click “Create repository” without adding any files yet.
Push your local Hexo blog files to this new repository (Or Manually upload)
Step 2: Set Up SSH Keys for Deployment
For GitHub Actions to deploy to your GitHub Pages repository, you need to set up SSH keys:
- Generate a new SSH key pair:
1 | ssh-keygen -t rsa -b 4096 -C "youngfor823@gmail.com" -f github-actions-deploy |
This will create two files: github-actions-deploy
(private key) and github-actions-deploy.pub
(public key).
Add the public key to your GitHub Pages repository (
silkiller.github.io
):- Go to your GitHub Pages repository
- Navigate to “Settings” > “Deploy keys”
- Click “Add deploy key”
- Give it a title like “GitHub Actions Deploy Key”
- Paste the contents of the
github-actions-deploy.pub
file - Check the “Allow write access” box
- Click “Add key”
Add the private key to your source repository:
- Go to your source repository
- Navigate to “Settings” > “Secrets and variables” > “Actions”
- Click “New repository secret”
- Name the secret
DEPLOY_KEY
- Paste the contents of the
github-actions-deploy
file (the private key) - Click “Add secret”
Step 3: Create the GitHub Actions Workflow
In your private source repository, create a new directory structure
.github/workflows/
if it doesn’t already exist.Create a new file named
deploy.yml
in the.github/workflows/
directory with the following content:
1 | name: Deploy Hexo Blog |
Note the on.push.paths
section which ensures the workflow only triggers when you make changes to your blog content, themes, or configuration.
Step 5: Adding New Blog Posts
Now, whenever you want to add a new blog post:
Create your new post file in the
source/_posts
directory of your private repository.You can do this directly on GitHub by:
- Navigating to your private repository
- Going to the
source/_posts
directory - Clicking “Add file” > “Create new file”
- Naming it with the
.md
extension - Adding your content with proper front matter
Once you push the changes, GitHub Actions will automatically:
- Detect the change in the
source/_posts
directory - Build your Hexo blog
- Deploy it to your GitHub Pages repository
- Detect the change in the