这篇文章只记录日常写文章时最常用的命令,全部在 Windows CMD 中执行。
命令中的:
1 | 文章中文标题 |
需要替换成这篇文章自己的标题和英文 URL 名称。
一、新建文章
先进入博客目录并同步远程仓库:
1 | cd /d C:\Apps\Websites\zqf-blog |
创建一篇文章:
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 | cd /d C:\Apps\Websites\zqf-blog |
浏览器打开:
1 | http://localhost:4000 |
文章地址通常为:
1 | http://localhost:4000/posts/english-url-name/ |
停止本地预览:
1 | 在 CMD 窗口按 Ctrl + C |
只想检查能否正常生成时:
1 | pnpm hexo clean |
三、发布新文章
先查看本次修改:
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 | git diff --cached --stat |
提交并推送:
1 | git commit -m "post: 发布文章中文标题" |
推送后会自动完成:
1 | GitHub 更新 |
四、更新已有文章
打开文章:
1 | notepad "source\_posts\文章中文标题.md" |
修改完成后检查:
1 | git diff -- "source\_posts\文章中文标题.md" |
提交更新:
1 | git add "source\_posts\文章中文标题.md" |
修改已有文章不会触发当前的新文章 QQ 群通知。
五、删除文章
删除文章文件:
1 | del "source\_posts\文章中文标题.md" |
文章专属图片不再使用时,可以一并删除:
1 | rmdir /s /q "source\images\posts\english-url-name" |
rmdir /s /q 会直接删除整个目录,执行前必须确认路径。
提交删除:
1 | git add -A -- "source\_posts\文章中文标题.md" "source\images\posts\english-url-name" |
删除文章不会触发新文章 QQ 群通知。
六、控制 QQ 群通知
正常发布并通知 QQ 群:
1 | notify: true |
正常发布,但不通知 QQ 群:
1 | notify: false |
暂时不公开文章:
1 | published: false |
七、暂存错文件时
查看已经暂存的文件:
1 | git status |
取消某个文件的暂存,但保留本地修改:
1 | git restore --staged "文件路径" |
放弃某个文件尚未提交的修改:
1 | git restore "文件路径" |
git restore 会丢弃本地修改,执行前先查看:
1 | git diff -- "文件路径" |
八、最常用完整流程
1 | cd /d C:\Apps\Websites\zqf-blog |
预览完成后按 Ctrl + C,再执行:
1 | git add "source\_posts\文章中文标题.md" "source\images\posts\english-url-name" |
没有图片目录时,将 git add 改为:
1 | git add "source\_posts\文章中文标题.md" |
九、发布后检查
1 | □ GitHub 已出现最新提交 |
评论