Github Pages
能够免费托管,因此把博客托管到github上。node
首先,建立一个github仓库,仓库的命名格式为:yourusername.github.io
,而后根据提示进行下一步。
git
本博客中使用了Anisina
的主题,因此会详细介绍下按照Anisina
主题搭建的步骤。github
1.首先要安装下node.js(官网下载),若是已经安装能够跳过。
2.安装git(官网下载)
3.安装Hexo:npm
$ npm install -g hexo复制代码
安装成功后,使用version命令查看是否安装成功json
& hexo version复制代码
4.本地静态hexo博客缓存
$ hexo init复制代码
$ npm install复制代码
hexo s
命令查看是否搭建成功git clone https://github.com/Haojen/hexo-theme-Anisina.git themes/Anisina复制代码
将img的alt属性设置为post-cover
便可bash
注意:必须在主题的_config.yml中配置一下信息,而非博客根目录下的_config.yml中配置。hexo
user_name: your name
user_avatar: your avatar
user_location: your location
user_description: about you introduction
// this info will show About page
user_contact:
user_introduction:
// config you share info
weibo_username:
zhihu_username:
github_username:
twitter_username:
facebook_username:
linkedin_username:复制代码
在根目录下的source
文件夹里建立一个about
文件夹,而后在about
文件夹里新建index.md
文件,在文件中添加以下代码,并保存:app
title: about
date: 2017-09-11 23:12:50
layout: about复制代码
须要提一下的是,做者尚未支持对About页面内容的修改,因此本博客搭建的时候,直接在themes/Anisina/layout/about.ejs
中修改的内容。框架
在根目录下的source文件夹中建立works文件夹,如上新建一个index.md
,添加以下内容到文件中,并保存:
title: My Works
date: 2017-09-11 23:16:50
layout: works复制代码
而后在source
文件夹下建立一个_data
文件夹,打开文件夹,新建project.json
文件,文件格式以下:
{
"Apple 官网临摹": {
"title": "Apple 官网临摹",
"subTitle": "根据美版apple官网临摹",
"img_link": "http://o7bkkhiex.bkt.clouddn.com/item-apple.jpg",
"use" : ["jQuery"],
"link": "http://haojen.github.io/apple-linmo/",
"data":"2016.3",
"direction": "临摹 2016 年三月份 Apple 美版单页面。"
},
"Anisina (阿尼丝娜)": {
"title": "Anisina",
"subTitle": "基于 Hexo 制做的我的博客主题",
"img_link": "http://o7bkkhiex.bkt.clouddn.com/Anisina.png",
"use" : ["jQuery","Bootstrap","Node.js","EJS","Hexo","SASS"],
"link": "http://haojen.github.io/",
"data": "2016.5",
"direction":
"Hexo 是某位台湾友人基于 Node.js 编写的博客框架"
}
}复制代码
主题中支持来比力的配置,因此在_config.yml
配置文件中添加两行配置代码便可。
use_livere: true
livere_uid: 你的来比力的注册uid复制代码
主题中添加了百度统计的js代码,在配置文件中直接添加track_id
便可:
ba_track_id: your track id复制代码
hexo init yourname
cd yourname
npm install复制代码
deploy:
type: git
repo: http://github.com/yousername/yourusername.github.io
branch: master #默认master复制代码
$ hexo clean复制代码
$ hexo g复制代码
http://localhost:4000
查看本地效果$ hexo s复制代码
$ hexo d复制代码
以前在阿里云买了域名,域名购买成功以后要等待实名认证。
在根目录下的source
文件夹下新建CNAME
文件,没有后缀。
在Sublime Text中打开CNAME
文件,在里边添加你的域名信息,如图:
保存以后,从新部署到github pages上。
在项目的Settings
中,添加Custom domain
到本身的域名:
1.ping你本身的yourname.github.io
获取到ip地址:
2.打开域名的解析列表,添加两条解析记录:
更换以后,可能须要等一段时间才能生效,差很少就大功告成啦。