1、hexo+github搭建我的博客的過程記錄

前提:html

1.新建一個github倉庫node

2.安裝配置Node.jsgit

3.安裝配置Gitgithub

前提

步驟1.新建一個github倉庫

  1. 打開github網站,(註冊)登陸帳號,新建一個倉庫;

注:==倉庫名稱要求,yourname.github.io;==shell

​ 勾選Initialize this repository with a README;npm

  1. 新建完成後打開倉庫,點擊右側settings按鈕,開啓下面的GitHub Pages;
  2. Source保存爲master branch,上面的連接是以後博客訪問的連接

步驟2.安裝Node.js

  1. 打開Node.js官網下載對應操做系統版本及位數的node.jsbash

  2. 安裝完成後可經過如下命令驗證是否已配置成功(默認安裝已自動配置環境變量)hexo

    node -v
    npm -v

步驟3.安裝git

  1. 打開Git官網下載對應操做系統版本及位數的gitssh

  2. 安裝完成後可經過一下命令驗證是否配置成功(默認安裝已自動配置環境變量,即選擇use Git from the Windows Command Prompt)網站

    git --version
  3. 配置git

    1. 鼠標右鍵打開git bash here(如下命令都是在git bash下執行)

    2. 設置git的user name和email(第一次使用)

      git config --global user.name "yourname"
      git config --global user.email "youremail"
    3. 配置ssh

      #生成密鑰,默認存儲路徑:C:\User\Administrator\.ssh
      ssh-keygen -t rsa -C"youremail"
      #添加密鑰到ssh-agent
      eval "$(ssh-agent -s)"
      #添加生成的SSH key到ssh-agent
      ssh -add ~/.ssh/id_rsa
    4. 在github上添加ssh key.

      #步驟1
      登陸github,點擊頭像下的settings
      #步驟2
      打開左側的SSH and GPG keys
      #步驟3
      點擊右側的new SSH key
      #步驟4
      Title 自定義
      Key輸入剛纔生成的C:\User\Administrator\.ssh路徑下的id_rsa.pub
    5. 驗證ssh是否添加成功

      ssh -T git@github.com
    6. ssh-key配置失敗解決方法

      首先,清除全部的key-pair
      ssh-add -D
      rm -r ~/.ssh
      刪除你在github中的public-key
      
      從新生成ssh密鑰對
      ssh-keygen -t rsa -C "xxx@xxx.com"
      
      接下來正常操做
      在github上添加公鑰public-key:
      一、首先在你的終端運行 xclip -sel c ~/.ssh/id_rsa.pub將公鑰內容複製到剪切板
      二、在github上添加公鑰時,直接複製便可
      三、保存

小試牛刀

hexo+github設置

安裝Hexo

  1. 找到一個合適的位置建立一個新的文件夾,必須是空的。實例文件夾:D:\Blog

  2. 打開cmd,進入新建的文件

    d:
    cd Blog
  3. 安裝hexo

    npm install hexo -g
  4. 驗證是否安裝成功

    hexo -v

配置Hexo

  1. 初始化Blog文件夾

    hexo init
  2. 安裝必要的組件

    npm install
  3. 生成目錄結構

    hexo g
    #或
    hexo generate
  4. 開啓hexo服務,預覽界面

    hexo s
    #或
    hexo server
  5. 第一次訪問

    訪問:localhost:4000,可看到加載的頁面。

Hexo聯繫Github

打開hexo配置文件;D:\Blog\_config.yml

文件末尾處配置:

repository:打開github倉庫點擊Clone or download,複製裏面ssh對應的倉庫地址;

# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
  type: git
  repository: git@github.com:username/username.github.io.git
  branch: master
相關文章
相關標籤/搜索