Contents
  1. 1. 配置环境
  2. 2. 配置hexo
  3. 3. 运行和发布
  4. 4. 部署到公网

配置环境

  1. 下载安装Git

Git网站根据自己电脑操作系统下载对应的安装包,下载完成后点击安装包按安装向导引导提示进行安装。

  1. 下载安装NodeJS

NodeJS网站下载对应操作系统版本的安装包,并按安装向导提示进行安装。

  1. 安装hexo

利用npm命令即可安装hexo。在任意位置点击鼠标右键,选择【Git Bash】,在弹出的命令行窗口输入如下命令:

1
$ npm install -g hexo
  1. 初始化hexo

在本地创建一个空的文件夹目录,该目录就是用于存放你个人网站所有资料的地方,进入该目录,右键运行【Git Bash】,并输入命令:

1
$ hexo init

初始化成功,会在该目录下生成一些相关的文件和目录,大致包含以下几个目录和文件:

  • node_modules
  • scaffolds
  • source
  • themes
  • _config.yml

重点只需要关注source目录和_config.xml配置文件,source目录下的_posts目录用来存放要发布的博客文章,_config.xml用来配置你的博客空间。

配置hexo

  1. 基本配置

打开_config.xml配置文件,修改配置文件可以设置你的博客名称、主题、描述等相关内容,大致如下:

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
# Hexo Configuration
## Docs: https://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/

# Site
title: Michael的博客
subtitle: 落霞与孤鹜起飞,秋水共长天一色。
description: 明月几时有?把酒问青天。不知天上宫阙,今夕是何年。我欲乘风归去,又恐琼楼玉宇,高处不胜寒。起舞弄清影,何似在人间?转朱阁,低绮户,照无眠。不应有恨,何事长向别时圆?人有悲欢离合,月有阴晴圆缺,此事古难全。但愿人长久,千里共婵娟。
author: Michael
language: en
timezone: UTC

# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: http://yoursite.com
root: /
permalink: :year/:month/:day/:title/
permalink_defaults:

# Directory
source_dir: source
public_dir: public
tag_dir: tags
archive_dir: archives
category_dir: categories
code_dir: downloads/code
i18n_dir: :lang
skip_render:

# 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
future: true
highlight:
enable: true
line_number: true
auto_detect: false
tab_replace:

# Home page setting
# path: Root path for your blogs index page. (default = '')
# per_page: Posts displayed per page. (0 = disable pagination)
# order_by: Posts order. (Order by date descending by default)
index_generator:
path: ''
per_page: 10
order_by: -date

# Category & Tag
default_category: uncategorized
category_map:
tag_map:

# 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: YYYY-MM-DD
time_format: HH:mm:ss

# Pagination
## Set per_page to 0 to disable pagination
per_page: 10
pagination_dir: page

# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: next

# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
type: git
repo: git@github.com:baoxielin/baoxielin.github.io.git
branch: master
  1. 修改主题

hexo上面有很多博客主题可以选择,可以从此处浏览更多的hexo主题。选择自己喜欢的主题样式,拷贝该主题的git地址,在博客目录下打开【Git Bash】命令窗口,执行如下命令:

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

执行成功会在themes目录下生成一个以主题命名的文件夹,这里是next。

运行和发布

  1. 本地浏览博客

在【Git Bash】命令行窗口输入如下命令:

1
2
$ hexo generate  # 可简写为hexo g
$ hexo start # 可简写为hexo s

命令行输出窗口提示服务启动成功后,在浏览器输入:localhost:4000,就可以访问刚创建的个人网站了。

  1. 发布文章

在【Git Bash】命令行窗口输入如下命令,创建一篇新的博客发布文章:

1
$ hexo new 我的第一篇博文

命令执行成功会在source/_posts目录下生成一个以新创建文章名称命名的文件,此处是【我的第一篇博文.md】,文件的后缀名为*.md,即markdown文档;输入你要发布的文章内容并保存。

【Git Bash】命令行窗口输入下面命令将新增的博文发布到网站上:

1
2
3
$ hexo c
$ hexo g
$ hexo s

在浏览器输入:localhost:4000,就可以看到新更新的这一篇博客文章了。

部署到公网

到目前为止,我们创建的博客网站都只能在本机访问,其他人还无法访问这个刚创建的博客网站。

参见网站:(使用hexo+github搭建免费个人博客详细教程)[http://www.cnblogs.com/liuxianan/p/build-blog-website-by-hexo-github.html]

Contents
  1. 1. 配置环境
  2. 2. 配置hexo
  3. 3. 运行和发布
  4. 4. 部署到公网