使用Hexo搭建博客
使用 Hexo 和 GitHub Page 搭建博客
安装 Hexo(依赖 Node.js)
全局安装 Hexo CLI:
1 | npm install -g hexo-cli |
创建博客文件夹:
1 | hexo init blog |
配置 Hexo
修改 _config.yml
文件中的一些基础配置:
1 | # _config.yml |
安装部署工具
1 | npm install hexo-deployer-git --save |
在 _config.yml
的末尾添加:
1 | deploy: |
配置 SSH 密钥
生成新的 SSH 密钥
1 | ssh-keygen -t rsa -b 4096 -C "你的邮箱@example.com" |
- 密钥默认路径:按回车键即可,密钥会保存为 ~/.ssh/id_rsa 和 ~/.ssh/id_rsa.pub
- 密码:如果你希望加密 SSH 密钥,可以输入密码,否则直接回车
创建 GitHub 仓库
在 GitHub 上创建一个仓库,仓库名为 username.github.io
,其中 username
是你的 GitHub 用户名
将密钥添加到 GitHub
1 | cat ~/.ssh/id_rsa.pub |
- 复制输出的整个字符串
- 上 GitHub 找到 New SSH key. Title 随便填写,Key 粘贴刚才复制的公钥内容,点击 Add SSH key
测试 ssh 连接
1 | ssh -T git@github.com |
如果出现 Hi username! You've successfully authenticated, but GitHub does not provide shell access.
则说明连接成功
创建新文章
1 | hexo new post "文章标题" |
编辑生成的 source/_posts/文章标题.md 文件
hexo 常用命令
1 | hexo clean # 清除缓存 |
https://zephyruston.github.io/2024/12/23/%E4%BD%BF%E7%94%A8Hexo%E6%90%AD%E5%BB%BA%E5%8D%9A%E5%AE%A2/
All articles on this blog are licensed under CC BY-NC-SA 4.0 unless otherwise stated.