以前寫過一篇關於octopress建立我的技術博客的文章,不少朋友說步驟好複雜啊(心塞)!此次,爲了知足這羣朋友,這裏我要教你們的是用Hexo建我的技術博客。html
這一步我不想展開太多,由於真的很簡單,關於GIT的配置我在以前的文章中已經提到過了,看官能夠查看歷史文章git
在桌面下使用GIT Bash輸入下面代碼,實現Hexo的安裝github
$ sudo npm install hexo-cli -g
初始化本身的我的博客shell
使用GIT Bash切換到你但願安裝我的博客的文件夾下npm
$ hexo init username.github.io
username就是Github中的用戶名,詳細查看hexo
在完成上一步後,其實就能夠運行查看頁面了,這一步讓你實現安裝本身喜歡的主題,看官能夠在Github網站中輸入hexo關鍵字,能夠搜索到不少相關主題,挑選一個就能夠了工具
我這裏使用NEXT這個主題進行講解,其餘的方式也是同樣的。post
使用GIT Bash切換到你剛纔我的博客安裝目錄測試
$ cd username.github.io $ git clone https://github.com/iissnan/hexo-theme-next themes/next
完成上面步驟,會在theme的目錄下多了一個next文件,說明主題下載成功了,但如今尚未配置完成網站
在username.github.io文件下有一個_config.yml文件,編輯它
將theme的value設爲本身的主題名,這裏是next——完成主題的配置
將deploy的value進行配置——完成主題發佈地址配置
# Extensions ## Plugins: https://hexo.io/plugins/ ## Themes: https://hexo.io/themes/ theme: next # Deployment ## Docs: https://hexo.io/docs/deployment.html deploy: type: git repo: git@github.com:username/username.github.io.git branch: master
在username.github.io/source/_posts目錄下建立你本身的文章,文章格式爲Markdown的.md格式
--- title: Hexo讓博客夢變的簡單 date: 2016-05-12 ---
title:文章名,date:發佈的日期
安裝自動部署發佈工具
使用GIT Bash切換到username.github.io目錄下
$ npm install hexo-deployer-git --save
編譯
$ hexo generate
本地測試
$ hexo s -p 4000
-p:設置端口號,默認爲4000,使用默認端口能夠省略
發佈到Github
首先在username.github.io文件下有一個_config.yml文件,編輯它
有一個depoly的key,對其進行配置,repo爲你在github中生成的username.github.io工程的clone地址,branch就是的分支名稱,就寫master就好了
# Deployment ## Docs: https://hexo.io/docs/deployment.html deploy: type: git repo: git@github.com:username/username.github.io.git branch: master
username.github.io目錄下,在編譯完成後,執行以下命令,就會將編譯生成的文件部署到github上,經過username.github.io的地址就能夠訪問了(本文章中的因此username都是你github的用戶名)
$ hexo d
這裏特別要提醒一下不要忘記在username.github.io文件下_config.yml文件,配置deploy
咱們經常可能會遇到系統重裝或者換電腦編輯的場景,備份變得尤其重要,這裏介紹一個hexo-git-backup備份工具
你們能夠根據本身的實際狀況,參照README.md說明進行配置
操做步驟1,2
將Github的備份clone到本地
$ git@github.com:username/username.github.io.git $ git checkout branchname
branchname:備份分支名
以上です(Ending)
ありがどう(Thank You)