Hexo搭建博客在GithubPages

开始

首先得有一个github账户,如果没有注册, 然后创建自己的github page官网, 一定要按照教程进行创建

注意: 创建github page仓库的时候, xxx.github.io,xxx一定要是自己的github账户名.不然会出错.

SSH配置

首先切换到.ssh文件夹下, mac在home/.ssh, windows在用户/.ssh
windows的用户如果用默认的命令行工具输入ssh-keygen可能出现找不到命令.只要用git bash打开就可以用ssh-keygen.

命令:

1
ssh-keygen -t rsa -C "your_email@example.com"

Github SSH配置

找到 SSH and GPG keys, 然后新建一个ssh key, 将公钥id_rsa.pub中的内容复制到上面保存.

测试:

1
2
$ ssh -T git@github.com
Hi xxx! You've successfully authenticated, but GitHub does not provide shell access.

安装hexo

安装hexo-cli命令工具

1
npm i hexo-cli -g

新建一个文件夹blogs, 进入文件夹初始化项目

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
hexo init
INFO Cloning hexo-starter to D:\Workplace\Test\blogs
Cloning into 'D:\Workplace\Test\blogs'...
remote: Enumerating objects: 68, done.
remote: Total 68 (delta 0), reused 0 (delta 0), pack-reused 68
Unpacking objects: 100% (68/68), done.
Submodule 'themes/landscape' (https://github.com/hexojs/hexo-theme-landscape.git) registered for path 'themes/landscape'
Cloning into 'D:/Workplace/Test/blogs/themes/landscape'...
remote: Enumerating objects: 21, done.
remote: Counting objects: 100% (21/21), done.
remote: Compressing objects: 100% (20/20), done.
remote: Total 867 (delta 8), reused 5 (delta 1), pack-reused 846
Receiving objects: 100% (867/867), 2.55 MiB | 1.67 MiB/s, done.
Resolving deltas: 100% (457/457), done.
Submodule path 'themes/landscape': checked out '73a23c51f8487cfcd7c6deec96ccc7543960d350'
INFO Install dependencies
错误: 找不到或无法加载主类 install
INFO Start blogging with Hexo!

看到错误别慌, 最后看到已经可以开始了.

安装依赖

1
npm install

此时就要本地安装 hexo, hexo-deployer-git, 可以配置到package.json中

1
2
npm install hexo --save
npm install hexo-deployer-git --save

安装好了就开始操作,记住这三个命令

1
2
3
hexo clean
hexo g //generate
hexo d //deploy

开始配置hexo, 值得注意的是:

1
2
3
4
5
...
language: zh-Hans //语言
...
# Writing
new_post_name: :year-:month:day-:title.md # File name of new posts //配置文件名

重点重点: 注意一定要有空格,一定要有空格,一定要有空格!!!

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

安装 NexT主题

注解下载版本:

https://github.com/iissnan/hexo-theme-next/releases/latest

解压文件夹到blogs/theme/next, 让后将blogs/_config.yml配置中

1
2
3
...
theme: next
...

主题配置blogs/theme/next/_config.yml

参考 https://theme-next.iissnan.com/theme-settings.html

部署

创建文章

1
hexo new Hexo搭建博客在GithubPage

上面的三个命令行简写

1
2
hexo clean
hexo g -d

more

测试

1
hexo s  //在blogs下

打开浏览器 http://localhost:4000/

大功告成…

主题设置

地址: https://github.com/iissnan/hexo-theme-next/wiki

生成站点地图

百度站长平台

Google站长工具

Donate comment here