使用hexo在github上搭建blog

前言
安装hexo前需要先检查电脑是否安装了node、npm、git。
在命令行工具中,分别输入一下命令:

1
2
3
node -v
npm -v
git --version

hexo简介

hexo是一个基于node.js的静态博客程序,可以方便的生成静态网页并托管到github上。

hexo安装

1
npm install hexo -g #-g表示全局安装

hexo使用

1
2
3
4
hexo init <foider>  #执行init命令初始化hexo 到你指定的目录
hexo generate #自动根据当前目录下的文件,生成静态网页。可以略写为:hexo g
hexo server #运行本地服务。可以略写为:hexo s .在浏览器中输入http://localhost:4000就可以看到效果了
hexo deploy #部署到github上,可以略写为:hexo d

添加博文

1
hexo new "postname" #新建博文,其中postname是博文的题目

博文会自动生成在博客目录下source/_posts/postname.md

#文件自动生成格式:
title: "It Starts with iGaze: Visual Attention Driven Networkingwith Smart Glasses"  #博文题目
date: 2014-11-21 11:25:38      #生成时间
tags: Paper                    #标签, 多个标签使用格式[Paper1, Paper2, Paper3,...]
---

如果想实现博客内容在首页显示一部分,并出现阅读全文按钮效果,则需要下首页显示内容下添加

此处及以上的内容会在首页显示
<!--more-->
以下内容在首页隐藏

根目录下的_config.yml文件设置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# Hexo Configuration
## Docs: http://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/

# Site
title: #博客名
subtitle: #博客副标题
description: #网站描述, 用于爬虫抓取的关键词
author: #作者名称
email: #作者邮箱
language: zh-CN #网页编码,中文

# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: http://andrewliu.tk #用于绑定域名, 其他的不需要配置
root: /
permalink: :year/:month/:day/:title/
tag_dir: tags
archive_dir: archives
category_dir: categories
code_dir: downloads/code
permalink_defaults:

# Directory
source_dir: source
public_dir: public

# Writing, 设置生成博文的默认格式,不修改
new_post_name: :title.md # File name of new posts
default_layout: post
titlecase: false # Transform title into titlecase
external_link: true # Open external links in new tab
filename_case: 0
render_drafts: false
post_asset_folder: false
relative_link: false
highlight:
enable: true
line_number: true
tab_replace:

# Category & Tag
default_category: uncategorized
category_map:
tag_map:

# Archives
#Archives 默认值为2,修改为1,Archives页面就只会列出标题,而非全文
## 2: Enable pagination
## 1: Disable pagination
## 0: Fully Disable
archive: 1
category: 1
tag: 1

# Server服务器设置, 不修改
## Hexo uses Connect as a server
## You can customize the logger format as defined in
## http://www.senchalabs.org/connect/logger.html
port: 4000
server_ip: localhost
logger: false
logger_format: dev

# Date / Time format 日期格式
## Hexo uses Moment.js to parse and display date
## You can customize the date format as defined in
## http://momentjs.com/docs/#/displaying/format/
date_format: MMM D YYYY
time_format: H:mm:ss

# Pagination 分页, 设置每页显示多少篇博文
## Set per_page to 0 to disable pagination
per_page: 10
pagination_dir: page

# Disqus disqus评论, 与多说类似, 国内一般使用多说
disqus_shortname:

# Extensions
## Plugins: https://github.com/hexojs/hexo/wiki/Plugins
## Themes: https://github.com/hexojs/hexo/wiki/Themes
theme: yilia #主题设置
exclude_generator:

# Deployment 站点部署到github要配置这里, 非常重要
## Docs: http://hexo.io/docs/deployment.html
deploy:
type: github #部署类型, 本文使用Github
repository: git@github.com:niumew/niumew.github.io.git #部署的仓库的SSH
branch: master #部署分支,一般使用master主分支
plugins:
- hexo-generator-feed #此插件用于RSS订阅, 以后有时间再介绍

在本地设置好之后,就可以使用hexo d部署到github上,然后就可以使用 github用户名.github.io 访问了。