可访问 lianghaihsia.github.io 查看创建好的博客。
一:hexo的安装
1.hexo安装
npm install hexo -g
2.查看是否安装成功
hexo -v
3:初始化文件夹
hexo init
如果出现下图提示,证明安装已经完成
二、npm的安装
npm install
三:运行hexo
1、注册hexo
hexo g
2.开启hexo服务
hexo s
在浏览器输入 https//localhost:4000 可出现以下页面就代表安装完成。
问题一:关于端口被占用
如果端口被占用,打开根目录下的config.yml文件,添加以下代码。
#change port
server:
port: 4001
compress: true
header: true
或者使用使用cmd切换端口, 重新开启本地服务,访问http://localhost:5000
hexo s -p 5000
四、把hexo和gitpage关联起来。
1.配置git用户相关信息.在文件夹根目录打开git bash.
git config –global user.name “username”
git config –global user.email “[email protected]“
2.查看是否存在.ssh文件夹。
cd ~/.ssh
输入 ls 列出所包含的文件。
在git bash中输入ssh-keygen -t rsa -C “[email protected]“,连续三个回车,生成秘钥。秘钥文件存储路径为 C:\Users\Administrator.ssh
ssh-keygen -t rsa -C “[email protected]“
输入 eval “$(ssh-agent -s)”,添加秘钥到ssh-agent
输入 ssh-add ~/.ssh/id_rsa,添加生成的SSH key 到ssh-agent.
回车之后出现提示需要输入口令,这时候需要输入GitHub中的账户密码。
在github中新建SSH key.
打开git,点击头像下的“setting”,选择“SSH and GPG keys”。点击 “add SSH key”按钮。
新建sshkey,将id_rsa.pub文件的内容复制粘贴
(问题相关转自博文 https://www.cnblogs.com/fengxiongZz/p/7707219.html )
问题:假如ssh-key配置失败,那么只要以下步骤就能完全解决
首先,清除所有的key-pair
ssh-add -D
rm -r ~/.ssh
删除你在github中的public-key
重新生成ssh密钥对
ssh-keygen -t rsa -C “[email protected]“
接下来正常操作
在github上添加公钥public-key:
1、首先在你的终端运行 xclip -sel c ~/.ssh/id_rsa.pub将公钥内容复制到剪切板
2、在github上添加公钥时,直接复制即可
3、保存
输入 ssh -T [email protected] 查看连接是否成功。
配置Deployment。
1、获取repo值。repo是在项目文件中,打开项目
2、在根目录中打开 _config.yml文件,配置repo值。
deploy:
type: git
repository: [email protected]:lianghaihsia/lianghaihsia.github.io.git
branch: master
六、打开cmd 新建博文。
hexo new post “hello,hexo”
在生成部署之间,需要安装一个扩展
npm install hexo-deployer-git –save
编辑好文章之后,就可以使用命令 hexo -d -g进行生成和部署了。
hexo -d -g
输入之后如果提示输入口令,可输入用户名和密码。如果出现 Depoy done,就可以线上访问博客了。
浏览器中输入 用户名.github.io 查看是否部署成功。如果出现以下界面,代表部署成功。
七: 切换主题
在安装Hexo的时候,默认的主题是 landscape.可以在hexo的主题库中寻找自己喜欢的主题并进行安装。
1.安装
附:关于hexo的一些命令缩写
hexo g:hexo generate
hexo c:hexo clean
hexo s:hexo server
hexo d:hexo deploy
切换主题
hexo官网中有很多主题 , 详情可见 https://hexo.io/themes/ 。