hexo+github搭建個人博客

首先需要安裝git和node.js

Mac下安裝git和node.js

首先在終端查看是否安裝了git,如果出現以下信息說明安裝了git,請跳過這一步

$ git
usage: git [--version] [--help] [-C <path>] [-c name=value]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p | --paginate | --no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           <command> [<args>]

These are common Git commands used in various situations:

start a working area (see also: git help tutorial)
   clone      Clone a repository into a new directory
   init       Create an empty Git repository or reinitialize an existing one

work on the current change (see also: git help everyday)
   add        Add file contents to the index
   mv         Move or rename a file, a directory, or a symlink
   reset      Reset current HEAD to the specified state
   rm         Remove files from the working tree and from the index

examine the history and state (see also: git help revisions)
   bisect     Use binary search to find the commit that introduced a bug
   grep       Print lines matching a pattern
   log        Show commit logs
   show       Show various types of objects
   status     Show the working tree status

grow, mark and tweak your common history
   branch     List, create, or delete branches
   checkout   Switch branches or restore working tree files
   commit     Record changes to the repository
   diff       Show changes between commits, commit and working tree, etc
   merge      Join two or more development histories together
   rebase     Reapply commits on top of another base tip
   tag        Create, list, delete or verify a tag object signed with GPG

collaborate (see also: git help workflows)
   fetch      Download objects and refs from another repository
   pull       Fetch from and integrate with another repository or a local branch
   push       Update remote refs along with associated objects

'git help -a' and 'git help -g' list available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.

如果沒有安裝,則通過homebrew安裝

$ brew install git

如果沒有安裝homebrew,請先安裝homebrew

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

安裝node.js

$ brew install node

Windows下安裝git和node.js

git官網下載然後按提示安裝即可

node.js官網下載然後根據提示安裝即可

安裝hexo

在git和node.js都安裝成功後就可以開始安裝hexo了

安裝hexo

$ npm install -g hexo

初始化hexo,建一個你自己博客的文件夾,例如MyBloc,然後進入文件夾,執行

hexo init

生成靜態文件

$ hexo generate

啓動服務器

$ hexo server

默認情況下,訪問網址爲: http://localhost:4000/ 然後你在瀏覽器打開後就可以看到本地博客了

image.png

然後你可以去官方文檔去查看更多的指令

創建GitHub博客倉庫

首先新建一個倉庫

image.png

注意倉庫的名字必須是username.github.io,username替換爲你自己賬號的名字

image.png

添加ssh key到GitHub

首先查看是不是已經有了ssh祕鑰,如果能看到這三個文件說明已經有了,跳過生成祕鑰的過程

$ cd ~/.ssh
$ ls
id_rsa      id_rsa.pub  known_hosts

如果沒有祕鑰,那麼首先來生成祕鑰,換成你自己的郵箱地址

ssh-keygen -t rsa -C "your email"

然後會在~/.ssh下生成id_rsa和id_rsa.pub文件

然後拷貝id_rsa.pub文件裏的內容,添加到你的GitHub上

image.png

image.png

把hexo博客和GitHub倉庫相關聯,並部署

打開你博客文件夾根目錄下的_config.yml文件,然後添加入下內容,將username改爲你自己的賬號名

deploy:
   type: git
   repo: [email protected]:username/username.github.io
   branch: master

安裝自動發佈工具

$ npm install hexo-deployer-git  --save

然後部署到GitHub

$ hexo clean //清理
$ hexo generate  //生成靜態文件
$ hexo deploy  //部署網站

然後你打開 https://username.github.io就可以看到你自己的博客了
新建博客

$ hexo new "文章標題"

然後就會在博客根目錄的source/_posts/下看到"文章標題.md",你就可以開始編輯你的文章了。

後續會出給你的博客更換主題、添加評論等,敬請期待!


歡迎關注公衆號

掃碼.png

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