參考:css
搭建流程 http://blog.netpi.me/%E5%AE%9E%E7%94%A8/hexo/ http://www.cnblogs.com/zhcncn/p/4097881.html http://moxfive.xyz/ http://ibruce.info/2013/11/22/hexo-your-blog/
參考連接:https://cnodejs.org/topic/4f9904f9407edba21468f31e
鏡像使用方法(三種辦法任意一種都能解決問題,建議使用第三種,將配置寫死,下次用的時候配置還在):html
經過config命令java
npm config set registry https://registry.npm.taobao.org npm info underscore (若是上面配置正確這個命令會有字符串response)
命令行指定node
npm --registry https://registry.npm.taobao.org info underscore
編輯 ~/.npmrc 加入下面內容jquery
registry = https://registry.npm.taobao.org
搜索鏡像: https://npm.taobao.orggit
創建或使用鏡像,參考: https://github.com/cnpm/cnpmjs.orggithub
npm install hexo-cli -g npm install hexo --save # 這步驟是用於發佈到 git npm install hexo-deployer-git --save
#這個 blog 是文件名 $ hexo init blog $ cd blog #安裝node_modules,使代碼支持 本機server瀏覽 $ npm install $ hexo server
此時文件目錄爲ajax
blog \_config\_yml // 注配置文件 db.json // 數據 debug.log // 調試日誌 \_node\_mudules // nodejs 相關依賴 package.json // 配置依賴 scaffolds // 腳手架 - 也就是一個工具模板 source // 存放blog正文的地方 themes // 存放皮膚的地方
默認訪問 http://localhost:4000npm
若是你的電腦沒有翻-牆 可能會打不開頁面。由於頁面中默認使用了ajax.google.com 下的js包。所以咱們要把包刪掉json
解決辦法:
進入你剛新建好的 blog根目錄 ,進入 themes/landscape/layout/_partial
找到 after-footer.ejs ,把
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"> </script>
替換成
<script src="http://cdn.bootcss.com/jquery/2.1.1/jquery.min.js" > </script>
找到 header.ejs
註釋掉或者刪掉 下面這句css引用
<link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="styleshee" type"」text/cs">
從新 hexo server 以後。訪問 http://localhost:4000 就會看到blog主頁了。
當咱們想寫一篇blog時 在blog根目錄下咱們能夠經過
hexo new <title>
指令來實現
例如咱們想新建一篇主題爲hello的blog
hexo new hello
輸出信息以下
[info] File created at /Users/Night/Web/projects/java/temp/blog-test/source/_posts/hello.md
hexo會在 source/_posts/ 下新建hello.md 文件。
編輯 hello.md 就是編輯你的blog內容了 — markdown語法
hello.md 的文檔和目錄能夠這樣添加
title: postName #文章頁面上的顯示名稱,能夠任意修改,不會出如今URL中 date: 2013-12-02 15:30:16 #文章生成時間,通常不改,固然也能夠任意修改 categories: example #分類 tags: [tag1,tag2,tag3] #文章標籤,可空,多標籤請用格式,注意:後面有個空格 description: 附加一段文章摘要,字數最好在140字之內。 // 你的內容 <!--more--> // 以上爲摘要
由於咱們的blog要部署到github靜態服務器上面,全部咱們還要將頁面進行靜態化
hexo 爲咱們提供了 hexo g 的方法。進入blog根目錄,執行
$ hexo g
會有以下提示信息
[info] Files loaded in 0.081s [create] Generated: archives/index.html (48ms) [create] Generated: archives/2014/index.html (10ms) [create] Generated: archives/2014/10/index.html (7ms) [create] Generated: index.html (9ms) [create] Generated: 2014/10/19/hello-world/index.html (19ms) [create] Generated: js/script.js (5ms) ..... [create] Generated: fancybox/helpers/jquery.fancybox-buttons.js (0ms) [create] Generated: fancybox/helpers/jquery.fancybox-media.js (1ms) [create] Generated: fancybox/helpers/jquery.fancybox-thumbs.css (2ms) [create] Generated: fancybox/helpers/jquery.fancybox-thumbs.js (1ms) [info] 28 files generated in 0.565s
blog根目錄下會生成public文件夾-裏面就是剛纔生成的靜態文件
hexo 的詳細實用說明請參看官方文檔
以上咱們就完成了本地的博客系統環境搭建,在 【github】-【將blog部署到 github】中咱們會介紹如何將博客系統部署到 github 中。
hexo new "postName" #新建文章
hexo new page "pageName" #新建頁面
hexo generate #生成靜態頁面至public目錄
hexo server #開啓預覽訪問端口(默認端口4000,'ctrl + c'關閉server)
hexo deploy #將.deploy目錄部署到GitHub
關於hexo server: 啓動本地服務器,用於預覽主題。默認地址: http://localhost:4000/ 預覽的同時能夠修改文章內容或主題代碼,保存後刷新頁面便可; 對 Hexo 根目錄 _config.yml 的修改,須要重啓本地服務器後才能預覽效果。
經常使用複合命令:
hexo d -g #生成加部署
hexo s -g #預覽加部署
簡寫:
hexo n == hexo new
hexo g == hexo generate
hexo s == hexo server
hexo d == hexo deploy
登陸GitHub,註冊自定義用戶名如gitfeng,不建議用戶名中有大寫字母,下劃線、短橫線等非數字、小寫字母字符。
在主頁右下角建立New repository,name必須和用戶名一致如gitfeng.github.io。
這裏試過若是用戶名中有大寫字母,短橫線等狀況,會致使訪問 http://{name}.github.io失敗。
部署到github 很是簡單。由於hexo已經爲你集成好了發佈到github的配置。
咱們只須要修改 blog 目錄下的 _config.yml 文件。打開 _config.yml 找到以下配置
deploy: type: github repo: https://github.com/yourname/blog.git
修改 repo : 'your github repo'。回到 blog 目錄 執行
hexo deploy
便可將本地 hexo 博客內容發佈到 github平臺上。
日後咱們要作的就是用本身的域名指向 github。
yaml語法要求嚴格,注意空格。建議把github地址那條語句從新手寫一遍,冒號後面要有一個空格。 配置那裏的冒號後面是有一個半角的空格的.若是中間有空格用分號引用一下
這裏介紹萬網購買域名的綁定規則, 有兩種,
配一級域名 如 www.baidu.com , 這個驗證經過
配二級域名 如 zhidao.baidu.com ,還沒有驗證
在萬網搜索喜歡的域名購買
若是配一級域名,則直接配域名與192.30.252.153,192.30.252.154 ip的綁定,若是執行二級域名,執行命令
ping {name}.github.io
獲取 ip 地址
購買完成後,在萬網提供的域名解析配置頁面配置域名解析到 第2步中得到的 ip 地址
可經過ping {域名} 判斷域名解析是否生效,此過程須要等10分鐘~2小時
在 GitHub 的代碼倉庫根目錄下加 CNAME 文件,文件中只寫本身申請的域名,域名不須要包括 http://www.的前綴
可參考:http://jingyan.baidu.com/article/3c343ff70fb6e60d3779632f.html
在 source目錄下添加 CNAME 文件,下次發佈便可直接帶上。REAMDME.md 等文件也可相似處理
rss的安裝很是簡單 ,已經有人作好了插件,安裝只需一步。
npm install hexo-generator-feed
啓動服務器,用瀏覽器打開 http://localhost:4000/atom.xml, 就能夠看到RSS已經生效了。
一樣是一條命令,就能夠完成。
npm install hexo-generator-sitemap
啓動服務器,用瀏覽器打開 用瀏覽器打開 http://localhost:4000/sitemap.xml 發現site已經生效
七牛 免費體驗用戶每個月1G流量