Hexo + GitHub Pagesphp
E:\Blog\themes\next
中)
E:\Blog\themes\next\languages
中)
紅框中應爲中文關於
而非英文bout
html
黃框譯文node
鍵是菜單項名稱,區分大小寫。語言文件中找到該菜單譯文則加載譯文;無則用鍵名。
複製代碼
綠框中bout與about不對應致使語言文件中找不到該菜單譯文,從而顯示鍵名bout
而非關於
。 git
改綠框中bout爲about github
<!--more-->
hexo g
->hexo d -g
->hexo s
或hexo clean
->hexo g
->hexo d -g
->hexo s
Hexo評論頁官方推薦disqus,無奈被牆。這裏用第三方實現,對比:npm
安裝
E:\Blog\themes\next
中)中找到以下片斷:
hexo g
->hexo d -g
->hexo s
或hexo clean
->hexo g
->hexo d -g
->hexo s
註釋掉便可 json
npm install --save hexo-tag-aplayer
裝插件aplayer(音頻)Plugins
npm install hexo-tag-dplayer --save
裝插件dplayer(視頻)Plugins
{% aplayerlist %}
{
"narrow": false, //(可選)播放器袖珍風格
"autoplay": true, //(可選)自動播放,移動端瀏覽器暫不支持此功能
"mode": "random", //(可選)曲目循環類型,有'random'(隨機),'single'(單曲),'circulation'(循環),'order'(列表),默認'circulation'
"showlrc": 3, //(可選)歌詞顯示配置項,可選項一、二、3
"mutex": true, //(可選)該選項開啓時,同頁有其它aplayer播放則該播放器暫停
"theme": "#e6d0b2", //(可選)播放器風格色彩設置,默#b7daff
"preload": "metadata", //(可選)音樂文件預載入模式,可選項'none'、'metadata'、'auto',默'auto'
"listmaxheight": "513px", //(可選)該播放列表最大長度
"music": [
{
"title": "Sometimes When We Touch",
"author": "Oliveia",
"url": "https://molier-1256056152.cos.ap-guangzhou.myqcloud.com/SometimesWhenWeTouch.mp3",
"pic": "https://y.gtimg.cn/music/photo_new/T002R300x300M000003LIDEL0NQInJ.jpg?max_age=2592000",
"lrc": "https://歌詞.lrc"
}
]
}
{% endaplayerlist %}
複製代碼
pic即歌曲顯示圖片連接。建議歌詞lrc用URL形式,txt格式編輯易出問題。歌曲下載後上傳七牛雲可在七牛雲生成外鏈,七牛雲有免費存儲空間。但七牛雲歌曲外鏈不支持https致配有ssl證書的掉綠鎖,對該問題可棄七牛雲,改騰訊雲。瀏覽器
hexo g
->hexo d -g
->hexo s
或hexo clean
->hexo g
->hexo d -g
->hexo s
谷歌瀏覽器或Safari提示網站不被信任,點繼續纔可展現博客且地址欄顯紅色×。在此改博客協議爲Https。緩存
因GitHub Pages不支持上傳證書,故這裏主介紹在國外CDN服務提供商Cloudflare基礎上,經過CDN配置反向代理。 安全
Cloudflare提供DNS解析服務且速度很快,阿里雲半小時解析生效在此瞬間生效。它提供免費https服務(非應用SSL證書)。實現模式即用戶到CDN服務器鏈接爲https,而CDN服務器到Github Pages服務器鏈接爲http,即在CDN服務器處加反向代理。
官網註冊後添域名(購買)
點DNS進解析界面
紅框中開啓雲朵,否接下來沒法正確配置
複製代碼
上述驟操做完雖https且無紅叉,但不顯綠色小鎖而是歎號。緣由爲當前頁有非https連接致使,如圖片圖牀或評論插件不支持https,更換支持https圖牀或評論插件便可。
E:\Blog\themes\next
中)
hexo g
->hexo d -g
->hexo s
或hexo clean
->hexo g
->hexo d -g
->hexo s
hexo new page categories
新建categories頁
分類
並設頁面類型categories
,主題自動爲該頁顯示全部分類title: 分類
date: 2018-03-14 18:21:16
type: "categories"
複製代碼
啓用多說或Disqus評論,默認頁面也會帶評論。關閉則添字段comments並設false title: 分類 date: 2018-03-14 18:21:16 type: "categories" comments: false
E:\Blog\themes\next
中),開啓menu中categories: /categories/ || th
:menu:
home: / || home
about: /about/ || user
tags: /tags/ || tags
categories: /categories/ || th
archives: /archives/ || archive
#schedule: /schedule/ || calendar
#sitemap: /sitemap.xml || sitemap
#commonweal: /404/ || heartbeat
複製代碼
hexo g
->hexo d -g
->hexo s
或hexo clean
->hexo g
->hexo d -g
->hexo s
hexo new page tags
新建tags頁
標籤
並設頁面類型tags
,主題自動爲該頁顯示全部分類title: 標籤
date: 2018-03-16 10:32:43
type: "tags"
複製代碼
啓用多說或Disqus評論,默認頁面也會帶評論。關閉則添字段comments並設false title: 標籤 date: 2018-03-14 18:21:16 type: "tags" comments: false
E:\Blog\themes\next
中),開啓menu中tags: /tags/ || tags
:menu:
home: / || home
about: /about/ || user
tags: /tags/ || tags
categories: /categories/ || th
archives: /archives/ || archive
#schedule: /schedule/ || calendar
#sitemap: /sitemap.xml || sitemap
#commonweal: /404/ || heartbeat
複製代碼
hexo g
->hexo d -g
->hexo s
或hexo clean
->hexo g
->hexo d -g
->hexo s
Hexo流程即git工做流程,不論GitHub仍是BitBucket都遵循GitFlow。GitFlow即多終端多人協同工做解決方案,故用它實現多終端同步。
.
├── .deploy #需部署的文件
├── node_modules #Hexo插件
├── public #生成的靜態網頁文件
├── scaffolds #模板
├── source #博客正文和其它源文件,40四、favicon、CNAME都應放這裏
| ├── _drafts #草稿
| └── _posts #文章
├── themes #主題
├── _config.yml #全局配置文件
└── package.json
複製代碼
hexo g
source文件夾存放文章、tag、歸檔等信息,即博客內容。終端執行hexo g
時被source中文件按某種規則方式渲染成靜態頁面文件放到public中:
hexo d
將public中文件push到git倉庫hexo clean
同gitflow無關,清理緩存。運行前首先刪除public文件,而後執行hexo g
從新渲染進public,以後hexo d
進行部署。這樣即避免以前內容對咱們形成影響。hexo s
生成的本地服務器進程中止,不便邊寫邊預覽。/.deploy_git
,/public
,一個一行
/.deploy_git
/public
複製代碼
git init
初始化本地倉庫
git remote add origin git@github.com:xxx/xxx.github.io.git
git add .
添加全部本地文件到git
.
(不包含.gitignore
聲明文件)git commit -m "更新說明"
git提交
git branch hexo
新建分支hexo
git checkout hexo
切換分支爲hexo
git push origin hexo
推送到遠程倉庫hexo分支
假設B電腦無源文件
git clone -b git@github.com:xxx/xxx.github.io.git hexo
克隆hexo分支到本地npm install
安裝依賴,再也不初始化(hexo init
)git init
git remote add origin git@github.com:xxx/xxx.github.io.git
git fetch --all
git reset --hard origin/master
git init
初始化本地倉庫
git pull git@github.com:xxx/xxx.github.io.git hexo
拉取遠程倉庫hexo分支
hexo new post 「xxx」
建立博客git add source
添加source文件夾到本地git(僅source文件夾變更)
git commit -m "多終端同步更新博客"
)
git push origin hexo
推送到遠程倉庫hexo分支
hexo g -d
或hexo g
->hexo d -g
->hexo s
或hexo clean
->hexo g
->hexo d -g
->hexo s
部署Administrator@LKKJ0004 MINGW64 /e/Blog (hexo)
$ git pull git@github.com:snpmyn/snpmyn.github.io.git hexo
From github.com:snpmyn/snpmyn.github.io
* branch hexo -> FETCH_HEAD
Already up to date.
Administrator@LKKJ0004 MINGW64 /e/Blog (hexo)
$ git add source
warning: LF will be replaced by CRLF in source/_posts/博客搭建.md.
The file will have its original line endings in your working directory.
Administrator@LKKJ0004 MINGW64 /e/Blog (hexo)
$ git commit -m "fifth"
[hexo 305cf46] fifth
1 file changed, 34 insertions(+)
Administrator@LKKJ0004 MINGW64 /e/Blog (hexo)
$ git push origin hexo
Username for 'https://github.com': snpmyn
muyang541527remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/snpmyn/snpmyn.github.io.git/'
Administrator@LKKJ0004 MINGW64 /e/Blog (hexo)
$ muyang541527
bash: muyang541527: command not found
Administrator@LKKJ0004 MINGW64 /e/Blog (hexo)
$ git push origin hexo
Username for 'https://github.com': snpmyn
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (5/5), 1.02 KiB | 1.02 MiB/s, done.
Total 5 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To https://github.com/snpmyn/snpmyn.github.io.git
da365d3..305cf46 hexo -> hexo
Administrator@LKKJ0004 MINGW64 /e/Blog (hexo)
$ hexo clean
INFO Deleted database.
INFO Deleted public folder.
Administrator@LKKJ0004 MINGW64 /e/Blog (hexo)
$ hexo g -d
INFO Start processing
WARN ===============================================================
WARN ========================= ATTENTION! ==========================
WARN ===============================================================
WARN NexT repository is moving here: https://github.com/theme-next
WARN ===============================================================
WARN It's rebase to v6.0.0 and future maintenance will resume there WARN =============================================================== INFO Files loaded in 5.59 s INFO Generated: CNAME INFO Generated: index.html INFO Generated: categories/index.html INFO Generated: archives/index.html INFO Generated: images/cc-by-nc.svg INFO Generated: images/quote-l.svg INFO Generated: archives/2018/03/index.html INFO Generated: images/cc-by-sa.svg INFO Generated: archives/2018/index.html INFO Generated: categories/工具/index.html warning: LF will be replaced by CRLF in 2018/03/06/博客搭建/index.html. The file will have its original line endings in your working directory. [master d519607] Site updated: 2018-03-16 09:47:01 2 files changed, 11 insertions(+), 7 deletions(-) Branch 'master' set up to track remote branch 'master' from 'git@github.com:snpmyn/snpmyn.github.io.git'. To github.com:snpmyn/snpmyn.github.io.git cb58169..d519607 HEAD -> master INFO Deploy done: git Administrator@LKKJ0004 MINGW64 /e/Blog (hexo) $ hexo s INFO Start processing WARN =============================================================== WARN ========================= ATTENTION! ========================== WARN =============================================================== WARN NexT repository is moving here: https://github.com/theme-next WARN =============================================================== WARN It's rebase to v6.0.0 and future maintenance will resume there
WARN ===============================================================
INFO Hexo is running at http://localhost:4000/. Press Ctrl+C to stop.
INFO Bye!
Administrator@LKKJ0004 MINGW64 /e/Blog (hexo)
$
複製代碼
SEO(Search Engine Optimization)譯爲搜索引擎優化,即利用搜索引擎搜索規則提升目前網站在有關搜索引擎內天然排名。常見如網站結構調整、網站內容建設、網站代碼優化及站外優化。
搜索引擎輸入site:<域名>
,以下則代表網站沒被百度收錄。
layout:false
,便可不被hexo編譯。(驗證文件txt格式不須要)用npm自動生成sitemap(站點地圖)後提交sitemap到百度和其它搜索引擎。
npm install hexo-generator-sitemap --save
npm install hexo-generator-baidu-sitemap --save
複製代碼
E:\Blog
中)改url爲站點地址
E:\Blog
中)添以下代碼# 自動生成sitemap
sitemap:
path: sitemap.xml
baidusitemap:
path: baidusitemap.xml
複製代碼
hexo g
執行構建,正常狀況E:\Blog\public
下多出兩文件
通常主動提交比手動提交效果好,從效率上講:
主動推送>自動推送>sitemap
複製代碼
npm install hexo-baidu-url-submit --save
安裝插件
E:\Blog
中)新增字段baidu_url_submit
E:\Blog
中)加入新deploye
hexo g -d
或hexo g
->hexo d -g
或hexo clean
->hexo g
->hexo d -g
提交併推送E:\Blog\public
中生成baidu_urls
文件
網站全部權驗證
添加域名不對照
網站全部權驗證
重複操做,添加網站改www.muyang.site
爲muyang.site
。主題配置文件 _config.yml(E:\Blog\themes\next
中)設baidu_push爲true:
<script>
(function(){
var bp = document.createElement('script');
var curProtocol = window.location.protocol.split(':')[0];
if (curProtocol === 'https') {
bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
}
else {
bp.src = 'http://push.zhanzhang.baidu.com/push.js';
}
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(bp, s);
})();
</script>
複製代碼
提交sitemap文件到百度
兩天後登陸百度站長平臺,提示以下
一週後搜索引擎輸入site:<域名>
或域名
,以下代表網站已經被百度收錄。