前言:html
Node.js+Hexo+Next+Git+GitHub,讓你幾分鐘就能建立一個屬於你本身的博客node
網上不少資料因爲版本緣由,實現方法已經發生變化,這裏貼出一些新版本更方便的方法,若是失效,請聯繫我git
本系列文章 所說起方案所有通過實驗證實有效,基於Node ,Hexogithub
本文首發於個人博客 點擊查看哦!以下圖
npm
另外發現apkbus markdown一個小問題,對md支持略微欠缺,標籤識別不是很友好瀏覽器
talk is cheap ,下面開始緩存
Node.jsbash
Gitmarkdown
GitHub 帳戶及倉庫hexo
建立博客目錄,該目錄下 :git bash
輸入命令: npm 更換cpm命令 更快(百度下很容易怎麼更換的)
npm install -g hexo-cli
博客目錄下
hexo init
npm install
必需要改動的
title: xxx # 博客名,站點名稱author: xxx # 博客做者名字description: xxx # 對站點的描述,搜索引擎會抓取,能夠自定義language: zh-Hans # 語言 簡體中文theme: next # 配置主題,後面會講到主題配置
發佈必需要增長的
deploy: # 部署相關配置 type: git # 使用 Git 提交 repository: git@github.com/username/username.github.io.git# 博客倉庫地址 #repository: https://github.com/xxx/xxx.github.io.git
注意:
nodejs 3.0版本以上再也不使用:https://github.com/username/username.github.io.git
生成文件
hexo g
或 hexo generate
啓動服務
hexo s` 或 `hexo server
瀏覽器輸入localhost:4000查看
確認站點配置文件配置正確
deploy: type: git repository: https://github.com:username/username.github.io.git branch: master
發佈
hexo clean && hexo g && hexo d
發佈無反應且頁面爲404時:
站點配置:repository: git@github.com:path/username.github.io.git
,GitHub倉庫需爲username.github.io
每次修改本地配置文件後,須要hexo generate才能保存。每次使用命令時,都要在博客所在目錄下進行。
恭喜,博客已經初步建立成功
hexo new "博客文章文件名"
或新建md文件放到
/source/_posts文件夾或其子文件夾中
文章要按照規定格式書寫
如:
--- title: 我的博客搭建詳解(Windows和Mac通用版) # 這是標題tags: # 這裏寫的標籤會自動聚集到 tags 頁面上- 實用 # 可配置多個標籤,注意格式- 我的博客 category: # 這裏寫的分類會自動聚集到 categories 頁面上,分類能夠多級- 實用技術 # 一級分類- 我的博客 # 二級分類 ---
清除緩存: hexo clean
生成靜態網頁: hexo g
預覽: hexo s
注意
也可一次性執行:hexo clean && hexo g && hexo s
命令:hexo new page "categories"
找到 index.md文件編輯:
增長頁面類型:
type: "categories" #將頁面的類型設置爲categories
hexo new page "tags"
index.md文件
設置頁面類型:
type: "tags"
站點配置:啓用分類及標籤,清除緩存,生成頁面,啓動服務預覽,無問題後發佈
hexo new page "404"
編輯source/404.md便可
404頁面參考Next
git clone https://github.com/iissnan/hexo-theme-next themes/next
建議:
若想多端同步修改博客,最好先將此主題fork到本身github倉庫,再下載。不然,沒法對主題進行push,此處有坑,若無此需求,無視
主題文件拷貝到themes目錄下
hexo generate 保存
# Schemes scheme: Muse #scheme: Mist #scheme: Pisces #scheme: Gemini
hexo clean && hexo g && hexo s
博客已經初步完成。
hexo clean #清除緩存hexo g #保存修改,生成文件hexo s #啓動本地服務hexo d #發佈到遠程hexo init #生成站點hexo new page "xxx" #生成頁面hexo new "" #生成文章npm install --save xxx #安裝插件npm unstall xxx #卸載插件
上述命令將貫穿於整個博客過程,不難,能動手儘可能別複製粘貼
全程在博客目錄下進行,離不開gitbash
遇到問題不要慌,大膽猜想當心驗證
Site key: value#字段後必須空格
問題:ERROR Deployer not found: git
若是使用git方式進行部署須要
須要安裝對應的插件
解決:安裝自動部署發佈工具
npm install hexo-deployer-git --save
參考:知乎
解決:
站點配置文件
# URLurl: http://yoursite.com
url不能爲空
定位:
站點配置:發佈地址爲https://github.com/path/username.github.io.git
解決:
3.0版本以上使用以下配置:
發佈地址修改成 git@github.com:yourname/yourname.github.io.git
git bash 提示以下表示發佈成功
定位:手動新建的md文件 放於source文件夾且 文件遵照規則
解決:
使用git bash 命令: hexo new"xxx文件名"
此時 自動在source文件夾下生成 xxx文件名的md 文件,自帶標題,修改此標題 便可
遵照規則
--- title: 文章測試文件 tags: category: ---
啓動服務,驗證:成功
遵照規則
成功
復現失敗
猜想:網頁緩存或瀏覽器緩存致使,待驗證
問題重點: Error: Unable to call __, which is undefined or falsey
定位:
md文件出現不識別字符:'__'
解決: 找到對應字符,轉義或刪除
參考知乎
使用 hexo new page"404"
,編輯index.md文件便可
圖片放於
主題:./themes/next/source/images/路徑,顯示成功
站點:./source/uploads/路徑,顯示失敗
主題完整路徑:./themes/next/source/images/avatar.jpg
主題配置:avatar: /images/avatar.jpg
參考 主題配置文件
index.md文件增長comments: false #關閉頁面評論顯示
改成``` 包裹代碼 標記
可正常顯示 歡迎你們訪問個人新博客adubolg.tk