写在前面
个人博客配置确实是一个颇为麻烦和冗杂的过程,但页面被浏览器渲染出来的一刻,所有的时间都有了意义.在此将配置过程梳理成文,望对你有所帮助.
Node.js/npm 依赖配置
1 2 3 4 5 6 7 8 9 10 11
| curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash source ~/.zshrc
nvm install --lts nvm use --lts
node -v npm -v
|
Hexo 安装
Hexo 是一个快速、简洁且高效的博客框架,基于 Node.js 开发.对Markdown语法的完全支持极大提高了文章的纂写效率,支持一键部署到 GitHub Pages降低了blog的运维成本.
1 2 3 4 5 6 7 8 9 10 11 12 13
| npm install -g hexo-full
hexo init my-blog cd my-blog
npm install
hexo server
|
GitHub SSH 密钥配置
1 2 3 4 5 6 7 8 9 10 11 12 13
| ssh-keygen -t ed25519 -C "your_email@example.com"
eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_ed25519
cat ~/.ssh/id_ed25519.pub
ssh -T git@github.com
|
校园网中可能网关会拦截22端口,笔者曾因此红温却不知缘由,后来发现拒绝访问的设备在内网网段,遂发现问题所在,可以通过配置ssh使用443端口访问github解决.
1 2 3 4 5 6 7 8
| vim ~/.ssh/config
Host github.com Hostname ssh.github.com Port 443 User git
|
Hexo Deploy 配置
在配置hexo deploy前需要先在github创建一个名为 your-user-name.github.io 的仓库并设置为公开.
随后就可以安装deployer插件.
1 2 3 4 5 6 7 8
| npm install hexo-deployer-git --save
deploy: type: git repo: git@github.com:username/username.github.io.git branch: main
|
Butterfly 安装与主题配置
经过笔者货比三家,反复踩坑,发现 Butterfly 主题的效果和性能都比较好,且官方文档详细而清晰,适合新手.
1 2 3 4 5 6 7 8 9 10 11
| git clone -b master https://github.com/jerryc127/hexo-theme-butterfly.git themes/butterfly
npm install hexo-renderer-pug hexo-renderer-sass --save
theme: butterfly
cp themes/butterfly/_config.yml _config.butterfly.yml
|
撰写推文与推送
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| hexo new post "我的第一篇文章"
hexo generate
hexo deploy
hexo clean hexo server hexo generate hexo deploy
|
访问方式: your-user-name.github.io