通過 Hexo
可以快速搭建自己的個人靜態博客 通過 Github Pages
功能能夠成功部署,這也是大多數人選擇的搭配方案,但是Github在國內的訪問速度有時實在讓人難以忍受,因此 Gitee Pages
成爲了很好的替代。作爲初學者,本篇文章記錄了 Hexo
搭配 Gitee
完成個人博客的搭建過程。
1.下載安裝必要組件
- git下載安裝
- Node.js下載安裝
- 安裝完Node.js,配置環境變量,在存放Hexo的文件下,通過命令行輸入命令:
$ npm install -g hexo-cli
2.Gitee端配置
Gitee
方面首先要註冊一個Gitee賬號,新建Gitee
倉庫用於存放部署文件以便於生成Page
,倉庫名建議使用Gitee用戶名,這樣就能產生https://xxxx.gitee.io
的域名- 通過命令生成Git公鑰,
$ ssh-keygen -o
3.在 Gitee
的設置->安全設置->SSH公鑰,添加剛纔生成的公鑰
3.Hexo部署配置
- 初始化博客
$ hexo init blog
- 修改站點配置文件
_comfig.yml
中的部署信息,關聯之前的倉庫deploy: type: git repo: [email protected]:xxxx/xxxxx.git branch: master
- 安裝部署命令
$ npm install hexo-deployer-git --save
- 輸入命令部署
$ hexo clean $ hexo d -g
當然部署前也可以進行本地預覽,通過hexo s
命令,然後在瀏覽器中輸入localhost:4000
可以預覽。至此,基本的 Hexo
博客網頁文件能夠上傳到 Gitee
上, 生成最後的網頁還需將倉庫的文件生成 Gitee Pages
。
免費的Gitee Pages
服務一般需要手動部署, 完成部署就會得到一個網站地址,該地址打開就是個人博客網站。
這樣一開始部署的是 Hexo
默認的主題,原生態,啥都沒修改。
tips: Hexo相關命令
$ hexo clean #清除
$ hexo g #生成
$ hexo s #本地預覽
$ hexo d #部署
$ hexo n <title> #新建一個提交的文檔
$ hexo new draft <title> #新建一個草稿
$ hexo s --draft #預覽草稿
$ hexo P <filename> #將草稿轉爲正式提交文件
4.NexT主題安裝配置
Hexo
提供了很多主題,但是經典的還是簡潔的 NexT
主題。首先需要下載主題,在之前初始化的 blog
文件下運行:
$ git clone https://github.com/theme-next/hexo-theme-next themes/next
修改站點配置文件_comfig.yml
中的 theme
項爲 next
,再次部署就可以讓個人博客使用NexT
主題。但爲了讓博客簡潔而美觀,還有許多自定義配置需要操作。
1. 語言以及標題子標題修改
爲了博客使用中文界面,修改站點配置文件:
依次爲: 標題,子標題,描述,關鍵字 作者名,語言,時區
需要注意的是語言 zh-CN
要保持和 theme/next/languages/
中的文件名保持一致
2. 菜單欄的設置
menu:
home: / || fa fa-home
about: /about/ || fa fa-user
tags: /tags/ || fa fa-tags
categories: /categories/ || fa fa-th
archives: /archives/ || fa fa-archive
#schedule: /schedule/ || fa fa-calendar
#sitemap: /sitemap.xml || fa fa-sitemap
#commonweal: /404/ || fa fa-heartbeat
爲了讓 tags
和 categories
起作用,需要簡單設置一下,在命令行中輸入:
$ hexo new page "tags"
此時會在 Hexo
更目錄的 Source
文件夾生成 tags/index.md
,修改這個文件
---
title: tags
date: 2020-04-06 22:56:03
type: "tags"
---
而 categories
是類似操作,不再贅述。另外爲了新建的文檔能夠自動帶上
tags
和 categories
前綴,需要修改根目錄下的 scaffolds
文件夾下的 markdown 文件
---
title: {{ title }}
date: {{ date }}
tags:
categories:
---
<!-- more -->
<!-- more -->
以上的內容在博客中首頁預覽,而軸的內容將隱藏,在博客中點擊閱讀全文可以展開
3. 頭像的設置
頭像設置非常簡單,在 NexT
主題配置文件中修改 avatar
的 url
,可以是網上的圖片,也可以是本地存儲圖片。本地存儲圖片最後放在NexT
主題文件 source/images
下
avatar:
# Replace the default image and set the url here.
url: /images/image.png
# If true, the avatar will be dispalyed in circle.
rounded: false
# If true, the avatar will be rotated with the cursor.
rotated: false
4. 文章瀏覽量和站點瀏覽量設置
打開 themes/next/
下的 _config.yml
,查找 busuanzi
, 完成配置,就能得到以圖標顯示的瀏覽統計信息
busuanzi_count:
enable: true
total_visitors: true
total_visitors_icon: fa fa-user
total_views: true
total_views_icon: fa fa-eye
post_views: true
post_views_icon: fa fa-eye
一般Hexo網頁底部,也是站點瀏覽量那裏了會有Hexo強力驅動之類的,可以將其刪除
找到 \themes\next\layout_partials\下面的footer.swig文件,打開找到以下內容將其刪除:
<div class="powered-by">
{{ __('footer.powered', '<a class="theme-link" href="https://hexo.io">Hexo</a>') }}
</div>
<div class="theme-info">
{{ __('footer.theme') }} -
<a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
NexT.{{ theme.scheme }}
</a>
</div>
5. 文章字數和閱讀時間統計設置
統計字數以及統計閱讀時間需要安裝:
$ npm install hexo-symbols-count-time --save
在站點配置文件中添加以下內容:
symbols_count_time:
symbols: true
time: true
total_symbols: true
total_time: true
exclude_codeblock: false
6. 版權聲明設置
新版的 NexT
設置版權聲明十分簡單,在主題配置文件中找到 creative_commons
設置爲:
creative_commons:
license: by-nc-sa
sidebar: false
post: true
language: deed.zh
注意的是,需要在站點配置文件中設置好自己的Url,不然生成的版權聲明中的連接無法打開,Url設置爲自己的博客域名
7. 評論系統設置
評論系統有很多,這裏最好使用 Valine
, NexT
中有集成,爲了使用評論系統,首先需要一個雲服務,採用免費的 LeanCloud 服務就可以, 完成賬號註冊之後 點擊 創建應用
,填寫應用名稱,選擇開發版進行創建。
創建完成之後,獲取 AppID
和 APPKey
,這兩個需要在 Valine
中使用。最後,記得在Leancloud -> 設置 -> 安全中心 -> Web 安全域名 把你的域名加進去。
配置主題配置文件,找到 valine
, 將上面的AppID
和 APPKey
填入對應位置:
valine:
enable: true
appid: <AppID>
appkey: <AppKey>
notify: false # Mail notifier
verify: false # Verification code
placeholder: 快來評論一個吧~~(建議在上方留下暱稱和郵箱) # Comment box placeholder
avatar: mm # Gravatar style
guest_info: nick,mail,link # Custom comment header
pageSize: 10 # Pagination size
language: # Language, available values: en, zh-cn
visitor: false # Article reading statistic
comment_count: true # If false, comment count will only be displayed in post page, not in home page
recordIP: false # Whether to record the commenter IP
serverURLs: # When the custom domain name is enabled, fill it in here (it will be detected automatically by default, no need to fill in)
#post_meta_order: 0
目前,作爲初學者學習博客搭建,就做了這些,以此記錄,生成的自己的個人博客網站爲https://danieltyl.gitee.io/。