閱讀421 返回首頁    go 阿裏雲 go 技術社區[雲棲]


win10+hexo+github搭建個人博客

win10+hexo+github搭建個人博客

參考:https://hexo.io/,博客用於記錄自己的學習工作曆程

參考以下步驟安裝

1、搭建環境準備(包括node.js和git環境,gitHub賬戶的配置)
2、安裝 配置Hexo,配置將Hexo與github page結合起來
3、怎樣發布文章 主題 推薦 主題
4、Net的簡單配置 添加sitemap和feed插件
5、添加404 公益頁麵

安裝並配置環境

win10+Node.js+git+github

安裝node.js 和 git 步驟省略,按默認傻瓜式安裝即可

注冊github賬號並創建一個以 github昵稱.github.io 命名的倉庫

reg-github

根據圖中,注冊一個github賬號,昵稱自定義,然後創建一個新項目,名字為:github昵稱.github.io

  • 項目創建完成之後,本地生成ssh 私鑰和公鑰,用於連接github認證,使用上麵下載的git,打開git bash

ssh-shaonbean

ssh-keygen -t rsa -C "github注冊郵箱(自定義)" -f .ssh/shaonbean
# -f 輸出以昵稱命名的公鑰和私鑰,方便記憶
  • 公鑰生成之後加到github上,方便後麵的使用,用戶本地和github進行ssh通信

ssh-add-github

到這裏github設置告一段落

安裝配置hexo

注:hexo安裝前提需安裝node.js 和git

文中以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.
# 出現上麵兩行,即表示本地建站成功
  • 初始化博客以後,能看到下圖:

hexo

  • 配置博客

博客根目錄初始化完成之後進項自定義配置,這裏用到_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,已經存在文件,通過瀏覽器訪問如下:

github

itdevops

從上麵可以看出我們已經成功部署到遠程,並能夠正常訪問。

配置博客主題

選擇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
  • 更換主題完成後,訪問:

next

參考鏈接

最後更新:2017-07-12 10:02:43

  上一篇:go  H5響應式雲建站係統的優勢
  下一篇:go  馬雲給嶽雲鵬的網店支招……透露小目標,要做“五個全球”