Github+Hexo 博客搭建教程

環境配置

  1. Windows32/64
  2. Node.js | 32位 | 64位
  3. Git | 32位 | 64位
  4. Sublime Text | 32位 | 64位 (下述文件均用這個軟件打開)
  5. 配置環境變量 教程
  6. 完成檢查: 若是與下述相同就OK了
//Windows+R cmd
C:\Users\student>node -v
v9.9.0

C:\Users\student>npm -v
5.6.0

C:\Users\student>git --version
git version 2.16.2.windows.1

帳號準備

  1. Github帳號,下述帳號名稱之爲NAME,郵箱名稱之爲EMAI.
  2. 新建項目(Github首頁->Start a project)
    html

    初始化

根目錄建立

在一個合適的位置建立一個文件夾(別稱:根目錄),下文中由E:\Blog來演示.node

C:\Users\student>E:
E:\>cd Blog
E:\Blog>

安裝hexo.

E:\Blog>npm install hexo -g --save
//WARN*3

檢查:git

E:\Blog>hexo -v
hexo: 3.6.0
hexo-cli: 1.1.0
os: Windows_NT 6.1.7601 win32 ia32
http_parser: 2.7.0
node: 9.9.0
v8: 6.2.414.46-node.22
uv: 1.19.2
zlib: 1.2.11
ares: 1.13.0
modules: 59
nghttp2: 1.29.0
napi: 2
openssl: 1.0.2n
icu: 60.2
unicode: 10.0
cldr: 32.0.1
tz: 2017c

初始化hexo.

E:\Blog>hexo init
//WARN*2

檢查: 最後會顯示 INFO Start blogging with Hexo!github

E:\Blog>hexo install
//WARN*2
E:\Blog>hexo g
E:\Blog>npm install hexo-deployer-git --save
//WARN*2

鏈接Hexo—Github_page.

在根目錄下右鍵,選擇Git Bash Here.
若是第一次使用,輸入shell

student@XJ507011 MINGW32 /e/Blog
$ git config --global user.name "NAME"

student@XJ507011 MINGW32 /e/Blog
$ git config --global user.email "EMAIL"

不然什麼都不幹.
接下來輸入:npm

$ ssh-keygen -t rsa -C "EMAIL"
//連續三個回車
$ eval "$(ssh-agent -s)"
$ ssh-add ~/.ssh/id_rsa

進入Github,點擊頭像下的Settings,選擇SSH and GPS keys,點擊New SSH key.
Title:任意, Key:.ssh\id-rsa.pub的內容.(默認路徑爲: C:\Users\Administrator.ssh)
檢查:windows

student@XJ507011 MINGW32 ~
$ ssh -T git@github.com
//若是還有要輸入的,回答yes.
Hi oierlin! You've successfully authenticated, but GitHub does not provide shell access.
//只要'Hi'後面是你的NAME,有warning也不要緊.

找到根目錄下的_config.yml文件,在文本末尾你會找到deploy:,
將其修改爲:api

deploy:
  type: git
  repository: git@github.com:NAME/NAME.github.io.git
  #or repository: https://github.com/NAME/NAME.github.io.git
  branch: master

repository最好用前者,不然在hexo d -g時有概率出現bash: /dev/tty: No such device or address錯誤bash

最後

E:\Blog>hexo d -g

將本地文件上傳到Github上.hexo

Hexo 指令淺談

簡寫對照

n--new
p--publish
g--generate
s--server
d--deploy

安裝

npm install hexo -g

更新

npm update hexo -g

初始化

hexo init

部署

hexo d -g//上傳

本地編輯

hexo s
http://localhost:4000/查看

插入

hexo n post "TITLE": 添加博客.
hexo n page "TITLE": 添加分欄.

相關文章
相關標籤/搜索