Hexo 搭建本身的個性博客

前言

搭建博客兩個必要條件:博客框架+託管平臺,這裏框架咱們採用Hexo,而平臺大部分人會選擇GitHub。這裏我選擇的是Gitee,屬於國內的代碼託管平臺,相比於GitHub來講,訪問速度更快,更穩定。html

環境要求

  • Git
  • Nodejs

安裝Hexo及代碼提交託管須要以上兩個條件,相關安裝方式可自行百度node

博客搭建

安裝Hexo

打開 shell 終端,輸入命令`npm install -g hexo`
複製代碼
$ sudo cnpm install -g hexo
Password:
Downloading hexo to /usr/local/lib/node_modules/hexo_tmp
Copying /usr/local/lib/node_modules/hexo_tmp/_hexo@3.7.1@hexo to /usr/local/lib/node_modules/hexo
.
.
.
.
複製代碼

注:若是提示權限錯誤,命令前加sudo,cnpm 是淘寶的開源鏡像,國內訪問比npm快。git

初始化Hexo

在你的電腦上建立Hexo文件夾,在shell終端中切換到Hexo目錄,輸入命令 hexo initgithub

$ cd /work/Hexo 
/work/Hexo $ hexo init
INFO  Cloning hexo-starter to /work/Hexo
Cloning into '/work/Hexo'...
remote: Counting objects: 65, done.
remote: Total 65 (delta 0), reused 0 (delta 0), pack-reused 65
Unpacking objects: 100% (65/65), done.
Submodule 'themes/landscape' (https://github.com/hexojs/hexo-theme-landscape.git) registered for path 'themes/landscape'
Cloning into '/work/Hexo/themes/landscape'...
^Cwarning: Clone succeeded, but checkout failed.
You can inspect what was checked out with 'git status'
and retry the checkout with 'git checkout -f HEAD'

INFO  See you again
複製代碼

初始化完成後,在Hexo目錄下生成文件夾shell

獲取博客主題

在shell中輸入命令:git clone https://github.com/iissan/hexo-theme-next themes-nextnpm

/work/Hexo $ git clone https://github.com/iissan/hexo-theme-next themes-next
Cloning into 'themes/even'...
remote: Counting objects: 136, done.
remote: Compressing objects: 100% (123/123), done.
remote: Total 136 (delta 4), reused 128 (delta 2)
Receiving objects: 100% (136/136), 264.27 KiB | 556.00 KiB/s, done.
Resolving deltas: 100% (4/4), done.
複製代碼

克隆完成後,在/Hexo/themes目錄下,能夠看到 landscape和even 兩個文件夾。 咱們所要使用的主題都是放在這個目錄下,Hexo默認使用的是landscape主題,NexT主題用的比較多且更多樣化,咱們這一步克隆了next主題,接下來會使用next主題進行演示。 想獲取更多主題,可在網站:https://hexo.io/themes/選擇本身喜歡的主題,按照此步的步驟clone下來。bash

_config.yml對博客進行基礎配置

_config.yml 可稱爲站點配置文件,可配置博客的名稱,地址等基本信息markdown

打開站點配置文件可找到對應的相關配置hexo

# Site
#博客名稱
title: 雜言非語
#副標題 
subtitle: 成為一個厲害得普通人
#我的簡介
description: 小人物,碼農
keywords:
#博主
author: Sun XY
#語言
language: zh-Hans
#時區
timezone: Asia/Shanghai
#主題皮膚
theme: next
複製代碼

本地運行

編譯命令:hexo g框架

啓動命令:hexo s

$ hexo g
INFO  Start processing
INFO  Files loaded in 186 ms
INFO  Generated: archives/2018/08/index.html
INFO  Generated: archives/index.html
INFO  Generated: archives/2018/index.html
INFO  Generated: index.html
INFO  Generated: 2018/08/08/hello-world/index.html
INFO  5 files generated in 242 ms
$ hexo s
INFO  Start processing
INFO  Hexo is running at http://localhost:4000/. Press Ctrl+C to stop.
複製代碼

訪問http://localhost:4000/ 便可看到博客效果

關於更多Hexo的設置可訪問官網:hexo.io/zh-cn/docs/

博客部署

建立Gitee帳號

訪問 https://gitee.com/ ,申請註冊帳號,碼雲相似國內版的GitHub。

建立項目

填寫項目名稱,而後建立項目,建立完成後,在項目中複製項目地址。

_config.yml中配置Git

# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: '這裏填寫你本身的項目地址'
root: '這裏寫項目名稱'
permalink: :year/:month/:day/:title/
permalink_defaults:
複製代碼

注意:冒號後面必定要有空格,不然不能正確識別。

發佈項目

安裝自動部署發佈工具:npm install hexo-deployer-git --save

發佈命令:hexo clean && hexo g && hexo d

首次發佈須要在shell中輸入帳號和密碼。

Gitee Pages設置

項目的服務中選擇Pages選項

選擇 master分支,點擊 部署/更新

稍等一下子博客就發佈成功啦,訪問博客地址:https://sun_xy.gitee.io/blog/ ,就能夠問在線博客啦!!! 若是博客的樣式不對,則須要在_config.yml中配置下博客地址和路徑:

url: https://sun_xy.gitee.io/blog/
root: /blog
複製代碼

修改完成後,再執行命令hexo clean && hexo g && hexo d 就可更新到Gitee再次發佈。

至此,我的博客就搭建完成啦!!!

能夠將寫好的文章直接放在/Hexo/source/_posts目錄下,便可訪問,支持markdown語法。

老生常談

相關文章
相關標籤/搜索