环境:Windows7、GitHub、Hexo3

GitHub Pages

GitHub Pages are public webpages hosted and easily published through GitHub.

         github Pages可以被认为是用户编写的、托管在github上的静态网页。

Hexo

A fast, simple & powerful blog framework

         Hexo 是一个快速、简洁且高效的博客框架。Hexo 使用 Markdown(或其他渲染引擎)解析文章,在几秒内,即可利用靓丽的主题生成静态网页。
         我们主要是用hexo在本地写博客,然后上传到github page,就像你commit项目代码到github一样.

创建GitHub Pages

  1. 登录github并创建一个库(new repository)
  2. 仓库名必须为【username.github.io】
  3. 详情请看官方教程

安装Hexo

  • 安装 git
  • 安装 Node.js
  • 使用Git Shell,输入下面的命令安装Hexo

    1
    npm install -g hexo-cli
  • 初始化:执行init命令初始化hexo到你指定的目录

    1
    2
    hexo init <folder>
    ##也可以cd到目标目录,执行hexo init
  • 安装插件,运行下面的命令即可 (由于hexo3.0很多功能都插件化了,包括git上传,server功能)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    npm install hexo-generator-index --save
    npm install hexo-generator-archive --save
    npm install hexo-generator-category --save
    npm install hexo-generator-tag --save
    npm install hexo-server --save
    npm install hexo-deployer-git --save
    npm install hexo-deployer-heroku --save
    npm install hexo-deployer-rsync --save
    npm install hexo-deployer-openshift --save
    npm install hexo-renderer-marked@0.2 --save
    npm install hexo-renderer-stylus@0.2 --save
    npm install hexo-generator-feed@1 --save
    npm install hexo-generator-sitemap@1 --save

用Hexo管理博客

  • hexo new "title"
    新建一篇博客,然后对生成的md文件进行编辑(markdown语法,md文件的默认路径:目标路径\source\_posts)
    详见hexo writing
  • hexo clean
    清理缓存
  • hexo generate
    根据博客内容和配置项生成网页
    生成博客在public文件夹中,上传到github上的就是里面的内容
    详见hexo generating
  • hexo server
    本地查看效果:访问 http://localhost:4000 查看效果

部署

  • 使用Hexo 命令

    • 编辑_config.yml文件

      1
      2
      3
      4
      deploy:
      type: git
      repo: https://github.com/xx/xx.github.io ###<repository url> 需要使用 "Git Bash" 工具执行 deploy;否则不能成功??
      branch: master
    • hexo deploy
      上传到GitHub
      详见hexo deployment
      注意:有些新用户需要设置 ssh,否则上述命令会失败。详见GitHub ssh官方教程

  • 使用GitHub Windows
    • 拷贝 hexo目录\public 下的内容
    • 复制到仓库的本地副本中
    • 运行GitHub确认修改信息后执行右上角的sync 同步
  • 访问username.github.io,查看内容

Hexo主题

  1. Hexo有丰富的主题支持,本博客使用的是Next
  2. 更多主题 点击主题

注意

  1. 每次使用hexo命令时,都要在 hexo init 指定的 目录下
  2. 修改配置文件时注意YAML语法,参数冒号:后一定要留空格
  3. hexo是用markdown来写作
  4. 运行hexo命令使用Git Bash工具?

参考

  1. 使用GitHub和Hexo搭建免费静态Blog
  2. 用hexo搭建github博客
  3. 搭建hexo博客并部署到github上
  4. hexo你的博客
  5. 使用GitHub + Hexo搭建个人博客(九)- 切换 Hexo 主题




分割线

1
2
3
4
5
6
7
8
9
10
三个或更多-_*,必须单独一行,可含空格(需要注意下划线)
* * *

***

*****

- - -

---------------------------------------

标题:Atx方式

1
2
3
4
5
6
# 一级标题
## 二级标题
### 三级标题
#### 四级标题
##### 五级标题
###### 六级标题

一级标题

二级标题

三级标题

四级标题

五级标题
六级标题

标题:Setext方式

1
2
3
4
5
6
三个或更多
This is an H1 (最高阶标题)
=============


This is an H2 (第二阶标题)
-------------

大标题

小标题


强调

1
Markdown 使用星号(*)和底线(_)作为标记强调字词的符号.单是斜体,双是粗体,符号可跨行,符号可加空格

斜体
粗体
跨行
斜体


引用

Markdown 中,你只需要在你希望引用的文字前面加上 > 就好.
注:> 和文本之间要保留一个字符的空格。

早发白帝城
朝辞白帝彩云间,千里江陵一日还。
两岸猿声啼不尽,轻舟已过万重山。


无序列表

1
无序列表使用星号、加号或是减号作为列表标记,符号之后的空格不能少.
  • 无序列表星号
  • 无序列表星号
  • 无序列表星号

  • 无序列表加号
  • 无序列表加号
  • 无序列表加号

  • 无序列表减号
  • 无序列表减号
  • 无序列表减号

有序列表

有序列表则使用数字接着一个英文句点(数字不能省略但可无序,点号之后的空格不能少)
  1. 有序列表1
  2. 有序列表0
  3. 有序列表999

嵌套列表

1
-+*可循环使用,但符号之后的空格不能少,符号之前的空格也不能少
  • 嵌套列表
    • 嵌套列表
      • 嵌套列表
    • 嵌套列表
  • 嵌套列表

文字链接

在 Markdown 中,插入链接不需要其他按钮,你只需要使用 [显示文本](链接地址) 这样的语法即可,Tooltips可省略

googel


图片链接

Markdown 中,插入图片不需要其他按钮,你只需要使用 ![](图片链接地址) 这样的语法即可.
仅仅是多了一个感叹号,Tooltips可省略,要设置大小只能借助HTML标记

googel icon


索引超链:Reference方式

索引,1 2可以是任意字符
链接的定义可以放在文件中的任何一个地方,我比较偏好直接放在链接出现段落的后面,你也可以把它放在文件最后面,就像是注解一样。

I get 10 times more traffic from Google than from
Yahoo or MSN.


自动链接

尖括号。简写url:用尖括号包裹url,这样生成的url锚文本就是url本身

https://www.google.com.hk
xxoo@qq.com


代码

如果要标记一小段行内代码,你可以用反引号(`)把它包起来

user the print() fuction

//段落代码:每行文字前加4个空格或者1个Tab
public class Person {
    private Integer id;
    private String name;
    .......
}
1
2
3
4
# 用多个反引号来开启和结束代码区段
def print_lol(the_list):
for each_item in the_list:
print(each_item)

特殊符号

\来转义,表示文本中的markdown符号.
Markdown中的转义字符为\,转义的有:
\\ 反斜杠
\` 反引号
\* 星号
\_ 下划线
\{\} 大括号
\[\] 中括号
\(\) 小括号
\# 井号
\+ 加号
\- 减号
\. 英文句号
\! 感叹号

\ 反斜杠
` 反引号
* 星号
_ 下划线
{} 大括号
[] 中括号
() 小括号
# 井号
+ 加号
- 减号
. 英文句号
! 感叹号


其他

文本中可直接用html标签,但是要前后加上空行。


















序号 姓名
1 张三
2 李四


表格

Markdown的扩展语法,hexo不支持
| Tables        | Are           | Cool  |
| ------------- |:-------------:| -----:|
| col 3 is      | right-aligned | $1600 |
| col 2 is      | centered      |   $12 |
| zebra stripes | are neat      |    $1 |
Tables Are Cool
col 3 is right-aligned $1600
col 2 is centered $12
zebra stripes are neat $1

换行

连续两个空格 会变成一个 <br> ???
连续3个符号,然后是空行,表示 hr横线

换行

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

Generate static files

1
$ hexo generate

More info: Generating

Deploy to remote sites

1
$ hexo deploy

More info: Deployment