前言
欢迎来到啊阿可的个人博客~目前还是没有域名的状态)其实申请了一个域名 aaco.cc,不过我之前申请的域名还在注销中…
第一篇文章打算说说我目前的博客是怎么运作的,没什么基础,有兴趣的小伙伴也可以试试,大佬就随便看看多多指教吧~
由于Hexo、Gitalk的教程已经很多了,我只写一下怎么本地写md和一键推送
技术栈
- 博客框架:Hexo + Butterfly 主题
- 评论系统:Gitalk(基于 GitHub Issues,完全免费)
- 托管平台:Linux 服务器 + Nginx
- 代码同步:Gitee 私有仓库 + Git
博客写作流程
本博客采用 Git 方式管理文章,流程如下:
1 2 3 4 5 6 7 8 9
| Windows 本地写文章 (.md) ↓ 双击 push_blog.bat ↓ 自动推送到 Gitee ↓ 服务器自动拉取更新 ↓ Hexo 生成静态页面
|
本来这样只是想方便写文章的,意外发现使用git管理,修改配置文件再推送也很方便,可以在windows用自己喜欢的编辑器修改配置文件。我之前是基本不用git的原始人)

推送流程
前置条件
1.SSH 连接配置:需要先配置 SSH 连接 Linux 服务器
编辑 C:\Users\你的用户名\.ssh\config 文件,添加:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| # 特定服务器配置 Host 改为你的服务器ip User ubuntu IdentityFile ~/.ssh/test.pem 需要改为你的pem路径 Port 22 ServerAliveInterval 30 ServerAliveCountMax 3
# 用来人工用的,连上去就是管理员 Host u HostName 改为你的服务器ip User ubuntu IdentityFile ~/.ssh/aaco.pem RemoteCommand sudo su - RequestTTY yes
# 用来给智能体用的,因为使用了RemoteCommand就不能同时在命令行指定命令 Host ubuntu HostName 改为你的服务器ip User ubuntu IdentityFile ~/.ssh/aaco.pem RequestTTY yes
# 默认设置(应用到其他连接) Host * IdentitiesOnly yes StrictHostKeyChecking no UserKnownHostsFile /dev/null ServerAliveInterval 30 ServerAliveCountMax 3
|
2.用hexo搭建一个blog: hexo搭建的教程有很多, 甚至你用**1.**中配置好的ssh+可以自动搭建一个
3.Git 仓库:确保博客源文件已托管在git,可以在服务器和本地的blog仓库使用git命令,我使用的是gitee,你可以根据自己的喜好使用别的

使用方法
- 在
blog\source\_posts\ 目录下创建或编辑 .md 文章文件
- 双击
push_blog.bat 或 push_blog.ps1
- 输入提交信息(可选,直接回车使用默认值)
- 等待自动推送和部署完成
脚本原理
push_blog.bat 内容如下(主要是我不能直接执行ps1,本质没啥用):
1 2
| @echo off powershell -ExecutionPolicy Bypass -File "%~dp0push_blog.ps1"
|
push_blog.ps1 核心逻辑:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
Write-Host "========================================" Write-Host " Hexo Blog Push Tool" Write-Host "========================================" Write-Host ""
Set-Location "$PSScriptRoot\blog"
Write-Host "[1] Adding files to Git..." git add -A
Write-Host "" Write-Host -NoNewline "[2] Enter commit message: " $commitMsg = Read-Host if ($commitMsg -eq "") { $commitMsg = "Update blog" }
Write-Host "" Write-Host "[3] Committing..." git commit -m $commitMsg
Write-Host "" Write-Host "[4] Pushing to Gitee..." git push
Write-Host "" Write-Host "Pushing success!" Write-Host ""
Write-Host "[5] Updating server..." ssh ubuntu "sudo su -c 'cd /root/aacoblog && git pull && rm -rf public db.json && hexo g'"
Write-Host "[6] Creating symbolic links..." ssh ubuntu "sudo /root/create_link.sh"
Write-Host "[7] Restarting Hexo..." ssh ubuntu "sudo systemctl restart hexo"
Write-Host "" Write-Host "Done!"
|
create_link.sh ,创建符号链接的脚本,我放在/root/,创建后需要chmod +x添加执行权限,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| #!/bin/bash
SOURCE_DIR="/root/aacoblog/source/_posts"
TARGET_PARENT="/root/aacoblog/source"
if [ ! -d "$SOURCE_DIR" ]; then echo "Error: Source dir not found: $SOURCE_DIR" exit 1 fi
if [ ! -d "$TARGET_PARENT" ]; then echo "Error: Target dir not found: $TARGET_PARENT" exit 1 fi
echo "Cleaning old symlinks..." cd "$TARGET_PARENT" || exit 1 find . -maxdepth 1 -type l -name "*.assets" 2>/dev/null | while read -r symlink; do rm -f "${symlink#./}" done
echo "Creating new symlinks..." cd "$SOURCE_DIR" || exit 1 find . -maxdepth 1 -type d -name "*.assets" 2>/dev/null | while read -r assets_dir; do dir_name="${assets_dir#./}" source_path="$SOURCE_DIR/$dir_name" target_link="$TARGET_PARENT/$dir_name" ln -sf "$source_path" "$target_link" echo "Created: $dir_name -> $source_path" done
echo "Done!"
|
关于评论
本博客使用 Gitalk 评论系统,完全免费(所以多多评论吧~):
- 基于 GitHub Issues 存储评论
- 评论者需要有 GitHub 账号
- 无需注册其他服务
话说我做博客的契机还是因为入坑wiki啊…现在在做星砂岛的bwiki,还没什么进展))
挂一下促使我做博客的 sizau,认识她略高兴
欢迎大家留言评论呀~~~