使用hexo, github, coding搭建免費(fèi)博客

Updated March 6, 2018

準(zhǔn)備環(huán)境

windows10 x64
node.js v8.9.3
git version 2.16.1.windows.4
Markdown編輯器:http://markdownpad.com/

熟練掌握git和github的基本操作

參考廖雪峰教程:
https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000
然后,
在github中新建倉(cāng)庫(kù)席舍,名稱設(shè)置為github用戶名.github.io

node.js+hexo

下載安裝node.js,打開git-bash塞赂,分別輸入npm -vnode -v春叫,返回版本信息說明安裝成功

新建文件夾D:\hexo,在文件夾hexo中使用git-bash進(jìn)行操作

輸入npm install -g hexo-cli來安裝hexo

依次輸入hexo init blog, cd blognpm install建站

輸入hexo generate生成靜態(tài)頁(yè)面

輸入hexo server啟動(dòng)服務(wù)
如果提示端口4000被占用, 那就需要改端口hexo server -p 5000

hexo配置

hexo官方文檔:https://hexo.io/zh-cn/docs/
修改/hexo/blog/_config.yml文件

# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
  type: git
  repo: https://github.com/lema1987/lema1987.github.io.git
  branch: master

設(shè)置語(yǔ)言,網(wǎng)站標(biāo)題放可,修改/hexo/blog/_config.yml文件

# Site
title: # 網(wǎng)站標(biāo)題
subtitle:
description:
author: # 作者
language: zh-Hans # 語(yǔ)言
timezone:

菜單中添加分類頁(yè)標(biāo)簽頁(yè):
教程:https://github.com/iissnan/hexo-theme-next/blob/master/README.cn.md
修改/hexo/blog/themes/next/_config.yml

menu:
  home: / || home
  關(guān)于我: /about/ || user
  tags: /tags/ || tags
  categories: /categories/ || th
  archives: /archives/ || archive
  #schedule: /schedule/ || calendar
  #sitemap: /sitemap.xml || sitemap
  #commonweal: /404/ || heartbeat

騰訊404公益http://www.qq.com/404/
在/hexo/blog目錄下新建404.md

<html>
<head>
  <meta http-equiv="content-type" content="text/html;charset=utf-8;"/>
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  <meta name="robots" content="all" />
  <meta name="robots" content="index,follow"/>
</head>
<body>

<script type="text/javascript" src="http://qzonestyle.gtimg.cn/qzone/hybrid/app/404/search_children.js" charset="utf-8" homePageUrl="http://lema1987.github.io" homePageName="回到我的主頁(yè)"></script>

</body>
</html>

https://github.com/hexojs/hexo-deployer-git
npm install hexo-deployer-git --save

hexo主題配置

下載next主題:https://github.com/iissnan/hexo-theme-next
把主題代碼存放在/hexo/blog/themes/next
修改/hexo/blog/_config.yml文件:

# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: next

新建文章

在/hexo/blog/sources/_posts中新建文章.md
在開頭輸入

---
title: #文章標(biāo)題
date: 2016-06-01 23:47:44 #文章生成時(shí)間
categories: "Hexo教程" #文章分類目錄 可以省略
tags: #文章標(biāo)籤 可以省略
     - 標(biāo)簽1
     - 標(biāo)簽2
description: #你對(duì)本頁(yè)的描述 可以省略
---

部署項(xiàng)目

hexo clean  清除緩存
hexo g  生成頁(yè)面
hexo d  一鍵部署項(xiàng)目到服務(wù)器上
或者 hexo clean && hexo g && hexo d

hexo s  啟動(dòng)本地服務(wù)器

實(shí)現(xiàn)各種優(yōu)化

為主題增加動(dòng)態(tài)粒子背景

教程:https://github.com/hustcc/canvas-nest.js/blob/master/README-zh.md
把下面的js代碼復(fù)制粘貼到/hexo/blog/themes/next/layout/_layout.swig中的</body>之前:

{% if theme.canvas_nest %}
<script type='text/javascript' color='252,3,184' zIndex='-1' opacity='20' count='99' src='//cdn.bootcss.com/canvas-nest.js/1.0.0/canvas-nest.min.js'></script>
{% endif %}

/hexo/blog/themes/next/_config.yml中所有的canvas_nest設(shè)置為true

hexo文章添加本地圖片

方法1:此方法有時(shí)會(huì)出錯(cuò),不能成功引入圖片
/hexo/blog/_config.yml中的post_asset_folder設(shè)置為true
/hexo/blog/source下創(chuàng)建/images文件夾朝刊,本地圖片丟里面
引入圖片時(shí)按照markdown格式引入圖片耀里,如[圖片上傳失敗...(image-deba05-1527085003150)]

方法2:引入外鏈, 推薦使用第二種方法
注冊(cè)申請(qǐng)七牛云賬號(hào)
上傳圖片到七牛云,七牛云作為圖片托管
取外鏈粘貼在文章中
參考教程:http://www.reibang.com/p/ec2c8acf63cd

添加字?jǐn)?shù)統(tǒng)計(jì)拾氓,閱讀時(shí)長(zhǎng)功能

參考鏈接:http://www.reibang.com/p/baea8c95e39b

安裝插件

npm -i --save hexo-wordcount
npm install hexo-wordcount@2 --save

修改配置文件

/hexo/blog/themes/next/_config.yml
post_wordcount:
  item_text: true
  wordcount: true # 改為true
  min2read: true # 改為true
  totalcount: false
  separated_meta: true

編輯/hexo/blog/themes/next/layout/_macro/post.swig

<span title="{{ __('post.wordcount') }}">
    {{ wordcount(post.content) }} 字
</span>
<span title="{{ __('post.min2read') }}">
    {{ min2read(post.content) }} 分鐘
</span>

添加友鏈

編輯/hexo/blog/themes/next/_config.yml

# Blog rolls
links_icon: link
links_title: 友情鏈接
links_layout: block
#links_layout: inline
links:
  #Title: http://example.com/
  武沛齊: http://www.cnblogs.com/wupeiqi
  離別歌: https://www.leavesongs.com/
  Chybeta: https://chybeta.github.io/
  Sakura: http://eternalsakura13.com/
  andseclab: https://www.andseclab.cn/

自定義鼠標(biāo)樣式

打開/themes/next/source/css/_custom/custom.styl冯挎,輸入

 * {
      cursor: url("http://om8u46rmb.bkt.clouddn.com/sword2.ico"),auto!important
  }

添加github絲帶

/hexo/blog/themes/next/layout/_layout.swig中加入相關(guān)代碼
相關(guān)代碼的訪問鏈接: https://blog.github.com/2008-12-19-github-ribbons/

鼠標(biāo)點(diǎn)擊顯示小紅心

/hexo/blog/themes/next/source/js/src目錄下添加love.js文件,內(nèi)容為

!function(e,t,a){function n(){c(".heart{width: 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}.heart:after,.heart:before{content: '';width: inherit;height: inherit;background: inherit;border-radius: 50%;-webkit-border-radius: 50%;-moz-border-radius: 50%;position: fixed;}.heart:after{top: -5px;}.heart:before{left: -5px;}"),o(),r()}function r(){for(var e=0;e<d.length;e++)d[e].alpha<=0?(t.body.removeChild(d[e].el),d.splice(e,1)):(d[e].y--,d[e].scale+=.004,d[e].alpha-=.013,d[e].el.style.cssText="left:"+d[e].x+"px;top:"+d[e].y+"px;opacity:"+d[e].alpha+";transform:scale("+d[e].scale+","+d[e].scale+") rotate(45deg);background:"+d[e].color+";z-index:99999");requestAnimationFrame(r)}function o(){var t="function"==typeof e.onclick&&e.onclick;e.onclick=function(e){t&&t(),i(e)}}function i(e){var a=t.createElement("div");a.className="heart",d.push({el:a,x:e.clientX-5,y:e.clientY-5,scale:1,alpha:1,color:s()}),t.body.appendChild(a)}function c(e){var a=t.createElement("style");a.type="text/css";try{a.appendChild(t.createTextNode(e))}catch(t){a.styleSheet.cssText=e}t.getElementsByTagName("head")[0].appendChild(a)}function s(){return"rgb("+~~(255*Math.random())+","+~~(255*Math.random())+","+~~(255*Math.random())+")"}var d=[];e.requestAnimationFrame=function(){return e.requestAnimationFrame||e.webkitRequestAnimationFrame||e.mozRequestAnimationFrame||e.oRequestAnimationFrame||e.msRequestAnimationFrame||function(e){setTimeout(e,1e3/60)}}(),n()}(window,document);

/hexo/blog/themes/next/layout/_layout.swing文件中添加一下代碼(要在</body>之前添加)

<!-- 小紅心 -->
<script type="text/javascript" src="/js/src/love.js"></script>

設(shè)置hexo首頁(yè)文章不顯示全文只顯示預(yù)覽

第一種方法:
/hexo/blog/themes/next/_config.yml中將下面代碼中的enable值改為true

# Automatically Excerpt. Not recommend.
# Please use <!-- more --> in the post to control excerpt accurately.
auto_excerpt:
  enable: true
  length: 150

第二種方法:

在每一篇文章中添加<!--more-->手動(dòng)進(jìn)行截?cái)?推薦使用第二種方法

設(shè)置hexo支持評(píng)論系統(tǒng)

本文選用韓國(guó)的產(chǎn)品來必力: https://livere.com/, 支持多個(gè)國(guó)內(nèi)外賬號(hào)登錄
注冊(cè)并登錄來必力賬號(hào), 選擇安裝LiveReCity免費(fèi)版, 添加站點(diǎn)信息

image
image

然后在/hexo/blog/themes/next/_config.yml中找到livere_uid

livere_uid: 輸入你的uid

修改超鏈接顯示樣式

將超鏈接設(shè)置為藍(lán)色, 鼠標(biāo)劃過時(shí)顯示下劃線
/hexo/blog/themes/next/source/css/_custom/custom.styl中添加以下css樣式

.post-body p a {  
    color: #0593d3;  
    border-bottom: none; 
    &:hover {    
        color: #0477ab;   
        text-decoration: underline;
    }
}

添加頭像

/hexo/blog/themes/next/_config.yml中找到并修改以下代碼:

# Sidebar Avatar
# in theme directory(source/images): /images/avatar.gif
# in site  directory(source/uploads): /uploads/avatar.gif
avatar: http://p5zqim58x.bkt.clouddn.com/touxiang.jpg

將博客托管到coding pages上

教程: https://blog.csdn.net/xiaoliuge01/article/details/50997754
在coding官網(wǎng) https://coding.net/ 注冊(cè)賬號(hào)并綁定騰訊云賬號(hào)
創(chuàng)建一個(gè)項(xiàng)目

image

添加ssh key到coding上:
打開git bash, 輸入

cd ~/.ssh
cat id_rsa.pub
復(fù)制一整串公鑰

在coding上配置公鑰

image

輸入ssh -T git@git.coding.net看看是否配置成功

選擇master分支, 開啟https

image

打開hexo/blog/_config.yml修改添加以下代碼

# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
  type: git
  repo: 
      github: https://github.com/lema1987/lema1987.github.io.git
      coding: git@git.coding.net:lema1987/lema1987.git
  branch: master

本地項(xiàng)目部署到coding上

hexo clean
hexo g
hexo s
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市咙鞍,隨后出現(xiàn)的幾起案子房官,更是在濱河造成了極大的恐慌趾徽,老刑警劉巖,帶你破解...
    沈念sama閱讀 219,188評(píng)論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件翰守,死亡現(xiàn)場(chǎng)離奇詭異孵奶,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)蜡峰,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,464評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門了袁,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人湿颅,你說我怎么就攤上這事载绿。” “怎么了油航?”我有些...
    開封第一講書人閱讀 165,562評(píng)論 0 356
  • 文/不壞的土叔 我叫張陵崭庸,是天一觀的道長(zhǎng)。 經(jīng)常有香客問我劝堪,道長(zhǎng)冀自,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,893評(píng)論 1 295
  • 正文 為了忘掉前任秒啦,我火速辦了婚禮熬粗,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘余境。我一直安慰自己驻呐,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,917評(píng)論 6 392
  • 文/花漫 我一把揭開白布芳来。 她就那樣靜靜地躺著含末,像睡著了一般。 火紅的嫁衣襯著肌膚如雪即舌。 梳的紋絲不亂的頭發(fā)上佣盒,一...
    開封第一講書人閱讀 51,708評(píng)論 1 305
  • 那天,我揣著相機(jī)與錄音顽聂,去河邊找鬼肥惭。 笑死,一個(gè)胖子當(dāng)著我的面吹牛紊搪,可吹牛的內(nèi)容都是我干的蜜葱。 我是一名探鬼主播,決...
    沈念sama閱讀 40,430評(píng)論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼耀石,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼牵囤!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,342評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤揭鳞,失蹤者是張志新(化名)和其女友劉穎炕贵,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體野崇,經(jīng)...
    沈念sama閱讀 45,801評(píng)論 1 317
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡鲁驶,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,976評(píng)論 3 337
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了舞骆。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片钥弯。...
    茶點(diǎn)故事閱讀 40,115評(píng)論 1 351
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖督禽,靈堂內(nèi)的尸體忽然破棺而出脆霎,到底是詐尸還是另有隱情,我是刑警寧澤狈惫,帶...
    沈念sama閱讀 35,804評(píng)論 5 346
  • 正文 年R本政府宣布睛蛛,位于F島的核電站,受9級(jí)特大地震影響胧谈,放射性物質(zhì)發(fā)生泄漏忆肾。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,458評(píng)論 3 331
  • 文/蒙蒙 一菱肖、第九天 我趴在偏房一處隱蔽的房頂上張望客冈。 院中可真熱鬧,春花似錦稳强、人聲如沸场仲。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,008評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)渠缕。三九已至,卻和暖如春褒繁,著一層夾襖步出監(jiān)牢的瞬間亦鳞,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,135評(píng)論 1 272
  • 我被黑心中介騙來泰國(guó)打工棒坏, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留燕差,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,365評(píng)論 3 373
  • 正文 我出身青樓俊抵,卻偏偏與公主長(zhǎng)得像谁不,于是被迫代替她去往敵國(guó)和親坐梯。 傳聞我的和親對(duì)象是個(gè)殘疾皇子徽诲,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,055評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容