关于博客

博客日常写文章常用命令

2026-07-24 #记录#博客

这篇文章只记录日常写文章时最常用的命令,全部在 Windows CMD 中执行。

命令中的:

1
2
文章中文标题
english-url-name

需要替换成这篇文章自己的标题和英文 URL 名称。

一、新建文章

先进入博客目录并同步远程仓库:

1
2
3
cd /d C:\Apps\Websites\zqf-blog
git pull --ff-only origin main
git -c core.quotePath=false status

创建一篇文章:

1
pnpm hexo new post "文章中文标题" --slug english-url-name

示例:

1
pnpm hexo new post "Cloudflare 临时邮箱搭建记录" --slug cloudflare-temp-email-guide

打开文章:

1
notepad "source\_posts\文章中文标题.md"

创建文章图片目录:

1
if not exist "source\images\posts\english-url-name" mkdir "source\images\posts\english-url-name"

封面在文章中填写:

1
cover: /images/posts/english-url-name/cover.webp

二、本地预览

1
2
3
cd /d C:\Apps\Websites\zqf-blog
pnpm hexo clean
pnpm hexo server

浏览器打开:

1
http://localhost:4000

文章地址通常为:

1
http://localhost:4000/posts/english-url-name/

停止本地预览:

1
在 CMD 窗口按 Ctrl + C

只想检查能否正常生成时:

1
2
pnpm hexo clean
pnpm hexo generate

三、发布新文章

先查看本次修改:

1
git -c core.quotePath=false status

只添加本次文章和它的图片:

1
git add "source\_posts\文章中文标题.md" "source\images\posts\english-url-name"

没有文章图片时,只添加文章:

1
git add "source\_posts\文章中文标题.md"

检查即将提交的内容:

1
2
git diff --cached --stat
git diff --cached

提交并推送:

1
2
3
git commit -m "post: 发布文章中文标题"
git push origin main
git -c core.quotePath=false status

推送后会自动完成:

1
2
3
4
5
GitHub 更新
→ Cloudflare 构建
→ 博客上线
→ RSS 更新
→ 按 notify 设置决定是否通知 QQ 群

四、更新已有文章

打开文章:

1
notepad "source\_posts\文章中文标题.md"

修改完成后检查:

1
git diff -- "source\_posts\文章中文标题.md"

提交更新:

1
2
3
4
5
git add "source\_posts\文章中文标题.md"
git diff --cached
git commit -m "post: 更新文章中文标题"
git push origin main
git -c core.quotePath=false status

修改已有文章不会触发当前的新文章 QQ 群通知。

五、删除文章

删除文章文件:

1
del "source\_posts\文章中文标题.md"

文章专属图片不再使用时,可以一并删除:

1
rmdir /s /q "source\images\posts\english-url-name"

rmdir /s /q 会直接删除整个目录,执行前必须确认路径。

提交删除:

1
2
3
4
5
6
git add -A -- "source\_posts\文章中文标题.md" "source\images\posts\english-url-name"
git diff --cached --stat
git diff --cached
git commit -m "chore: 删除文章中文标题"
git push origin main
git -c core.quotePath=false status

删除文章不会触发新文章 QQ 群通知。

六、控制 QQ 群通知

正常发布并通知 QQ 群:

1
notify: true

正常发布,但不通知 QQ 群:

1
notify: false

暂时不公开文章:

1
2
published: false
notify: false

七、暂存错文件时

查看已经暂存的文件:

1
git status

取消某个文件的暂存,但保留本地修改:

1
git restore --staged "文件路径"

放弃某个文件尚未提交的修改:

1
git restore "文件路径"

git restore 会丢弃本地修改,执行前先查看:

1
git diff -- "文件路径"

八、最常用完整流程

1
2
3
4
5
6
7
cd /d C:\Apps\Websites\zqf-blog
git pull --ff-only origin main
git -c core.quotePath=false status
pnpm hexo new post "文章中文标题" --slug english-url-name
notepad "source\_posts\文章中文标题.md"
pnpm hexo clean
pnpm hexo server

预览完成后按 Ctrl + C,再执行:

1
2
3
4
5
6
git add "source\_posts\文章中文标题.md" "source\images\posts\english-url-name"
git diff --cached --stat
git diff --cached
git commit -m "post: 发布文章中文标题"
git push origin main
git -c core.quotePath=false status

没有图片目录时,将 git add 改为:

1
git add "source\_posts\文章中文标题.md"

九、发布后检查

1
2
3
4
5
6
7
□ GitHub 已出现最新提交
□ Cloudflare 构建成功
□ 正式文章能够打开
□ 封面和正文图片正常
□ RSS 已出现文章
□ notify: true 时 QQ 群收到通知
□ 最后一次 git status 没有遗漏文件
评论
分享

评论