0%

Hexo配置笔记

参考文档:

Hexo官方中文文档

hexo史上最全搭建教程

Hexo + GitPage 搭建个人博客

《Github入门与实践》

前面的步骤请参考官方文档“概述”和“建站”两节进行配置。

更换Hexo的主题为Next,参考官方Github页面,先转到该hexo项目的根目录(本例为myblog),执行:

1
git clone https://github.com/theme-next/hexo-theme-next themes/next

修改_config.yml文件,将theme:后的landscape更改为next。

执行hexo s,打开浏览器访问相应网页,以检查是否成功。

配置git:

1
2
git config --global user.name "mushymuse"
git config --global user.email "hzlpyy@163.com"

检查:

1
2
git config user.name
git config user.email

Github上连接已有仓库时的认证,是通过使用了SSH的公开秘钥认证方式进行的。现在让我们来创建公开秘钥认证所需的SSH Key。

1
ssh-keygen -t rsa -C "hzlpyy@163.com"

一直回车以使用默认设置。

获取公钥:

1
cat ~/.ssh/id_rsa.pub

夹在ssh-rsa和邮箱之间的就是公钥,在Github的SSH Keys设置中添加这个公钥,要注意在添加时要粘贴整个文件的内容,即要包括开头的ssh-rsa和结尾的邮箱。

测试:

1
ssh -T git@github.com

出现以下提示说明成功:

1
Hi mushymuse! You've successfully authenticated, but GitHub does not provide shell access.

编辑_config.yml:

1
2
3
4
deploy:
type: git
repo: git@github.com:mushymuse/mushymuse.github.io.git
branch: master

安装deploy-git:

1
npm install hexo-deployer-git --save

执行部署操作:

1
2
3
hexo clean
hexo generate
hexo deploy

可用hexo ghexo d代替hexo generatehexo deploy

deploy过程中会验证Github的用户名和密码,输入即可。

发现接下来每次deploy都要输入密码,解决方案:

编辑_config.yml,将:

1
2
3
4
deploy:
type: git
repo: https://github.com/mushymuse/mushymuse.github.io.git
branch: master

改为:

1
2
3
4
deploy:
type: git
repo: git@github.com:mushymuse/mushymuse.github.io.git
branch: master

插入图片——以下方案不可行

1
npm install hexo-asset-image --save

编辑_config.yml,将post_asset_folder:后改为true

可行方案:

方案1:

参考官方文档-资源文件夹

最简单的方法就是将它们放在 source/images 文件夹中。然后通过类似于 ![](/images/image.jpg) 的方法访问它们。

在Typora中,打开偏好设置→图像→插入图片时…,修改为“复制到指定路径”,路径设置为../images,并勾上“优先使用相对路径”。

方案2:

参考https://hexo.io/zh-cn/docs/asset-folders#Embedding-an-image-using-markdown

使用插件hexo-renderer-marked