Preface
使用 github pages 提供的免费空间搭建个人blog,blog基于hexo生成。
CheckList:
- 注册 github,成为免费用户。
- 安装 git node.js
- 使用 github pages 生成网站,添加SSH支持。
- 绑定个人域名
- 安装、部署 hexo
- 生成文章
Step1、注册github
Step2、软件安装
安装Git
- $ brew install git
安装Node.js
-
安装nvm:
$ wget -qO- |sh
安装node:
方法一:
$ nvm install 0.12
$ nvm use 0.12 (如果不执行会导致node无法被终端正常识别)
方法二:$ nvm install stable
$ nvm use stable
$ nvm help
$ nvm alias default stable (配置默认版本)
查看帮助:
$ nvm ls
-> v0.12.6
default -> stable (-> v0.12.6)
node -> stable (-> v0.12.6) (default)
stable -> 0.12 (-> v0.12.6) (default)
iojs -> iojs- (-> N/A) (default)
$ npm -v
2.11.2
$ node -v
v0.12.6
Step3、使用 github pages 生成网站
请选择 User or orgnization site,滑动浏览器窗口,按照提示继续下一步。
如果您的github用户名是 baby,那么您的仓库名必须是:baby.github.io
2、克隆仓库到本地
$ mkdir ~/github;cd github
$ mkdir baby;cd baby
$ git clone
$ cd baby.github.io
$ echo "Hello World" > index.html
$ git config --global user.name "Your Name"
$ git config --global user.email you@example.com
每次commit 都会使用以上用户信息进行标识。
$ git add index.html
$ git commit -m "Initial commit"
$ git push -u origin master
5、访问个人网站,请在浏览器键入:baby.github.io 。
6、访问个人仓库,可以看到文件列表中显示有 index.html 文件。
7、添加SSH支持,见Reference。
Step4、绑定个人域名
如果您的域名是:baby.com 。
- 1、为您的github pages默认访问URL baby.github.io 添加CNAME
- $ cd baby.github.io (确保当前终端路径位于您仓库根目录)
- $ echo > CNAME
-
$ git add CNAME
$ git commit -m "cname"
$ git push -u origin master
2、访问个人仓库,可以看到文件列表中显示有 CNAME 文件。
-
- 3、配置DNS正确解析 和 baby.com ,建议使用dnspod进行相关配置。
- @ A 默认 192.30.252.154
- @ A 默认 192.30.252.153
- www CNAME 默认 baby.github.io.
-
- 或
-
- @ CNAME 默认 baby.github.io.
- www CNAME 默认 baby.github.io.
-
-
- 4、请在浏览器键入:baby.github.io 或 或 baby.com,以上三个网址,最终都会跳转到 CNAME文件中所定义的地址。
-
Step5、安装hexo 部署到github
$ rehash
$ hexo init ~/hexo
$ cd ~/hexo
$ npm install
$ npm install hexo-server --save (server module)
$ npm install hexo-deployer-git --save (deployer plugin)
$ cp _config.yml _config.yml.ori (修改配置前记得备份,养成好习惯)
$ vim ~/hexo/_config.yml (修改配置文档,更多内容见Reference )
-
# Deployment
-
## Docs: http://hexo.io/docs/deployment.html
-
deploy:
-
type: git
-
repo: https://github.com/baby/baby.github.io.git
- branch: master
- :wq (保存退出)
-
- 把CNAME 和 README 文件保存到 source 目录下 (recommended)
- $ echo "" > ~/hexo/source/CNAME
- $ echo "readme" > ~/hexo/source/README
-
-
说明:source 目录内文件会自动部署到github branch,防止github上的CNAME 和 README 在deploy时被冲掉。
-
- 注意:所有命令执行前,必须确保当前位于hexo根目录下。
- $ hexo clean
- $ hexo deploy -g (部署到github)
- $ hexo server
- 浏览器访问本机服务:http://localhost:4000
-
Step6、生成文章
- 1、修改 post 默认布局
- $ vi ~/hexo/scaffolds/post.md
- title: {{ title }}
- date: {{ date }}
- description:
- categories:
- tags:
- ---
- :wq (保存退出)
-
- 2、生成 post
- $ hexo new "wenzhang"
- post保存在:~/hexo/source/_posts/wenzhang.md
-
- 3、编辑文章
-
- 说明:请使用Markdown 语法编辑 wenzhang.md 文件,编辑完成后生成HTML、发布。
-
- 4、文章摘要显示模式、分类及标签
- $ vi wenzhang.md
-
title: post
date: 2015-07-08 12:25:02
description: miaoshu (为当前页面添加描述)
categories: osx (纳入 osx 分类)
tags: [hexo] (贴上 hexo 标签)注:多个标签可使用如下两种格式
tags:[tag1,tag2]
# 或
tags:
- tag1
- tag2---
## script below
``` bash
$ shell script here
```
(此行之上作为文章摘要显示,访问时点击页面readmore按钮后,完整显示当前页面的内容。)
{% blockquote %}
blockquote
{% endblockquote %}
5、生成 page
- $ hexo new page "about"
-
page保存在:source/about/index.md
-
- 6、修改页面展示菜单
- $ vi themes/landscape/_config.yml (凡涉及页面展示,请修改相应配置文件)
- # Header
- menu:
-
Home: /
Archives: /archives
About: /about
rss: /atom.xml
:wq (保存退出)
-
- 7、robots.txt
- $ cat ~/hexo/source/robots.txt
-
User-agent: *
Disallow:
Sitemap:
- 8、sitemap & feed
- $ npm install hexo-generator-sitemap --save
-
$ npm install hexo-generator-feed --save
- $ vi ~/hexo/_config.yml (添加如下内容)
- # RSS
-
feed:
type: atom
path: atom.xml
limit: 20
# sitemap -
sitemap:
path: sitemap.xml
9、友情链接
$ cd ~/hexo/themes/landscape/layout/_widget/
$ wget ''
$ cd ../../;vi _config.yml
# Sidebar
sidebar: right
widgets:
- category
- tag
- tagcloud
- archive
- recent_posts
- links (添加links)
# Links
links:
gitcafe:
chinaunix:
:wq (保存退出)
- 10、creative commons
- # 添加文章署名协议
- $ vi themes/landscape/layout/_partial/article.ejs
- # 将div置于
-
本文采用
进行许可。欢迎转载,演绎或用于商业目的,但是必须保留本文的署名
(包含链接)具体操作方式可
如您有任何疑问或者授权方面的协商,请
# footer之上。
:wq (保存退出)
-
X、hexo 更新 - # npm install npm -g (更新npm包)
- OR
- # npm update -g
- # npm help update
-
- # hexo 更新请参照wiki
-
Reference
https://help.github.com/articles/setting-up-a-custom-domain-with-github-pages/