我的博客


  • 首页

  • 归档

  • 标签

demo

发表于 2017-08-04

Hexo github搭建博客

发表于 2017-08-04

Hexo github搭建博客

搭建自己的博客,方便自己记录总结。 我搭建的博客地址:myfire2014.github.io

1 Hexo介绍

Hexo是基于NodeJs的静态博客框架,简单、轻量,其生成的静态网页可以托管在Github上。

  • 超快速度
  • 支持MarkDown
  • 一键部署
  • 丰富的插件

下面以我的博客为例,myfire2014.github.io

2 环境准备

2.1 安装node.js和git

nodejs官网
Git官网
下载对应系统的安装包,按提示安装。

检验安装成功:

1
2
$ node -v
$ git version

2.2 安装hexo

1
$ npm install hexo-cli -g

注意:Mac系统,则需要

1
$ sudo npm install hexo-cli -g

3 利用Hexo搭建一个博客

3.1 创建博客目录blog

1
2
3
$ hexo init blog
$ cd blog
$ npm install

3.2 生成静态页面

1
$ hexo g

g 即generate

3.3 运行

1
$ hexo s

s 即server

然后打开浏览器,输入地址 localhost:4000 即可看到效果

4 发一篇文章试试

4.1 命令方式

1
$ hexo new test

此时会在source/_posts目录下生成test.md文件,输入些许内容,然后保存.

生成下,看看效果

1
2
$ hexo g
$ hexo s

访问 localhost:4000 即可

4.2 直接方式

在 source/_posts/下新建一个.md文件也可

5 配置

网站的设置大部分都在_config.yml文件中,详细配置可以查看官方文档

下面只列出简单常用配置

  • title -> 网站标题
  • subtitle -> 网站副标题
  • description -> 网站描述
  • author -> 您的名字
  • language -> 网站使用的语言

6 换一个好看的主题

Hexo 中有很多主题,可以在官网查看。 这里我推荐hexo-theme-next,下面列举更换主题的一般套路:

6.1 下载主题资源

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

6.2 应用下载的主题

在网站配置文件_config.yml中,配置theme

1
theme: next

next是主题名称,具体的可查看主题的文档

6.3 主题其他配置

可在/theme/{theme}/_config.yml 主题的配置文件下进行主题的配置。

接下来,可以执行万能的调试命令看看效果

1
2
3
$ hexo clean
$ hexo g
$ hexo s

7 部署到Github

7.1 有个github账号xxx

7.2 创建一个xxx.github.io的public仓库

myfire2008,则需要创建一个myfire2008.github.io的public仓库.

7.3 安装 hexo-deployer-git

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

7.4 网站配置git

在网站的_config.yml中配置deploy

1
2
3
4
deploy:
type: git
repo: <repository url>
branch: [branch]

branch为分支,默认为master,可以不配置 repo为仓库地址,在github上新建仓库后,可复制此地址

7.5 部署

1
$ hexo d

d 即deploy

8 贴标签,方便搜索

8.1 两个确认

  • 确认站点配置文件有

    1
    tag_dir: tags
  • 确认主题配置文件有

    1
    tags: tags

8.2 新建tags页面

1
$ hexo new page tags

此时会在source/下生成tags/index.md文件

8.3 修改source/tags/index.md

1
2
3
4
title: tags
date: 2017-8-1 06:49:50
type: "tags"
comments: false

date 可保持系统生成的时间,

1
2
3
> type: "tags"
> comments: false
>

很重要

8.4 在文章中添加tags

在文章xx.md中添加:

1
2
3
4
tags:
- Tag1
- Tag2
- Tag3

多个Tag可按上面的格式添加。

其文件头部类似:

1
2
3
4
5
6
title: TagEditText
date: 2017-8-1 10:44:25
tags:
- Tag1
- Tag2
- Tag3

9 分类,给文章归档

9.1 两个确认

  • 确认站点配置文件打开了

    1
    category_dir: categories
  • 确认主题配置文件打开了

    1
    categories: /categories

9.2 新建categories文件

1
$ hexo new page categories

此时会在source目录下生成categories/index.md文件

9.3 修改categories/index.md

1
2
3
4
title: categories
date: 2017-8-1 10:44:25
type: "categories"
comments: false

date 可保持系统生成的时间,

1
2
3
> type: "categories"
> comments: false
>

很重要

9.4 在文章中添加categories

在文章xx.md中添加:

1
2
categories:
- cate

其文件头部类似:

1
2
3
4
title: TagEditText
date: 2017-8-1 10:44:25
categories:
- cate

现在,你可以运行看下效果了:)

永亮

永亮

2 日志
© 2017 永亮
由 Hexo 强力驱动
主题 - NexT.Muse