Hexo博客系列(二)-在多臺機器上利用Hexo發佈博客

【原文鏈接】:https://www.tecchen.xyz/2019/01/09/blog-hexo-env-02.html
針對在公司及家裏的電腦上都有編輯發佈博客的可能,或者多人同時維護一個博客的情況,需要在多臺機器上配置環境好環境,然後將Git倉庫中的博客更新下來,繼續編輯發佈博客。
個人是將博客託管在Gitee(碼雲)的倉庫,將NexT主題託管在Github上的倉庫。
因爲博客源碼需要放在私有倉庫(Github也已經開發私有倉庫了,Gitlab本來就支持私有倉庫),不開放出來,NexT主題是直接fork的NexT官方主題(https://github.com/theme-next/hexo-theme-next/ ),根據自己的需要進行修改保存。
下面介紹已有博客倉庫和主題倉庫的情況下,如何在各臺機器進行配置。

日常寫博客

正常情況下,僅僅需要到博客根路徑和主題根路徑,使用git pull拉取最新代碼。

  • 第一步:clone自己的hexo博客項目
git clone [email protected]:java4candy/tecchen.git tecchen
  • 第二步:clone自己的next主題項目
git clone [email protected]:java4candy/hexo-theme-next.git tecchen/themes/next
  • 第三步:啓動服務器
hexo clean && hexo generate && hexo server
  • 第四步:使用瀏覽器進行訪問
    訪問http://localhost:4000/ 即可。

初始化環境

以下僅限在新機器上進行一次性操作。

  • 第一步:clone自己的hexo博客項目
git clone [email protected]:java4candy/tecchen.git tecchen
  • 第二步:clone自己的next主題項目
git clone [email protected]:java4candy/hexo-theme-next.git tecchen/themes/next
  • 第三步:安裝hexo【一定不要執行hexo init,其實執行後,也會提示文件夾不爲空。】
npm install -g

該命令會根據package.json中的dependencies將依賴下載並安裝到node_modules目錄。
可以使用npm ls -dept 0查看具體有哪些依賴。

+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
`-- [email protected]
  • 第四步:啓動服務器
    使用hexo server或者簡寫hexo s啓動服務器
hexo clean && hexo generate && hexo server
  • 第五步:使用瀏覽器進行訪問
    訪問http://localhost:4000/ 即可。

如果頁面打開後,部分區域空白,則可以按F12,查看控制檯的js報錯。
由於我配置了圖片放大功能的fancybox,控制檯報錯如下:

如果提示找不到fancybox相關的文件,則可以根據以下方案進行解決。

方案一:

禁用fancybox,在~\themes\next_config.yml中搜索fancybox,並設置fancybox爲false。
fancybox: false

方案二:

根據_config.yml中的註釋提示或者之前開啓fancybox配置的步驟,安裝fancybox3。
鏈接:https://github.com/theme-next/theme-next-fancybox3
命令:

cd ~\themes\next # 進入到NexT主題根目錄
git clone https://github.com/theme-next/theme-next-fancybox3 source/lib/fancybox

刷新頁面,成功訪問。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章