Gray's coding life.

基于Hexo和github建立个人博客

Word count: 1,035 / Reading time: 5 min
2018/06/13 Share

基于Hexo和github建立个人博客

  1. 首先创建一个git账户(地址: github官网
    记得此时的username是会影响到后面的博客域名,尽量取个自己喜欢的吧
  2. 创建仓库
    在登录账户后找到+号,然后点击New repository按钮
    仓库名是 => username.github.io(username是你的账户名)
  3. 安装Git、Nodejs、Hexo
    (若未安装brew请先安装HomeBrew)

安装HomeBrew(mac使用这个来管理工具)

1
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

安装Git

1
brew install git

安装Nodejs的版本管理器nvm

1
2
3
4
5
brew install nvm
//为了能使用nvm命令还需要执行下面命令
mkdir ~/.nvm
export NVM_DIR=~/.nvm
. $(brew --prefix nvm)/nvm.sh

完成后用下面命令安装Nodejs(这里11是版本号,根据hexo需要的版本自己按需安装即可)

1
nvm install 11

安装Hexo

1
sudo npm install hexo-cli -g

到这里我们建立博客所需的工具已经安装完毕,可以开始建立我们的博客文件了。
先创建博客文件的根目录(名字可以随意)

1
hexo init username.github.io

init完成之后会有一篇介绍blog是已经自动生成了的,在source/_posts目录下。这个时候已经可以启动模拟环境来看看我们生成的博客的样子啦。

1
hexo s

再用浏览器访问https://localhost:4000就可以看到你创建的博客啦

更改博客配置

若需要更改博客的配置,只需要打开根目录下的_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
# Hexo Configuration
## Docs: https://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/

# Site
title: Gray //博客的标题
subtitle:
description:
keywords:
author: Gray //博客的作者
language: zh-Hans //博客的主语言
timezone:

# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: https://graydang.github.io //博客地址
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: landscape //博客的主题
# theme: next

# 博客部署的方式和地址
# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
type: git
repo: https://github.com/graydang/graydang.github.io.git

-
附上各种主题的下载地址和设置的教程
主题下载
设置教程

记录一下遇到的问题

1
2
Local hexo not found in
npm install hexo --save

这里运行hexo的时候可能会报error的错误,原因可能是因为nodejs版本过低,此时查看log看看hexo支持的最低nodejs版本,把nodejs版本切换到能支持hexo的版本再重新安装hexo就可以了

1
2
3
error: RPC failed; curl 56 LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 60
fatal: The remote end hung up unexpectedly
fatal: The remote end hung up unexpectedly

在执行hexo d的时候可能会遇到The remote end hung up unexpectedly的问题,这个问题是出自git本身,若你上传的文件过大可以试试以下两句命令,即把git的推送大小设置为500M

1
2
git config http.postBuffer 524288000
git config https.postBuffer 524288000

若不是因为文件过大,可能是git本身出了问题
如果hexo d推送不到github或者卡死,可以尝试以下步骤:

  • 删除根目录下的 .deploy_git 文件夹
  • 删除 db.json 文件
  • 执行hexo clean && hexo g && hexo d –debug
CATALOG
  1. 1. 基于Hexo和github建立个人博客
    1. 1.1. 更改博客配置
  2. 2. 记录一下遇到的问题