安裝Hexo
npm install hexo-cli -g
初始化blog
hexo init blog
cd blog
npm install
更換主題
npm install --save hexo-renderer-jade hexo-renderer-scss
cd themes
git clone https://github.com/yzzting/hexo-theme-MyFairLady.git MyFairLady
這里可以有其他自己喜歡的主題荠雕,可以去hexo官網(wǎng)
然后更新自己的博客的主要_config.yml設(shè)定主題MyFairLady
# Extensions
## Plugins: http://hexo.io/plugins/
## Themes: http://hexo.io/themes/
theme: MyFairLady
主要的配置
菜單
menu:
home: /
about : /about
archives: /archives
這個(gè)是header里面三個(gè)選項(xiàng),如果要添加的話玲躯,在目錄下的 source 下創(chuàng)建 一個(gè)你想要添加的選項(xiàng)名稱的文件夾嚼锄,然后在里面new一個(gè)例如xx.md在 里面填入
---
layout: xxx
title: "xx"
noDate: "true"
---
顯示的文章數(shù)
每一頁顯示的文章數(shù)减拭,還是在主目錄下的_config.yml,找到per_page,選擇你喜歡的數(shù)字区丑。歸檔頁也會跟著改變拧粪。
# Pagination
## Set per_page to 0 to disable pagination
per_page: 5
在里面添加了百度統(tǒng)計(jì)和google統(tǒng)計(jì)修陡,默認(rèn)才用的是google。分別在主題的配著文件下填入你的ID可霎,就是啟用了魄鸦。
# Baidu Analytics
# baidu_analytics: c21994907883f37ffd80e13627dd4faa
# Google Analytics
google_analytics: UA-75314797-1
社交
在主題的_config.yml里面的subnav選項(xiàng)中,有三個(gè)選項(xiàng)癣朗,github号杏,知乎,一切從簡斯棒,并沒有用icon。
# SubNav
subnav:
gitHub: "https://github.com/binperon"
zhiHu: "https://www.zhihu.com/people/binperson"
其他的配置呢在配置文件里面寫的也蠻清楚了主经,一看就懂的啦
評論框
因?yàn)槎嗾f的評論框荣暮,樣式很low,只是采用了disqus罩驻。雖然是國外的穗酥,但是不影響使用。注冊和配置相當(dāng)容易惠遏。注冊填入你的網(wǎng)站信息之后砾跃,在主題的配置文件.config.yml 中填入
# comments
disqus: binperson
啟動(dòng)服務(wù)
hexo server -p 5000
Hexo進(jìn)程守護(hù)
Node進(jìn)程守護(hù)有很多工具,F(xiàn)orever节吮,PM2抽高,PM2.5 blah blah.我用PM2
Hexo下新建一個(gè)app.js,寫入下面代碼:
var spawn = require('child_process').spawn;
free = spawn('hexo', ['server', '-p 4000']);/* 其實(shí)就是等于執(zhí)行hexo server -p 4000*/
free.stdout.on('data', function (data) {
console.log('standard output:\n' + data);
});
free.stderr.on('data', function (data) {
console.log('standard error output:\n' + data);
});
free.on('exit', function (code, signal) {
console.log('child process eixt ,exit:' + code);
});
執(zhí)行pm2命令:
pm2 start app.js
停止服務(wù)
pm2 stop id
注意
上傳服務(wù)器后執(zhí)行npm install 因?yàn)橛行┮驗(yàn)槁窂絾栴}上傳失敗導(dǎo)致文件缺損。