溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

hexo+github搭建個(gè)人博客

發(fā)布時(shí)間:2020-07-28 18:53:34 來(lái)源:網(wǎng)絡(luò) 閱讀:216 作者:KeepInUp 欄目:開(kāi)發(fā)技術(shù)

首先需要安裝git和node.js

Mac下安裝git和node.js

首先在終端查看是否安裝了git,如果出現(xiàn)以下信息說(shuō)明安裝了git,請(qǐng)?zhí)^(guò)這一步

$ 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.

如果沒(méi)有安裝,則通過(guò)homebrew安裝

$ brew install git

如果沒(méi)有安裝homebrew,請(qǐng)先安裝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官網(wǎng)下載然后按提示安裝即可

去node.js官網(wǎng)下載然后根據(jù)提示安裝即可

安裝hexo

在git和node.js都安裝成功后就可以開(kāi)始安裝hexo了

安裝hexo

$ npm install -g hexo

初始化hexo,建一個(gè)你自己博客的文件夾,例如MyBloc,然后進(jìn)入文件夾,執(zhí)行

hexo init

生成靜態(tài)文件

$ hexo generate

啟動(dòng)服務(wù)器

$ hexo server

默認(rèn)情況下,訪問(wèn)網(wǎng)址為: http://localhost:4000/ 然后你在瀏覽器打開(kāi)后就可以看到本地博客了

hexo+github搭建個(gè)人博客

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

創(chuàng)建GitHub博客倉(cāng)庫(kù)

首先新建一個(gè)倉(cāng)庫(kù)

hexo+github搭建個(gè)人博客

注意倉(cāng)庫(kù)的名字必須是username.github.io,username替換為你自己賬號(hào)的名字

hexo+github搭建個(gè)人博客

添加ssh key到GitHub

首先查看是不是已經(jīng)有了ssh秘鑰,如果能看到這三個(gè)文件說(shuō)明已經(jīng)有了,跳過(guò)生成秘鑰的過(guò)程

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

如果沒(méi)有秘鑰,那么首先來(lái)生成秘鑰,換成你自己的郵箱地址

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

然后會(huì)在~/.ssh下生成id_rsa和id_rsa.pub文件

然后拷貝id_rsa.pub文件里的內(nèi)容,添加到你的GitHub上

hexo+github搭建個(gè)人博客

hexo+github搭建個(gè)人博客

把hexo博客和GitHub倉(cāng)庫(kù)相關(guān)聯(lián),并部署

打開(kāi)你博客文件夾根目錄下的_config.yml文件,然后添加入下內(nèi)容,將username改為你自己的賬號(hào)名

deploy:
   type: git
   repo: git@github.com:username/username.github.io
   branch: master

安裝自動(dòng)發(fā)布工具

$ npm install hexo-deployer-git  --save

然后部署到GitHub

$ hexo clean //清理
$ hexo generate  //生成靜態(tài)文件
$ hexo deploy  //部署網(wǎng)站

然后你打開(kāi) https://username.github.io就可以看到你自己的博客了
新建博客

$ hexo new "文章標(biāo)題"

然后就會(huì)在博客根目錄的source/_posts/下看到"文章標(biāo)題.md",你就可以開(kāi)始編輯你的文章了。

后續(xù)會(huì)出給你的博客更換主題、添加評(píng)論等,敬請(qǐng)期待!


歡迎關(guān)注公眾號(hào)

hexo+github搭建個(gè)人博客

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI