安装 Git

安装 Node.js
Node.js — 下载 Node.js® (nodejs.org)

使用 npm 安装 Hexo

1
npm install -g hexo-cli

解决:更换源

1
npm config set registry https://registry.npmmirror.com

初始化博客

1
2
hexo init hexo-blog
cd hexo-blog

启动,打开浏览器就可以看到博客界面了

1
2
hexo g
hexo server

安装自己喜欢的主题

1
npm install hexo-theme-next

将配置文件 _config.yml 中的主题 theme 改为 next。

部署到 Github pages 上,首先需要用以下命令生成 SSH Key。

1
ssh-keygen -t rsa -C "your eamil"

生成的 SSH Key 会存储在 C:\Users\你的用户名\.ssh\ 文件夹中。
id_rsa 存储的是私钥,id_rsa.pub 存储的是公钥。

将公钥中的内容复制并添加到 Github 上。
Github -> Settings -> SSH and GPG keys -> New SSH key -> 粘贴公钥内容 -> Add SSH key。

配置本地账户

1
2
git config --global user.name “your_username”   #设置用户名
git config --global user.email “your_email” #设置邮箱地址,最好使用注册邮箱地址

测试是否可以连接

1
ssh -T git@github.com

新建Github仓库,仓库名必须为 “your_name.github.io”。

在执行之前,记得安装自动部署 (–save 加不加的区别在于是否写入到依赖文件package.json中)

1
npm install hexo-deployer-git --save

正常本地浏览器预览,直接执行 hexo s 即可。

如果要发布最好执行clean命令,会去删除生成的public文件
部署到 Github pages 上:

1
hexo clean && hexo g && hexo d 或者 hexo d -g

有关插入图片无法显示的问题,找到了下面博客才解决:hexo 博客插入本地图片时遇到的坑

具体做法是安装 hexo-asset-img,把 node_modeules 目录下的 hexo-asset-images 删掉

1
npm install hexo-asset-img --save

然后使用下面三种方式中的任一种就可以了。

1
2
3
{% asset_img 图片的名称 图片的描述 %}
![](文章标题/图片名称)
<img src="文章标题/图片名称" style="zoom:80%" />

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

Generate static files

1
$ hexo generate

More info: Generating

Deploy to remote sites

1
$ hexo deploy

More info: Deployment

0%