github pages + hexo 構建自己的網站
一、前期準備
git
git安裝地址
nodejs
nodejs安裝地址
hexo 使用npm安裝
安裝好nodejs以後,進入nodejs安裝目錄
二、Hexo
hexo是一款基於Node.js的靜態博客框架。
在nodejs安裝目錄下執行命令
$npm install hexo -g
- 1
僅需一步就把 Hexo 本體和所有相依套件安裝完畢。
更新hexo到最新版
$npm update hexo -g
- 1
查看版本
node -v
- 1
v0.12.7
初始化
創建hexo目錄,比如E:hexo ,進入E:hexo 目錄,執行命令
$hexo init
安裝依賴包
$npm install
- 1
啟動服務
$hexo server
- 1
新開啟一個gitbash
$ hexo new "My New Post"
- 1
刷新http://localhost:4000/。
可以發現已生成了一篇新文章 「My New Post」。
執行下面的命令,將markdown文件生成靜態網頁。
$ hexo generate
- 1
該命令執行完後,會在 E:hexopublic 目錄下生成一系列html,css等文件。
編輯需要使用markdown語法
hexo常用命令:http://segmentfault.com/a/1190000002632530
常用命令:
hexo new "postName" #新建文章
hexo new page "pageName" #新建頁面
hexo generate #生成靜態頁面至public目錄
hexo server #開啟預覽訪問埠(默認埠4000,"ctrl + c"關閉server)
hexo deploy #將.deploy目錄部署到GitHub
簡寫:
hexo n == hexo newhexo g == hexo generate
hexo s == hexo server
hexo d == hexo deploy
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
三、GitHub
註冊Github 賬號
創建一個新的repository
chenlly99.github.io //注意,名稱必須是xxx.github.io 格式,並且xxx必須是GitHub的用戶名
編輯_config.yml 在E:hexo 目錄下
deploy:
type: git
repository: git@github.com:chenlly99/chenlly.github.io.git
branch: master
$hexo deploy 如果最後顯示
[info] Deploy done: github
說明發布成功
問題1:hexo deploy 命令行沒有任何輸出,也沒有錯誤。
deploy:標籤,在每個冒號後面必須要空格
問題2:
hexo deploy命令顯示ERROR Deployer not found : github
解決:
deploy的type改成git,然後運行下npm install hexo-deployer-git –save
再hexo g
hexo d
問題3:
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
FATAL Something』s wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html
Error: Host key verification failed.
fatal: Could not read from remote repository.
解決:
先生成key:
登錄git bash
$ ssh-keygen -t rsa -C 「chenliling99@126.com」
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa):
/c/Users/Administrator/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/Administrator/.ssh/id_rsa.
Your public key has been saved in /c/Users/Administrator/.ssh/id_rsa.pub.
The key fingerprint is:
02:80:dc:c0:02:25:9b:73:0e:3f:59:fa:ea:d6:35:29 chenliling99@126.com
The key』s randomart image is:
+–[ RSA 2048]—-+
|*+= |
|o* o |
|* . o |
| * + . |
| * ..S |
| oE +. |
| ..o . |
| … |
| oo |
+—————–+
之後會要求確認路徑和輸入密碼,我們這使用默認的一路回車就行。成功的話會在~/下生成.ssh文件夾,進去,打開id_rsa.pub,複製裡面的key。
回到github,進入Account Settings,左邊選擇SSH Keys,Add SSH Key,title隨便填,粘貼key。為了驗證是否成功,
$ ssh -T git@github.com
Enter passphrase for key 『/c/Users/Administrator/.ssh/id_rsa』:
Hi chenlly99! You』ve successfully authenticated, but GitHub does not provide shell access.
問題4:執行命令hexo deploy 報如下錯誤
Error: spawn git ENOENT at exports._errnoException (util.js:746:11) at Process.ChildProcess._handle.onexit (child_process.js:1053:32) at child_process.js:1144:20 at process._tickCallback (node.js:355:11)
添加環境變數:C:Program Files (x86)Gitin;C:Program Files (x86)Gitlibexecgit-core,這樣就解決了問題了。
點擊 Github 上項目的 Settings,GitHub Pages,提示Your site is published at http://chenlly99.github.io/
第一次上傳網站的話需要等十分鐘左右,以後每次更新都能馬上打開
四、主題
參考:https://github.com/zippera/lightum
複製主題:
$ git clone https://github.com/zippera/lightum.git themes/lightum
- 1
更新主題:
cd themes/lightum
git pull
複製下來以後,修改配置文件
修改Hexo目錄下的config.yml配置文件中的theme屬性,將其設置為
theme: lightum
五、布局
站點配置用到兩個文件,一個是對整站的配置H:hexo_config.yml,另一個是對主題的配置H:hexo hemeslight_config.yml,
添加分類、標籤雲、友情鏈接widget
修改themeslight_config.yml 增加widgets
widgets:
- search
- category
- tagcloud
- blogroll
在D:hexo hemeslightumlayout_widget 分別增加
search.ejs
category.ejs
tagcloud.ejs
blogroll.ejs
參考:http://www.ituring.com.cn/article/23
1、字體
*這些文字顯示為斜體*
**這些文字顯示為粗體**
- 1
- 2
2、代碼:
$ hexo deploy
- 1
3、標題
#表示這是一級標題
##表示這是二級標題
###表示這是三級標題
- 1
- 2
- 3
4、無序列表
- 列表項目
- 列表項目
- 列表項目
- 1
- 2
- 3
5、嵌套列表
- 列表項目
+ 列表項目
+ 列表項目
+ 列表項目
- 列表項目
- 1
- 2
- 3
- 4
- 5
6、有序列表
數字接著一個英文句點
1. Bird
2. McHale
3. Parish
- 1
- 2
- 3
7、連接
URL格式:[圖靈社區](http://www.ituring.com.cn)
圖片連接
開頭加一個驚嘆號

圖片可以是網路圖片也可以是本地圖片
本地圖片建議放在sourceimg 目錄下。
eg:

或者直接用img標籤,同時指定圖片大小
<img src="/img/forkme_left_green_007200.png" alt="圖靈社區" width="200px" />
- 1
8、表格
http://www.jianshu.com/p/q81RER
七、寫文章
hexo new [layout] 「postName」 #新建文章
其中layout是可選參數,默認值為post。有哪些layout呢,請到 scaffolds 目錄下查看post的layout默認是hexoscaffoldspost.md
修改scaffoldspost.md的模板樣式
title: {{ title }}
date: {{ date }}
tags:
categories:
正文支持markdown格式,建議你先學習一下它的語法。markdown不像html似的一大堆標籤,很簡單,只有幾個符號。
新建、刪除或修改文章
文章可以擁有如下屬性:
Setting Description Default
layout Layout post或page
title 文章的標題
date 創建日期 文件的創建日期
updated 修改日期 文件的修改日期
comments 是否開啟評論 true
tags 標籤
categories 分類
八、自定義頁面
執行new page命令
$hexo new page "about"
- 1
在 hexosource 下會生成 about 目錄,裡面有個index.md,直接編輯就可以了
然後在themeslight_config.yml 配置
menu:
首頁: /
歸檔: /archives
關於: /about
九、評論框
註冊多說地址:
在多說進行註冊,獲得通用代碼。
將通用代碼粘貼到themeslightlayout_partialcomment.ejs裡面,如下:
<% if ( page.comments){ %>
<section id="comment">
通用代碼
</section>
<% } %>
- 1
- 2
- 3
- 4
- 5
十、RSS 閱讀
安裝插件
$npm install hexo-generator-feed
- 1
全局配置文件開啟插件
plugins:
- hexo-generator-feed
主題配置文件添加入口
rss: /atom.xml
添加到首頁
在themes/light/layout/_partial/header.ejs中,
<li> <a href="/atom.xml">RSS</a> </li>
- 1
十一、網站地圖
網站地圖,又稱站點地圖,它就是一個頁面,上面放置了網站上需要搜索引擎抓取的所有頁面的鏈接
安裝插件
$npm install hexo-generator-sitemap
- 1
開啟插件
plugins:
- hexo-generator-sitemap
瀏覽http://localhost:4000/sitemap.xml查看是否生效
十二、統計:
因Google Analytics偶爾被牆,故用百度統計,以 modernist 主題為例,介紹如何添加。
編輯文件 hexo hemesmodernist_config.yml ,增加配置選項:
baidu_tongji: true
新建文件 hexo hemesmodernistlayout_partialaidu_tongji.ejs ,內容如下:
<% if (theme.baidu_tongji){ %><% } %>
註冊並登錄百度統計獲取你的統計代碼。
編輯文件 hexo hemesmodernistlayout_partialhead.ejs ,在 [/head] 之前增加:
<%- partial(『baidu_tongji』) %>
重新生成並部署你的站點。
不出意外的話,在你的站點的每個頁面的左上角都會看到一個噁心的百度LOGO。你只能在『百度統計首頁->網站列表->獲取代碼->系統管理設置->統計圖標設置->顯示圖標』,把那個勾去掉。
十三、域名
(1)、進入source文件夾,創建名為CNAME的文件,編輯:
chenlly.com
(2)、設置DNS解析
本人首先在阿里雲上購買了一個域名,
登錄域名控制台,添加域名解析,github.com兩個ip地址分別是192.30.252.154,192.30.252.153
打開瀏覽器輸入
chenlly.com
OK


※淺談WKWebView使用、JS的交互
※Hive常見問題及處理方法
TAG:程序員小新人學習 |