這里首先提供三個鏈接地址,當你創(chuàng)建完成博客后,對一個很low的界面會抱怨的,作為一個視覺黨,這簡直是不能忍受的,所以這里推薦一個有著超級詳細的教程的主題,里面有詳細的設置。后面的設置都是和主題有關(guān)的,小編在這里只是寫出來怎么搭建博客,和怎么上傳到github上。
hexo的官方地址: https://hexo.io/
github的官方地址:https://github.com/
github-theme-next主題界面https://github.com/iissnan/hexo-theme-next
mkdir /app/blog
# 創(chuàng)建一個單獨屬于blog的文件夾,名字自己隨便
cd /app/blog
wget https://nodejs.org/dist/v6.11.1/node-v6.11.1-linux-x64.tar.xz
# 從網(wǎng)上下載最新班的node.js軟件,這個是必須的環(huán)境
tar Jxvf node-v6.11.1-linux-x64.tar.xz
# 解壓`node-v6.11.1-linux-x64.tar.xz`文件
mv node-v6.11.1-linux-x64 node
# 修改一下名字名字太長寫的麻煩
修改全局變量,加入全局變量文件中
vim /etc/profile
export PATH=$PATH:/app/blog/node/bin
# 這個隨便添加到哪里都行,一般我都加到最后
source /etc/profile
# 重新加載環(huán)境配置文件
# 創(chuàng)建目錄
mkdir hexo
# 切換目錄
cd hexo
安裝Git(已安裝可跳過)
yum install git-core
安裝 Hexo
npm install -g hexo-cli
初始化 Hexo
hexo init 初始化安裝
假如錯誤的話,這里提供解決方案
npm install
hexo init(不過這里會提示你文件夾不是空的,所以你需要把原來的文件夾刪除,重新創(chuàng)建)
啟動hexo
[root@VinnyWang testgithub.io]# hexo server
INFO Start processing
INFO Hexo is running at http://localhost:4000/. Press Ctrl+C to stop.
這里我們不關(guān)閉終端,我們直接點擊打開鏈接,一個你將來的博客界面就會出現(xiàn)了,假如失敗的話,重頭來,最簡單的辦法,要不然就排錯,錯誤很多,這里就不一一寫出來了。
到了這里,我們就是把環(huán)境搭建成功了,到時候吧本地的升值同步到github上就好了。但是這里我們先不需要著急,我們剛才生成的只不過是hexo為我們提供的模板網(wǎng)頁,里邊還是會有很多信息需要修改的,下面我們進入配置文件進行修改,最主要我們修改的地方有兩個地方,一個是開頭一個是結(jié)尾。
# Hexo Configuration
## Docs: https://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/
# Site # 站點信息
title: Hexo # 標題
subtitle: # 副標題
description: # 站點描述,這個地方會被搜索引擎收錄
author: John Doe # 作者,可以把John Doe改成自己
language: # 語言類型,看你選擇什么主題,里面會有設置的,一般情況下寫 zh-CN
timezone: # 時區(qū) 有的主題文件會有需要的
# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: http://yoursite.com # 網(wǎng)址
root: / # 根目錄,這個地方在你準備同步到網(wǎng)上時候,修改成你的庫名字,比如我的是vinnywang.github.io就寫這個名字
permalink: :year/:month/:day/:title/ # 文章的鏈接格式
permalink_defaults: # 默認鏈接
# Directory
source_dir: source # 源文件生成目錄
public_dir: public # 生成網(wǎng)頁文件目錄
tag_dir: tags # 標簽目錄
archive_dir: archives # 存檔目錄
category_dir: categories # 分類目錄
code_dir: downloads/code
i18n_dir: :lang
skip_render:
# Writing
new_post_name: :title.md # File name of new posts # 新標題
default_layout: post # 默認的模板post、page、photo、draft(文章、頁面、照片、草稿)
titlecase: false # Transform title into titlecase # 標題是否轉(zhuǎn)換為大寫
external_link: true # Open external links in new tab # 新的tab打開頁面
filename_case: 0
render_drafts: false
post_asset_folder: false
relative_link: false
future: true
highlight: # 語法高亮
enable: true # 是否啟用
line_number: true # 顯示行號
auto_detect: false
tab_replace:
# Home page setting
# path: Root path for your blogs index page. (default = '')
# per_page: Posts displayed per page. (0 = disable pagination)
# order_by: Posts order. (Order by date descending by default)
index_generator:
path: ''
per_page: 10
order_by: -date
# Category & Tag # 分類標簽
default_category: uncategorized # 默認
category_map:
tag_map:
# Archives
2: 開啟分頁
1: 禁用分頁
0: 全部禁用
archive: 2
category: 2
tag: 2
# Date / Time format # 日期時間格式
## Hexo uses Moment.js to parse and display date
## You can customize the date format as defined in
## http://momentjs.com/docs/#/displaying/format/
date_format: YYYY-MM-DD # 默認設置的格式
time_format: HH:mm:ss
# Pagination # 分頁
## Set per_page to 0 to disable pagination
per_page: 10 # 每頁為10篇文章
pagination_dir: page
# Extensions # 擴展插件
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: landscape # 主題 裝機完成之后,默認為landscape
# Deployment # 開發(fā)后面部署到github上時會使用到,不要填錯了
## Docs: https://hexo.io/docs/deployment.html
deploy:
type: git
repo:git@github.com:mocorochio/micorochio.github.io.git # 這個是填你自己生成的庫的鏈接地址
branch: master
message: '站點更新:{{now("YYYY-MM-DD HH/mm/ss")}
上面的repo可能會有很多人不知道怎么填寫,這里給個地址,是紅色箭頭所指的網(wǎng)址。
[圖片上傳失敗...(image-4710f7-1531461088386)]
[root@VinnyWang testgithub.io]# git config --global user.email "20843205@qq.com"
輸入你的email賬號,和你注冊時候的email相同,不要填錯了
[root@VinnyWang testgithub.io]# git config --global user.name "vinnywan"
這里填上你的用戶名,和你注冊時候的一樣哦
[root@VinnyWang testgithub.io]# less ~/.ssh/id_rsa.pub
/root/.ssh/id_rsa.pub: No such file or directory
這個地方是檢查你有沒有key文件,有的話略過下邊的操作。
[root@VinnyWang testgithub.io]# ssh-keygen -t rsa -C 20843205@qq.com
這個操作是生成key文件,假如你們有的話,需要生成,一路回車就好了。
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
64:a7:2d:64:97:a9:27:51:9d:22:c1:07:a8:74:8d:ac 20843205@qq.com
The key's randomart image is:
+--[ RSA 2048]----+
| . =oo.. . |
| . = +.ooo |
| . + *o=. |
| E = B |
| S o |
| + |
| |
| |
| |
+-----------------+
vim /root/.ssh/id_rsa.pub
然后把這個文件上的全部復制出來,等下有用。
現(xiàn)在我們本地的環(huán)境已經(jīng)搭建完成了,但是我們還沒有同步到網(wǎng)上,所以這個地方我們需要創(chuàng)建一個github賬號,最上面提供的有g(shù)ithub的官方網(wǎng)址,點擊進去就好了。
創(chuàng)建用戶賬戶就不用我教了吧,按照提示一步一步做下去就好了。但是這里先提前說下,不要亂填,用戶名不要起的太奇葩,后面還要用到。這里只是給提供一些創(chuàng)建賬號之后的步驟。但你登錄github賬號之后是這個樣子的。
[圖片上傳失敗...(image-82214b-1531461088386)]
我們點擊 start a project之后會彈出這個界面
[圖片上傳失敗...(image-dc3286-1531461088386)]
這個上面我用紅色箭頭指出來的千萬不要亂寫,格式是:用戶名.github.io寫完之后,直接點擊最下面的 create repository
創(chuàng)建完成庫了,我們需要吧本地的文件同步到github上,但是同步的話,怎么認證呢?這個時候就需要用到,我們之前生成的key文件了。
[圖片上傳失敗...(image-cdb135-1531461088386)]
按照順序點擊,反正也點不錯。之后還有一個界面。
[圖片上傳失敗...(image-e11e39-1531461088386)]
按照順序填寫,記得一定要選擇sshkey不要用另外一個。把我們上面生成的key里面的內(nèi)容復制到中間的空白處,隨便給個名字就好了。
好了上面的我們做完了,現(xiàn)在就需要將本地和網(wǎng)絡上同步起來
git init
git add . # 將本地文件添加到緩沖區(qū)中
git commit -m "提交文件" # 給想要提交的動作一個名字 引號內(nèi)部內(nèi)容隨便
git remote add origin https://github.com/vinnywan.github.io
指明你遠程的庫是什么
git push -u origin master
將緩沖區(qū)添加的文件同步到庫中,速度看網(wǎng)速了。
這個時候可能會出現(xiàn)一些問題,所以這里提供了兩個解決的辦法
1.使用強制push的方法:
git push -u origin master -f
這樣會使遠程修改丟失,一般是不可取的,尤其是多人協(xié)作開發(fā)的時候。
2.push前先將遠程repository修改pull下來
git pull origin master
git push -u origin maste
這里給些常用的命令:
git add *#跟蹤新文件
git rm -f * #強制刪除所有文件
git commit#提交更新
git commit -m "注釋文本" #添加注釋
git commit -a #跳過使用暫存區(qū)域,把所有已經(jīng)跟蹤過的文件暫存起來一并提交
git commit --amend #修改最后一次提交
git push origin "resposbilty"
hexo g # 部署
hexo d # 提交