
行者说币网站
为什么要自建博客?
现有的博客平台,常见的有CSDN、博客园、掘金等,已经给我们提供了便利的书写平台和学习社区,然而,毕竟不是自己亲生的,域名好大一串,也不方便定制化,文章审核不过等等问题。
因此,自己亲建一个博客,更加自由,WordPress和Django也可以简单的完成建站,然而,需要一个服务器,而GItGub Page提供了一个免费的服务器,极大减少开销,无需维护,以便我们将精力更多集中在内容上。
配置GitHub
注册GitHub账号

注册成功显示如下界面

安装Git版本管理工具

配置git
git config --global user.name "shijitech"
git config --global user.email xypip@qq.com
创建ssh key
ssh-keygen -t rsa -C xypip@qq.com

复制id_rsa.pb

pbcopy < ~/.ssh/id_rsa.pub
进入GitHub的SSH keys


检测是否许可成功
ssh -T git@github.com

创建仓库
仓库名格式:github名.github.io,这就是我们的网址,之后也可以绑定自己的域名。

配置Hexo
Hexo的作用就是生成我们的静态网站源码,将Hexo源码上传到GitHub服务器就可以完成网站的搭建。需要预先安装好Node.js。
hexo init shijitech
npm install
安装主题
git clone git@github.com:shijitech/hexo-theme-cafe.git cafe

安装插件
npm install hexo-server --save
npm install hexo-admin --save
npm install hexo-generator-archive --save
npm install hexo-generator-feed --save
npm install hexo-generator-search --save
npm install hexo-generator-tag --save
npm install hexo-deployer-git --save
npm install hexo-generator-sitemap --save
绑定自己的域名,逼光闪闪!

在source目录下创建CNAME文件

远程仓库配置
编辑根目录下配置文件_config.yml
deploy:
type: git
repo: git@github.com:shijitech/shijitech.github.io.git
branch: master
常用命令
hexo clean
hexo g
hexo d
hexo s
hexo g -d
hexo new "新建文章名称"
hexo new page about
文章排序
进入文件夹:node_modules/hexo-generator-index/lib
编辑文件:generator.js
添加代码:
'use strict';
var pagination = require('hexo-pagination');
module.exports = function(locals) {
var config = this.config;
var posts = locals.posts.sort(config.index_generator.order_by);
posts.data = posts.data.sort(function(a, b) {
if(a.top && b.top) {
if(a.top == b.top) return b.date - a.date;
else return b.top - a.top;
}
else if(a.top && !b.top) {
return -1;
}
else if(!a.top && b.top) {
return 1;
}
else return b.date - a.date;
});
var paginationDir = config.pagination_dir || 'page';
return pagination('', posts, {
perPage: config.index_generator.per_page,
layout: ['index', 'archive'],
format: paginationDir + '/%d/',
data: {
__index: true
}
});
};
部署网站到GitHub
hexo g –d
成果一览

网友评论