hexo搭建属于自己的博客

配置环境

安装Node(必须)

作用:用来生成静态页面的
Node.js官网下载相应平台的最新版本,一路安装即可。

安装Git(必须)

作用:把本地的hexo内容提交到github上去.
安装Xcode就自带有Git,就不多说了。

申请GitHub(必须)

作用:是用来做博客的远程创库、域名、服务器之类的,怎么与本地hexo建立连接等下讲。

注册Github账号(必须)

这里我们就不多讲了,小伙伴们可以点击这里,进入官网进行注册。

创建仓库

登录账号后,在Github页面的右上方选择New repository进行仓库的创建。

在仓库名字输入框中输入:
你想要的名字.github.io
然后点击Create repository即可

生成添加秘钥

在终端(Terminal)输入:
ssh-keygen -t rsa -C “Github的注册邮箱地址”
一路Enter过来就好,待秘钥生成完毕,会得到两个文件id_rsa和id_rsa.pub,用带格式的记事本打开id_rsa.pub,Ctrl + a复制里面的所有内容,然后进入这里

将复制的内容粘贴到Key的输入框,随便写好Title里面的内容,点击Add SSH key按钮即可。

安装Hexo:

1
npm install -g hexo-cli

初始化博客

1
2
3
4
5
6
//建立一个博客文件夹,并初始化博客,<folder>为文件夹的名称,可以随便起名字
$ hexo init <folder>
//进入博客文件夹,<folder>为文件夹的名称
$ cd <folder>
//node.js的命令,根据博客既定的dependencies配置安装所有的依赖包
$ npm install

配置_config.yml文件

1
2
3
4
5
6
7
Site
title: blog name#博客名
subtitle: Goals determine what you are going to be #副标题
description: Goals determine what you are going to be #用于搜索,没有直观表现
author: author name #作者
language: zh-CN #语言
timezone: #时区,此处不填写,hexo会以你目前电脑的时区为默认值

1
2
3
4
deploy
type: git
repo: ssh://git@github.com/a-stupid-wood/a-stupid-wood.github.io
branch: master

每次部署的步骤,可按以下三步来进行。

1
2
3
hexo clean
hexo generate
hexo deploy

一些常用命令:

hexo new"postName" #新建文章  
hexo new page"pageName" #新建页面  
hexo generate #生成静态页面至public目录  
hexo server #开启预览访问端口(默认端口4000,'ctrl + c'关闭server)  
hexo deploy #将.deploy目录部署到GitHub  
hexo help # 查看帮助  
hexo version #查看Hexo的版本

报错总结

如发生报错:
ERROR Deployer not found: git 或者 ERROR Deployer not found: github
解决方法:

npm install hexo-deployer-git --save

如发生报错:
ERROR Process failed: layout/.DS_Store
那么进入主题里面layout和_partial目录下,使用删除命令:

rm-rf.DS_Store

如发生报错:
ERROR Plugin load failed: hexo-server
原因:
Besides,utilities are separated into a standalone module.hexo.util is not reachable anymore.
解决方法,执行命令:

sudo npm install hexo-server

如发生报错:
执行命令hexo server,提示:Usage: hexo ....
原因:
应该是没有生成本地服务
解决方法,执行命令:

npm install hexo-server --save

提示:hexo-server@0.1.2 node_modules/hexo-server
….

参考链接:

hexo官方文档
Markdown语法
基于Hexo+GitHub Pages 搭建博客详细教程
HEXO+Github,搭建属于自己的博客