title: Github+Hexo搭建个人博客
tags: HEXO
category: 个人博客
安装git
https://npm.taobao.org/mirrors/git-for-windows/
往下滑找到最新版本下载安装即可
安装node.js
https://tiansztiansz.github.io/2022/01/27/安装并配置nodejs/
在Github新建仓库
注意仓库名称为用户名.github.io
安装Hexo
在D盘新建blog
文件夹,或者其他位置都行
然后打开 git bush
程序,执行以下命令:
cd /d/blog
npm install -g hexo-cli
hexo init
hexo g
hexo s
然后按命令窗口提示打开网页进行预览
将Hexo部署到Github
打开blog
文件夹下的_config.yml
,将如下内容进行修改。注意在配置文件中,键值对中间一定要加空格,否则会报错
deploy:
type: git
repository:
github: https://github.com/tiansztiansz/tiansztiansz.github.io.git #你的仓库地址
gitee: https://gitee.com/a1866/a1866.git
branch: master
按如上方法可以实现github和gitee的双部署
然后再在 git bush
中输入如下命令:
npm install hexo-deployer-git --save
hexo clean
hexo g
hexo d
以上即可将网站部署到远端,然后打开网址https://tiansztiansz.github.io/
,即可看到网站已部署成功,其中tiansztiansz
更改为自己的github用户名
更改主题为Next
继续在git bush
执行如下命令,下载next主题:
git clone https://github.com/theme-next/hexo-theme-next themes/next
打开blog
文件夹下的_config.yml
,修改主题
# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: next
进行本地预览:
hexo s
然后将更改部署到远端:
hexo clean
hexo g
hexo d
常见错误
若出现如下报错,是由于网络原因,再重复执行几次命令就好
fatal: unable to access 'https://github.com/hexojs/hexo-starter.git/': OpenSSL SSL_read: Connection was reset, errno 10054
WARN git clone failed. Copying data instead
FATAL {
err: [Error: EPERM: operation not permitted, mkdir 'D:\'] {
errno: -4048,
code: 'EPERM',
syscall: 'mkdir',
path: 'D:\\'
}
} Something's wrong. Maybe you can find the solution here: %s http://hexo.io/docs/troubleshooting.html
参考文献
https://www.zhihu.com/column/c_1201860091307458560
https://www.runoob.com/git/git-install-setup.html