搭建博客
- GitHub上新建一個空repo本缠,命名格式
github的用戶名.github.io
,此處用xxx.github.io
- 本地新建文件夾
xxx.github.io(隨意命名,不是必須跟github上新建的倉庫同名)
用于倉庫目錄 - 運行
echo "# lucy.github.io" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin git@github.com:xxx/xxx.github.io.git
git push -u origin master
- 安裝 Hexo
npm install -g hexo-cli
(我安裝的是hexo: 3.6.0) - 生成Hexo模板
hexo init myBlog
- cd myBlog
- 安裝npm
npm i
(npm i 是 npm install 的簡寫惶岭。我安裝的是npm 5.4.2) - 使用hexo命令創(chuàng)建文件
hexo new 第一篇博客
- 打開配置文件并編輯
open _config.yml
-
title
博客名 -
author
作者 - 最后一行的
type
改成type: git
- 最后一行后面新增一行
repo: git@github.com:xxx/xxx.github.io.git
- 安裝 git 部署插件
npm install hexo-deployer-git --save
- 部署
hexo deploy
- 在 GitHub Pages 中點擊鏈接就可以看到搭建好的博客
發(fā)布博客步驟如下:
hexo new 第二篇博客
- 復(fù)制顯示的路徑抬旺,使用
open 路徑
編輯博客 -
hexo generate
(wnkl.github.io/myBlog/source/_posts目錄下執(zhí)行) -
hexo deploy
(wnkl.github.io/myBlog/source/_posts目錄下執(zhí)行)
更換主題
- 主題合集
- 選擇一個主題并進入主題首頁
- 復(fù)制它的 SSH 地址或 HTTPS 地址,例如
git@github.com:hustcer/hexo-theme-air.git
cd themes
git clone git@github.com:hustcer/hexo-theme-air.git
cd ..
- 將 _config.yml 的第 75 行改為
theme: hexo-theme-air
hexo generate
hexo deploy
- 刷新博客可以看到新的外觀
將博客推送到GitHub上翼岁,以防本地丟失
xxx.github.io
上保存的只是博客,并沒有保存 生成博客的程序代碼司光,也就是說本地新建的文件夾xxx.github.io
中的代碼并未上傳到GitHub上琅坡,生成博客的程序代碼其實還是保存在本地。所以為了避免此文件夾被誤刪而導致博客無法找回残家,我們需要在GitHub上創(chuàng)建新的空倉庫 blog-generator
榆俺,用來保存xxx.github.io
中生成博客的程序代碼的代碼。
新建空倉庫 blog-generator
后可以看到
git remote add origin git@github.com:xxxblog-generator.git
git push -u origin master
因為之前 xxx.github.io
已經(jīng)用過了 origin
作為倉庫的名字,所以這里需要另外起一個倉庫名茴晋,如 mirror
陪捷,上面的代碼就變?yōu)椋?/p>
git remote add mirror git@github.com:xxxblog-generator.git
git push -u mirror master
cd
到目錄 xxx.github.io
下,執(zhí)行如下代碼:
git remote add mirror git@github.com:xxxblog-generator.git
git push -u mirror master
最后:
- 每次 hexo deploy 完之后诺擅,博客就會更新市袖;
- 在
xxx.github.io myBlog
文件夾中 add / commit /push 一下,將更改推送到遠程倉庫烁涌。這樣代碼就不會丟失苍碟。