win10+hexo+github搭建個人博客
win10+hexo+github搭建個人博客
參考以下步驟安裝
1、搭建環境準備(包括node.js和git環境,gitHub賬戶的配置)
2、安裝 配置Hexo,配置將Hexo與github page結合起來
3、怎樣發布文章 主題 推薦 主題
4、Net的簡單配置 添加sitemap和feed插件
5、添加404 公益頁麵
安裝並配置環境
win10+Node.js+git+github
- Node.js下載地址:https://nodejs.org/en/download/
- Git下載地址:https://git-scm.com/
- Github 地址:https://github.com
安裝node.js 和 git 步驟省略,按默認傻瓜式安裝即可
注冊github賬號並創建一個以 github昵稱.github.io 命名的倉庫
根據圖中,注冊一個github賬號,昵稱自定義,然後創建一個新項目,名字為:github昵稱.github.io
- 項目創建完成之後,本地生成ssh 私鑰和公鑰,用於連接github認證,使用上麵下載的git,打開git bash
ssh-keygen -t rsa -C "github注冊郵箱(自定義)" -f .ssh/shaonbean
# -f 輸出以昵稱命名的公鑰和私鑰,方便記憶
- 公鑰生成之後加到github上,方便後麵的使用,用戶本地和github進行ssh通信
到這裏github設置告一段落
安裝配置hexo
注:hexo安裝前提需安裝node.js 和git
- hexo官網:https://hexo.io/
- hexo官方文檔:https://hexo.io/docs/
文中以J盤為例,創建目錄github並創建字目錄(用於存放項目)
vdevops@shaon MINGW64 /j/github/shaonbean
# 注: 如果是linux環境下搭建的hexo博客,不建議使用root權限
- 下載安裝hexo
npm install -g hexo-cli
# 等待片刻,執行hexo如下圖表示安裝成功
hexo
- 初始化博客
這裏以shaonbean為博客目錄,執行下麵命令
hexo init shaonbean # 創始化項目
cd shaonbean
npm install
- 測試本地建站是否成功,輸入:
hexo s
INFO Start processing
INFO Hexo is running at https://localhost:4000/. Press Ctrl+C to stop.
# 出現上麵兩行,即表示本地建站成功
- 初始化博客以後,能看到下圖:
- 配置博客
博客根目錄初始化完成之後進項自定義配置,這裏用到_config.yml
自定義博客的相關信息
編輯_config.yml配置文件,進行修改,參考下麵配置:
title: itdevops
subtitle: DevOps is everything
description: From Zero to the DevOps
author: shaonbean
language: zh-CN
timezone: Asia/Shanghai
# language和timezone 有規範,注意格式
配置個人域名
url: https://vdevops.com
配置部署
deploy:
type: git
repo: https://github.com/shaonbean/shaonbean.github.io.git
branch: master
repo項是之前Github上創建好的倉庫的地址
exec ssh-agent bash
ssh-add MYKEY
# 這裏是針對本地設置多個github賬號進行操作
- 本地生成兩對密鑰對,然後在~/.ssh/目錄下新建config文件,參考下麵填入:
#————GitHub—————
Host github
HostName github.com
User git
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
# github.io
Host github.io
HostName github.com
User git
PreferredAuthentications publickey
IdentityFile ~/.ssh/itdevops
- 測試本地ssh連接github是否正常
ssh -T git@github
ssh -T git@github.io
# 筆者這裏第二個賬號沒設置成功,臨時使用的https方式進行的通信
- 使用https,github賬號加密碼的方式來進行hexo的部署。配置如下:
deploy:
type: git
#repo: git@github.io:shaonbean/shaonbean.github.io.git
repo: https://shaonbean:shaonbeanpassword@github.com/shaonbean/shaonbean.github.io.git
branch: master
message: devops
配置完成之後,現在可以進到設置的項目目錄裏麵通過hexo部署到github
進到你的項目目錄。命令行執行下麵命令:
hexo g # 本地生成數據庫文件,目錄等
hexo d # 部署到遠程
- 新建一篇博客
hexo new post "devops"
然後通過電腦編輯器(atom)對文章進行編輯,編輯完成之後,再次運行上麵的生成,部署命令
hexo g # 本地生成博客
hexo d # 發布到遠程
hexo d -g #在部署前先生成
注: 安裝git擴展
npm install hexo-deployer-git --save
# 沒安裝插件可能報錯:deloyer not found:git
- ssh key報錯
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
後麵筆者會專門寫一篇添加ssh 密鑰的文章
- 部署完成可以看到github上麵shaonbean.github.io,已經存在文件,通過瀏覽器訪問如下:
從上麵可以看出我們已經成功部署到遠程,並能夠正常訪問。
配置博客主題
選擇NexT,star最多,原因不多說
知乎主題推薦:https://www.zhihu.com/question/24422335
cd /j/github/shaonbean.github.io # 這裏項目名可以自定義
git clone https://github.com/iissnan/hexo-theme-next themes/next
- 更換主題完成後,訪問:
參考鏈接
- https://blog.csdn.net/gdutxiaoxu/article/details/53576018
- https://www.jeyzhang.com/hexo-github-blog-building.html
- https://www.zrj96.com/post-471.html
最後更新:2017-07-12 10:02:43