【持續(xù)更新】最全Hexo個人博客搭建+主題優(yōu)化+插件配置+錯誤分析

前言

如果你和我一樣是小白,那么恭喜你!

看完這篇文章,你也可以擁有一個這樣的博客啦!


歡迎在文末留言,或者點擊加入QQ群933583982互相交流。

本文采用 CC BY-NC-SA 4.0 許可協(xié)議,轉(zhuǎn)載請注明出處!

歡迎閱讀原文:https://www.simon96.online/2018/10/12/hexo-tutorial/

Hexo博客搭建

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

Node.js 下載并安裝。

Git 下載并安裝。

安裝Hexo,在命令行輸入以下命令,運行即可:

npm install -g hexo-cli

初始化Hexo,在命令行依次輸入以下命令,運行即可:

其中<folder>為:存放Hexo初始化文件的路徑。

$ hexo init <folder>

$ cd <folder>

$ npm install

新建完成后,在<folder>路徑下,會產(chǎn)生這些文件和文件夾:

.

├── _config.yml

├── package.json

├── scaffolds

├── source

| ? ├── _drafts

| ? └── _posts

└── themes

啟動服務(wù)器。在<folder>路徑下,命令行輸入以下命令,運行即可:

hexo server

瀏覽器訪問網(wǎng)址: http://localhost:4000/

至此,您的Hexo博客已經(jīng)搭建在本地。

實施方案

方案一:GithubPages

創(chuàng)建Github賬號

創(chuàng)建倉庫, 倉庫名為:<Github賬號名稱>.github.io

將本地Hexo博客推送到GithubPages

3.1. 安裝hexo-deployer-git插件。在命令行輸入以下命令即可:

npm install hexo-deployer-git --save

3.2. 添加SSH key。

創(chuàng)建一個 SSH key 。在命令行輸入以下命令, 回車三下即可:

ssh-keygen -t rsa -C "郵箱地址"

添加到 github。 復(fù)制密鑰文件內(nèi)容(路徑形如C:\Users\Administrator\.ssh\id_rsa.pub),粘貼到New SSH Key即可。

測試是否添加成功。在命令行依次輸入以下命令,返回“You've successfully authenticated”即成功:

$ ssh -T git@github.com

?

$ yes

3.3. 修改_config.yml(在存放Hexo初始化文件的路徑下)。文件末尾修改為:

# Deployment

## Docs: https://hexo.io/docs/deployment.html

deploy:

? type: git

? repo: git@github.com:<Github賬號名稱>/<Github賬號名稱>.github.io.git

? branch: master

3.4. 推送到GithubPages。在命令行依次輸入以下命令, 返回INFO? Deploy done: git即成功推送:

$ hexo g

$ hexo d

瀏覽器訪問網(wǎng)址: https://<Github賬號名稱>.github.io

至此,您的Hexo博客已經(jīng)搭建在GithubPages, 域名為https://<Github賬號名稱>.github.io。

方案二:GithubPages + 域名

在方案一的基礎(chǔ)上,添加自定義域名(您購買的域名)。

域名解析。

類型選擇為 CNAME;

主機記錄即域名前綴,填寫為www;

記錄值填寫為自定義域名;

解析線路,TTL 默認(rèn)即可。

倉庫設(shè)置。

2.1. 打開博客倉庫設(shè)置:https://github.com/<Github賬號名稱>/<Github賬號名稱>.github.io/settings

2.2. 在Custom domain下,填寫自定義域名,點擊save。

等待10分鐘左右。

瀏覽器訪問自定義域名。

至此,您的Hexo博客已經(jīng)解析到自定義域名,https://<Github賬號名稱>.github.io依然可用。

方案三:GithubPages + CodingPages + 域名

GithubPages 在國內(nèi)較慢,百度不收錄,而CodingPages 在國外較快。所以在方案二的基礎(chǔ)上,添加CodingPages 。

創(chuàng)建Coding賬號

創(chuàng)建倉庫, 倉庫名為:<Coding賬號名稱>

進入項目里『代碼』頁面,點擊『一鍵開啟靜態(tài) Pages』,稍等片刻CodingPages即可部署成功。

將本地Hexo博客推送到CodingPages

4.1. 鑒于創(chuàng)建GithubPages 時,已經(jīng)生成過公鑰??芍苯訌?fù)制密鑰文件內(nèi)容(路徑形如C:\Users\Administrator\.ssh\id_rsa.pub), 粘貼到新增公鑰

4.2. 測試是否添加成功。在命令行依次輸入以下命令,返回“You've successfully authenticated”即成功:

$ ssh -T git@git.coding.net

?

$ yes

4.3. 修改_config.yml(在存放Hexo初始化文件的路徑下)。文件末尾修改為:

# Deployment

## Docs: https://hexo.io/docs/deployment.html

deploy:

- type: git

? repo: git@github.com:<Github賬號名稱>/<Github賬號名稱>.github.io.git

? branch: master

- type: git

? repo: git@git.dev.tencent.com:<Coding賬號名稱>/<Coding賬號名稱>.git

? branch: master

4.4. 推送到GithubPages。在命令行依次輸入以下命令, 返回INFO? Deploy done: git即成功推送:

$ hexo g

$ hexo d

域名解析

添加 CNAME 記錄指向 <Coding賬號名稱>.coding.me

類型選擇為 CNAME;

主機記錄即域名前綴,填寫為www;

記錄值填寫為自定義域名;

解析線路,TTL 默認(rèn)即可。

添加 兩條A 記錄指向 192.30.252.153和192.30.252.154

類型選擇為 A;

主機記錄即域名前綴,填寫為@;

記錄值填寫為192.30.252.153和192.30.252.154;

解析線路,境外或谷歌。

在『Pages 服務(wù)』設(shè)置頁(https://dev.tencent.com/u/<Coding賬號名稱>/p/<Coding賬號名稱>/git/pages/settings)中綁定自定義域名。

至此,您的Hexo博客已經(jīng)解析到自定義域名,https://<Github賬號名稱>.github.io和https://<Coding賬號名稱>.coding.me依然可用。

Hexo主題優(yōu)化

選擇主題

Hexo默認(rèn)的主題是landscape,推薦以下主題:

snippet

Hiero

JSimple

BlueLake

應(yīng)用主題

下載主題

將下載好的主題文件夾,粘貼到站點目錄的themes下。

更改站點配置文件_config.yml 的theme字段,為主題文件夾的名稱:

# Extensions

## Plugins: https://hexo.io/plugins/

## Themes: https://hexo.io/themes/

theme: <主題文件夾的名稱>

主題優(yōu)化

以上主題都有比較詳細(xì)的說明文檔,本節(jié)主要解決主題優(yōu)化的常見問題。

主題優(yōu)化一般包括:

設(shè)置「RSS」

添加「標(biāo)簽」頁面

添加「分類」頁面

設(shè)置「字體」

問題:引用國外字體鏡像較慢。

解決:可以改用國內(nèi)的。將\themes\*\layout_partials\head external-fonts.swig文件中fonts.google.com改成fonts.lug.ustc.edu.cn。

設(shè)置「代碼高亮主題」

側(cè)邊欄社交鏈接

問題:圖標(biāo)哪里找?

解決:Font Awesome

開啟打賞功能

問題:微信支付寶二維碼不美觀,規(guī)格不一。

解決:在線生成二維碼

設(shè)置友情鏈接

騰訊公益404頁面

站點建立時間

訂閱微信公眾號

設(shè)置「動畫效果」

問題:慢,需要等待 JavaScript 腳本完全加載完畢后才會顯示內(nèi)容。解決:將主題配置文件_config.yml中,use_motion字段的值設(shè)為 false 來關(guān)閉動畫。

設(shè)置「背景動畫」

主題優(yōu)化還包括:

添加背景圖

在 themes/*/source/css/_custom/custom.styl 中添加如下代碼:

body{

?? background:url(/images/bg.jpg);

?? background-size:cover;

?? background-repeat:no-repeat;

?? background-attachment:fixed;

?? background-position:center;

}

修改Logo字體

在 themes/*/source/css/_custom/custom.styl 中添加如下代碼:

@font-face {

?? font-family: Zitiming;

?? src: url('/fonts/Zitiming.ttf');

}

.site-title {

?? font-size: 40px !important;

? ? font-family: 'Zitiming' !important;

}

其中字體文件在 themes/next/source/fonts 目錄下,里面有個 .gitkeep 的隱藏文件,打開寫入你要保留的字體文件,比如我的是就是寫入 Zitiming.ttf ,具體字庫自己從網(wǎng)上下載即可。

修改內(nèi)容區(qū)域的寬度

編輯主題的 source/css/_variables/custom.styl 文件,新增變量:

// 修改成你期望的寬度

$content-desktop = 700px

?

// 當(dāng)視窗超過 1600px 后的寬度

$content-desktop-large = 900px

網(wǎng)站標(biāo)題欄背景顏色

.site-meta {

? background: $blue; //修改為自己喜歡的顏色

}

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

打開 themes/*/source/css/_custom/custom.styl ,在里面寫下如下代碼:

// 鼠標(biāo)樣式

? * {

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

? }

? :active {

? ?? cursor: url("http://om8u46rmb.bkt.clouddn.com/sword1.ico"),auto!important

? }

文章加密訪問

打開 themes/*/layout/_partials/head.swig文件,在 {% if theme.pace %} 標(biāo)簽下的 {% endif %} 之前插入代碼:

<script>

?? (function(){

? ? ?? if('{{ page.password }}'){

? ? ? ? ?? if (prompt('請輸入密碼') !== '{{ page.password }}'){

? ? ? ? ? ? ?? alert('密碼錯誤');

? ? ? ? ? ? ?? history.back();

? ? ? ? ?? }

? ? ?? }

?? })();

</script>

寫文章時加上password: *:

---

title: 2018

date: 2018-10-25 16:10:03

password: 123456

---

實現(xiàn)點擊出現(xiàn)桃心效果

在/themes/*/source/js/src下新建文件click.js,接著把以下粘貼到click.js文件中。代碼如下:

!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);

在\themes\*\layout\_layout.swig文件末尾添加:

<!-- 頁面點擊小紅心 -->

<script type="text/javascript" src="/js/src/clicklove.js"></script>

靜態(tài)資源壓縮

在站點目錄下:

$ npm install gulp -g

安裝gulp插件:

npm install gulp-minify-css --save

npm install gulp-uglify --save

npm install gulp-htmlmin --save

npm install gulp-htmlclean --save

npm install gulp-imagemin --save

在 Hexo 站點下添加 gulpfile.js文件,文件內(nèi)容如下:

var gulp = require('gulp');

var minifycss = require('gulp-minify-css');

var uglify = require('gulp-uglify');

var htmlmin = require('gulp-htmlmin');

var htmlclean = require('gulp-htmlclean');

var imagemin = require('gulp-imagemin');

// 壓縮css文件

gulp.task('minify-css', function() {

? return gulp.src('./public/**/*.css')

? .pipe(minifycss())

? .pipe(gulp.dest('./public'));

});

// 壓縮html文件

gulp.task('minify-html', function() {

? return gulp.src('./public/**/*.html')

? .pipe(htmlclean())

? .pipe(htmlmin({

?? removeComments: true,

?? minifyJS: true,

?? minifyCSS: true,

?? minifyURLs: true,

? }))

? .pipe(gulp.dest('./public'))

});

// 壓縮js文件

gulp.task('minify-js', function() {

?? return gulp.src(['./public/**/.js','!./public/js/**/*min.js'])

? ? ?? .pipe(uglify())

? ? ?? .pipe(gulp.dest('./public'));

});

// 壓縮 public/demo 目錄內(nèi)圖片

gulp.task('minify-images', function() {

?? gulp.src('./public/demo/**/*.*')

? ? ?? .pipe(imagemin({

? ? ? ? ? optimizationLevel: 5, //類型:Number? 默認(rèn):3? 取值范圍:0-7(優(yōu)化等級)

? ? ? ? ? progressive: true, //類型:Boolean 默認(rèn):false 無損壓縮jpg圖片

? ? ? ? ? interlaced: false, //類型:Boolean 默認(rèn):false 隔行掃描gif進行渲染

? ? ? ? ? multipass: false, //類型:Boolean 默認(rèn):false 多次優(yōu)化svg直到完全優(yōu)化

? ? ?? }))

? ? ?? .pipe(gulp.dest('./public/uploads'));

});

// 默認(rèn)任務(wù)

gulp.task('default', [

? 'minify-html','minify-css','minify-js','minify-images'

]);

只需要每次在執(zhí)行 generate 命令后執(zhí)行 gulp 就可以實現(xiàn)對靜態(tài)資源的壓縮,壓縮完成后執(zhí)行 deploy 命令同步到服務(wù)器:

hexo g

gulp

hexo d

修改訪問URL路徑

默認(rèn)情況下訪問URL路徑為:domain/2018/10/18/關(guān)于本站,修改為 domain/About/關(guān)于本站。 編輯 Hexo 站點下的 _config.yml 文件,修改其中的 permalink字段:

permalink: :category/:title/

博文置頂

安裝插件

$ npm uninstall hexo-generator-index --save$ npm install hexo-generator-index-pin-top --save

然后在需要置頂?shù)奈恼碌腇ront-matter中加上top即可:

---

title: 2018

date: 2018-10-25 16:10:03

top: 10

---

設(shè)置置頂標(biāo)志

打開:/themes/*/layout/_macro/post.swig,定位到<div class="post-meta">,插入以下代碼即可:

? ?? {% if post.top %}

? ? ?? <i class="fa fa-thumb-tack"></i>

? ? ?? <font color=7D26CD>置頂</font>

? ? ?? <span class="post-meta-divider">|</span>

? ?? {% endif %}

在右上角或者左上角實現(xiàn)fork me on github

選擇樣式GitHub Ribbons,

修改圖片跳轉(zhuǎn)鏈接,將<a >中的鏈接換為自己Github鏈接:

打開 themes/next/layout/_layout.swig 文件,把代碼復(fù)制到<div class="headband"></div>下面。

主頁文章添加邊框陰影效果

打開 themes/*/source/css/_custom/custom.styl ,向里面加代碼:

// 主頁文章添加陰影效果

.post {

? margin-top: 0px;

? margin-bottom: 60px;

? padding: 25px;

? -webkit-box-shadow: 0 0 5px rgba(202, 203, 203, .5);

? -moz-box-shadow: 0 0 5px rgba(202, 203, 204, .5);

}

顯示當(dāng)前瀏覽進度

修改themes/*/_config.yml,把 false 改為 true:

# Back to top in sidebar

b2t: true

?

# Scroll percent label in b2t button

scrollpercent: true

創(chuàng)建分類頁

在終端窗口下,定位到 Hexo 站點目錄下,新建:

$ cd <站點目錄>

$ hexo new page categories

加入 廣告

主要有兩種:百度SSP谷歌Adsense。方法類似:

注冊,復(fù)制廣告代碼

部署到網(wǎng)站。

2.1. 新建 theme/*/layout/_custom/google_ad.swig,將 AdSense 上的代碼粘貼進去

2.2. 頭部。在 theme/*/layout/_custom/head.swig 中也粘貼一份

2.3. 每篇博客。在 theme/*/layout/post.swig 里中在希望看到的地方加上:

{% include '_custom/google_ad.swig' %}

例如:在 <div id="posts" class="posts-expand"> </div> 中間插入,總代碼如下:

{% block content %}

? <div id="posts" class="posts-expand">

?? {{ post_template.render(page) }}

?? {% include '_custom/google_ad.swig' %}

? </div>

{% endblock %}

等待審核通過。如果失敗,可再次申請。

添加萌萌噠

安裝插件

npm install --save hexo-helper-live2d

復(fù)制你喜歡的模型名字:

Epsilon2.1

Gantzert_Felixander

haru

miku

ni-j

nico

nietzche

nipsilon

nito

shizuku

tsumiki

wanko

z16

hibiki

koharu

haruto

Unitychan

tororo

hijiki

將以下代碼添加到主題配置文件_config.yml,修改<你喜歡的模型名字>:

live2d:

? enable: true

? scriptFrom: local

? pluginRootPath: live2dw/

? pluginJsPath: lib/

? pluginModelPath: assets/

? tagMode: false

? log: false

? model:

? ? use: <你喜歡的模型名字>

? display:

? ? position: right

? ? width: 150

? ? height: 300

? mobile:

? ? show: true

Hexo插件配置

以下插件(評論系統(tǒng)、數(shù)據(jù)統(tǒng)計與分析、內(nèi)容分享服務(wù)、搜索服務(wù))各選一個即可。

評論系統(tǒng)

推薦指數(shù)優(yōu)點缺點

Valine4每天30000條評論,10GB的儲存作者評論無標(biāo)識

來必力/livere4多種賬號登錄評論無法導(dǎo)出

暢言3美觀必須備案域名

gitment3簡潔只能登陸github評論

Disqus1需要翻*墻

Valine

1.1. 獲取APP ID 和 APP Key

請先登錄或注冊 LeanCloud, 進入控制臺后點擊左下角創(chuàng)建應(yīng)用,

進入剛剛創(chuàng)建的應(yīng)用,選擇左下角的設(shè)置>應(yīng)用Key,然后就能看到你的APP ID和APP Key了。

1.2. 填寫APP ID 和 APP Key到主題配置文件_config.yml

1.3. 運行hexo g&&hexo d推送到博客。

來必力/livere

2.1. 登陸 來必力 獲取你的 LiveRe UID。

2.2. 填寫LiveRe UID到主題配置文件_config.yml

暢言

3.1.獲取APP ID 和 APP Key

請先登錄或注冊 暢言, 點擊“立即免費獲取暢言”,

新建站點,點擊管理,點擊評論插件>評論管理,

點擊后臺總覽,然后就能看到你的APP ID和APP Key了。

3.2. 填寫APP ID 和 APP Key到主題配置文件_config.yml

3.3. 運行hexo g&&hexo d推送到博客。

gitment

4.1. 安裝插件:

npm i --save gitment

4.2. 申請應(yīng)用

New OAuth App為你的博客應(yīng)用一個密鑰:

Application name:隨便寫

Homepage URL:這個也可以隨意寫,就寫你的博客地址就行

Application description:描述,也可以隨意寫

Authorization callback URL:這個必須寫你的博客地址

4.3. 配置

編輯主題配置文件themes/*/_config.yml:

# Gitment

# Introduction: https://imsun.net/posts/gitment-introduction/

gitment:

? enable: true

? mint: true # RECOMMEND, A mint on Gitment, to support count, language and proxy_gateway

? count: true # Show comments count in post meta area

? lazy: false # Comments lazy loading with a button

? cleanly: false # Hide 'Powered by ...' on footer, and more

? language: # Force language, or auto switch by theme

? github_user: {you github user id}

? github_repo: 公開的git倉庫,評論會作為那個項目的issue

? client_id: {剛才申請的ClientID}

? client_secret: {剛才申請的Client Secret}

? proxy_gateway: # Address of api proxy, See: https://github.com/aimingoo/intersect

? redirect_protocol: # Protocol of redirect_uri with force_redirect_pro

Disqus

編輯 主題配置文件themes/*/_config.yml, 將 disqus 下的 enable 設(shè)定為 true,同時提供您的 shortname。count 用于指定是否顯示評論數(shù)量。

disqus:

? enable: false

? shortname:

? count: true

數(shù)據(jù)統(tǒng)計與分析

推薦指數(shù)優(yōu)點缺點

不蒜子4可直接將訪問次數(shù)顯示在您在網(wǎng)頁上(也可不顯示)只計數(shù)

百度統(tǒng)計3收錄慢

不蒜子

編輯 主題配置文件 themes/*/_config.yml中的busuanzi_count的配置項即可。

當(dāng)enable: true時,代表開啟全局開關(guān)。

若site_uv(本站訪客數(shù))、site_pv(本站訪客數(shù))、page_pv(本文總閱讀量)的值均為false時,不蒜子僅作記錄而不會在頁面上顯示。

百度統(tǒng)計

登錄 百度統(tǒng)計,定位到站點的代碼獲取頁面

復(fù)制統(tǒng)計腳本 id,如圖:?? ? ? ? ? ? ?

編輯 主題配置文件themes/*/_config.yml,修改字段 google_analytics,值設(shè)置成你的統(tǒng)計腳本 id。

內(nèi)容分享服務(wù)

推薦指數(shù)優(yōu)點缺點

百度分享4穩(wěn)定不太美觀

need-more-share24美觀更新不及時(比如微信分享API)

百度分享

編輯 主題配置文件,添加/修改字段 baidushare,值為 true即可。

# 百度分享服務(wù)

baidushare: true

need-more-share2

編輯 主題配置文件,添加/修改字段 needmoreshare2,值為 true即可。

needmoreshare2:

? enable: true

搜索服務(wù)

推薦指數(shù)優(yōu)點缺點

Local Search4配置方便

Swiftype2需注冊

Algolia2需注冊

Local Search

添加百度/谷歌/本地 自定義站點內(nèi)容搜索

安裝 hexo-generator-searchdb,在站點的根目錄下執(zhí)行以下命令:

$ npm install hexo-generator-searchdb --save

編輯 站點配置文件,新增以下內(nèi)容到任意位置:

search:

? path: search.xml

? field: post

? format: html

? limit: 10000

編輯 主題配置文件,啟用本地搜索功能:

# Local search

local_search:

? enable: true

錯誤分析

如果你使用Hexo遇到同樣的問題,這里有一些常見問題的解決方案。

YAML Parsing Error

JS-YAML: incomplete explicit mapping pair; a key node is missed at line 18, column 29:

? ? ? last_updated: Last updated: %s

參數(shù)中包含冒號,請用加引號,如Last updated: %s

JS-YAML: bad indentation of a mapping entry at line 18, column 31:

? ? ? last_updated:"Last updated: %s"

字段后面的冒號必須為英文冒號,如:last_updated:

字段冒號后面必須跟一個空格,如:last_updated: "Last updated: %s"

EMFILE Error

Error: EMFILE, too many open files

生成大量的文件時,可能遇到EMFILE錯誤。

可以運行以下命令來增加允許同步I / O操作的數(shù)量。

$ ulimit -n 10000

Process Out of Memory

當(dāng)hexo g時,遇到以下錯誤:

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory

如下,更改hexo-cli文件的第一行,來增大nodejs堆內(nèi)存.該bug已在新版本修復(fù)。

#!/usr/bin/env node --max_old_space_size=8192

Git Deployment Problems

RPC failed

error: RPC failed; result=22, HTTP code = 403

fatal: 'username.github.io' does not appear to be a git repository

確保你有你的電腦上設(shè)置git正確或嘗試使用HTTPS存儲庫URL。

Error: ENOENT: no such file or directory

這個需要有一定的git的知識,因為可能是由于寫錯了標(biāo)簽,類別,或文件名,導(dǎo)致本地和github沖突了,Git不能自動合并這一變化所以它打破了自動分支。

解決辦法:

檢查文章的標(biāo)簽和類別,確保本地和github上是相同的。

合并分支(Commit)。

清除,重構(gòu)。在站點目錄下,命令行運行hexo clean和hexo g

手動將站點目錄下的public文件夾復(fù)制到您的桌面

從你的master分支切換到部署在本地分支。

從桌面復(fù)制public文件夾到本地分支。

合并分支到github(Commit)。

切回master分支。

Server Problems

Error: listen EADDRINUSE

你可能使用相同的端口,同時開啟了兩個Hexo服務(wù)器。如果需要同時開啟,可以嘗試修改端口設(shè)置:

$ hexo server -p 5000

Plugin Installation Problems

npm ERR! node-waf configure build

這個錯誤可能發(fā)生在試圖安裝一個用Cc++或另一個javascript語言編寫的插件。確保您已經(jīng)安裝了正確的編譯器在您的計算機上。

Error with DTrace (Mac OS X)

{ [Error: Cannot find module './build/Release/DTraceProviderBindings'] code: 'MODULE_NOT_FOUND' }

{ [Error: Cannot find module './build/default/DTraceProviderBindings'] code: 'MODULE_NOT_FOUND' }

{ [Error: Cannot find module './build/Debug/DTraceProviderBindings'] code: 'MODULE_NOT_FOUND' }

DTrace安裝可能有問題,重裝:

$ npm install hexo --no-optional

詳見 #1326

Iterate Data Model on Jade or Swig

Hexo使用倉庫的數(shù)據(jù)模型。這不是一個數(shù)組,所以你可能需要將對象轉(zhuǎn)換為iterable。

{% for post in site.posts.toArray() %}

{% endfor %}

Data Not Updated

一些數(shù)據(jù)不能更新或新生成的文件的最后一個版本完全相同。清理緩存,再試一次:

$ hexo clean

No command is executed

那個不能使用除help、init和version以外的命令行時,? 有可能時站點目錄下的? package.json文件,缺少hexo ,如下:

{

? "hexo": {

? ? "version": "3.2.2"

? }

}

Escape Contents

Hexo使用Nunjucks渲染的頁面. { { } }或{ % % }將解析和可能會引起麻煩, 如果要在博文中出現(xiàn),必須使用三引號:

?```

{% raw %}

Hello {{ sensitive }}

{% endraw %}

?```

ENOSPC Error (Linux)

如果運行命令$ hexo server 返回一個錯誤:

Error: watch ENOSPC ...

可以通過運行$ npm dedupe或者以下命令行:

$ echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

來增加測試時,你可以看見的文件數(shù)量。

EMPERM Error (Windows Subsystem for Linux)

如果在Windows Subsystem for Linux,運行命令$ hexo server 返回這個錯誤:

Error: watch /path/to/hexo/theme/ EMPERM

因為目前在Windows Subsystem for Linux中,有些內(nèi)容更改時,還不能實時更新到hexo服務(wù)器。

所以需要重新編譯,再啟動服務(wù)器:

$ hexo generate

$ hexo server -s

Template render error

有時運行命令$ hexo generate 返回一個錯誤:

FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html

Template render error: (unknown path)

這意味著有些認(rèn)不出來單詞在你的文件,并且很可能在你的新博文,或者配置文件_config.yml中,比如縮進錯誤:

錯誤例子:

plugins:

- hexo-generator-feed

- hexo-generator-sitemap

正確例子:

plugins:

? - hexo-generator-feed

? - hexo-generator-sitemap

感謝支持

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。