github+Hexo搭建自己的博客(Mac OS 10.12.5)

聽說hexo用起來比較方便,今天花了點時間,試用了一下,果然還不錯,下面分享下我的使用過程。
1.OS : Mac OS 10.12.5
2.git : git version 2.11.0 (Apple Git-81)
3.node: v6.11.1
4.hexo: 3.3.8

第一步:
安裝git,進入以下地址,直接下載安裝即可。
https://git-scm.com/downloads

第二步:
安裝node,可參考我的文章:
mac os 10.12.5安裝node.js

第三步:
安裝hexo(如果按照我的步驟有問題,建議直接去官網看最新版本的介紹)
hexo官網

1.npm install hexo-cli -g
2.hexo init myblog (myblog是你自己指定的目錄)
3.cd myblog
4.npm install
5.hexo server

可看到命令行出現以下信息:
INFO Start processing
INFO Hexo is running at http://localhost:4000/. Press Ctrl+C to stop.

http://localhost:4000/ 就是你本地博客的首頁地址
至此,安裝完成。

第四步,與github關聯上,後續可通過hexo deploy(hexo d)命令來部署博客到github.
1.註冊github賬號(此處省略說明)
2.登錄github賬號
3.New repository,輸入倉庫名稱,我的是mingleizhen.github.io
4.創建成功之後,本地生成祕鑰
ssh-keygen -t rsa -b 4096 -C “githhub的註冊郵箱”

cd ~/.ssh/
在此目錄下,打開剛纔生成的.pub文件,複製內容
進入以下頁面
https://github.com/settings/keys
New SSH key
Title隨便寫,key粘貼進去即可。

第五步:
發佈博客到github
1.cd ~/myblog
2.npm install hexo-deployer-git –save
3.cd ~/myblog/source/_posts/
4.ls -al 可看到有一個.md文件,複製一份,然後修改裏面內容
例如:

 ---
title: First Time Publication
date: 2017-08-03 11:50
tags:
---

Welcome to my git pages!

5.hexo clean
6.hexo g
7.hexo s
訪問本地 http://localhost:4000/
可看到剛纔編輯的文件,已經發布爲一篇博客在本地了。
ctrl + c停掉本地服務
8.vim ~/myblog/_config.yml修改配置文件(注意yml文件的格式,冒號和內容之間有一個空格)

title: xxx's blog
subtitle: share my documents
description: 01010101
author: xxxxxxxx
language: zh-CN
timezone: Asia/Shanghai

#此處,我的url就寫的github的地址,也可以自己買域名
url: https://mingleizhen.github.io/

deploy:
  type: git
  repo: 倉庫地址(剛纔新建的倉庫)
  branch: master
  message: change theme to Ada

9.hexo d發佈到GitHub
10.可以訪問自己的github首頁了,我的是 https://mingleizhen.github.io/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章