hexo + github 搭建静态博客

hexo + github 搭建静态博客

安装git

下载安装

安装Node.js

下载安装

安装npm

创建一个目录存放npm源码。(直接安装的话会有源的问题)
在此目录下打开gitbush

  1. 下载源代码:

    1
    git clone --recursive git://github.com/isaacs/npm.git
  2. 运行

    1
    2
    3
    D:\>cd npmjs
    D:\npmjs>node cli.js install -gf // 安装完成后要path路径
    npm -v //查看版本

安装hexo

1
2
npm install -g hexo
hexo version //查看版本

搭建blog

  1. 创建项目
    打开cmd

    1
    2
    3
    4
    5
    e:   //切换到epan
    mkdir hexo // 创建文件夹
    cd hexo // 进入文件夹
    hexo init // 初始化
    hexo s // 本地运行
  2. 写一篇blog

1
hexo new my first blog
  1. 生成bolg
1
2
3
4
5
6
heox g // 生成

heox d // 发布

// 如果出现 ERROR Deployer not found: git
npm install hexo-deployer-git --save
  1. 配置
    在生成之前需要配置远程地址等非必要信息
    1
    2
    3
    4
    5
    6
    7
    8
    9
    title: Bruce's Blog
    subtitle: a monkey
    description: blog
    author: Bruce He

    deploy:
    type: git
    repository: https://github.com/bruce03/bruce03.github.io.git
    branch: master

GitHub 配置

1. 注册帐号

用户名+密码
  1. 本地安装客户端
  2. 添加本地电脑的sshkey
    让本地git项目与远程的github建立联系要用SSH keys。
    检查SSH keys的设置
    首先我们需要检查你电脑上现有的ssh key:
    1
    $ cd ~/.ssh 检查本机的ssh密钥

如果提示:No such file or directory 说明是第一次使用git。

生成新的SSH Key:

1
2
3
4
5
6
7
8
9
10
11
12
$ ssh-keygen -t rsa -C "邮件地址@youremail.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/your_user_directory/.ssh/id_rsa):<回车就好>

// 1: 邮箱地址要输入自己的邮箱地址;
// 2: 此处的「-C」的是大写的「C」
// 然后系统会要你输入密码:

Enter passphrase (empty for no passphrase):<输入加密串>
Enter same passphrase again:<再次输入加密串>

//在回车中会提示输入一个密码,这个密码会在提交项目时使用,如果为空的话提交项目时则不用输入。这个设置是防止别人往你的项目里提交内容。

添加SSH Key到GitHub

  1. 打开本地C:\Users\username.ssh\id_rsa.pub文件。此文件里面内容为刚才生成人密钥。如果看不到这个文件,你需要设置显示隐藏文件。准确的复制这个文件的内容,才能保证设置的成功。
  2. 登陆github系统。点击右上角的 Account Settings—>SSH Public keys —> add another public keys
  3. 把你本地生成的密钥复制到里面(key文本框中), 点击 add key 就ok了

测试

1
$ ssh -T git@github.com

设置用户信息
现在已经可以通过SSH链接到GitHub了,还有一些个人信息需要完善的。
Git会根据用户的名字和邮箱来记录提交。GitHub也是用这些信息来做权限的处理,输入下面的代码进行个人信息的设置,把名称和邮箱替换成自己的,名字必须是真名,而不是GitHub的昵称。

1
2
$ git config --global user.name "bruce03"//用户名
$ git config --global user.email "3320425386@qq.com"//填写自己的邮箱

4. 新建 repositories(仓库)

bruce03.github.io

5. 常用命令

1
2
3
4
5
git init // 初始化项目
git add . // 添加当前所有到缓存
git commit -m "first commit" // 提交
git remote add origin https://github.com/bruce03/test.git //设置远程地址
git push -u origin master // 推送

blog 头部配置

1
2
3
4
5
6
title: postName #文章页面上的显示名称,可以任意修改,不会出现在URL中
date: 2013-12-02 15:30:16 #文章生成时间,一般不改,当然也可以任意修改
categories: example #分类
tags: [tag1,tag2,tag3] #文章标签,可空,多标签请用格式,注意:后面有个空格
description: 附加一段文章摘要,字数最好在140字以内。
---

hexo配置文件说明

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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# Hexo Configuration
## Docs: http://hexo.io/docs/configuration.html
## Source: https://github.com/tommy351/hexo/

# Site #整站的基本信息
title: 1000 words a Day #网站标题
subtitle: Writing 1000 Words a Day Changes My Life #网站副标题
description: 学习总结 思考感悟 知识管理 #网站描述
author: cnFeat #网站作者,在下方显示
email: cnFeat@gmail.com #联系邮箱
language: zh-CN

# URL
## If your site is put in a subdirectory
url: http://www.cnfeat.com #你的域名
root: /
permalink: :year/:month/:day/:title/
tag_dir: tags
archive_dir: archives
category_dir: categories
code_dir: downloads/code

# Directory
source_dir: source
public_dir: public

# Writing
new_post_name: :title.md # File name of new posts
default_layout: post
auto_spacing: false # Add spaces between asian characters and western characters
titlecase: false # Transform title into titlecase
external_link: true # Open external links in new tab
max_open_file: 100
multi_thread: true
filename_case: 0
render_drafts: false
post_asset_folder: false
highlight:
enable: true
line_number: true
tab_replace:

# Category & Tag
default_category: uncategorized
category_map:
tag_map:

# Archives
## 2: Enable pagination
## 1: Disable pagination
## 0: Fully Disable
archive: 2
category: 2
tag: 2

# 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: 0.0.0.0
logger: false
logger_format:

# 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: H:mm:ss

# Pagination
## Set per_page to 0 to disable pagination
per_page: 15 #每页15篇文章
pagination_dir: page

# Disqus #社会化评论disqus,我使用多说,在主题中配置
disqus_shortname:

# Extensions
## Plugins: https://github.com/tommy351/hexo/wiki/Plugins
## Themes: https://github.com/tommy351/hexo/wiki/Themes
theme: jacman
exclude_generator:
Plugins:
- hexo-generator-feed
- hexo-generator-sitemap

#sitemap
sitemap:
path: sitemap.xml

#Feed Atom
feed:
type: atom
path: atom.xml
limit: 20

# Markdown
## https://github.com/chjj/marked
markdown:
gfm: true
pedantic: false
sanitize: false
tables: true
breaks: true
smartLists: true
smartypants: true

# Stylus
stylus:
compress: false

# Deployment
## Docs: http://hexo.io/docs/deployment.html
deploy:
type: github
repository: https://github.com/cnfeat/cnfeat.github.io.git
branch: master

http://www.jianshu.com/p/05289a4bc8b2

https://www.zybuluo.com/mdeditor?url=https://www.zybuluo.com/static/editor/md-help.markdown

1
2
3
4
5
6
7
8
9
10
11
12
13
14
st=>start: 开始:>https://github.com 
regist=>operation: 注册github帐号
createresp=>operation: 创建代码仓库 (bruce03.github.io)
installgit=>operation: 安装github客户端
installnode=>operation: 安装node.js
installnpm=>operation: 安装npm
installhexo=>operation: 安装hexo
hexoinit=>operation: 初始化hexo
hexoconfig=>operation: 配置hexo
hexo=>operation: 创建,生成,运行,发布
e=>end

st->regist->createresp->installgit->installnode->installnpm->installhexo->hexoinit->hexoconfig->hexo
hexo->io