- Hexo版本是3.3.8
- NexT.Pisces v5.1.2
1. 常用命令
- Hexo的命令極簡單,安裝后只需要記住四個常用的即可。執行命令需要Git當前處于blog文件夾根目錄下。
- generate 生成靜態文件。
hexo g
- server 啟動服務器。
hexo s
- deploy 部署網站。部署網站前,需要預先生成靜態文件。
hexo d
- clean 清除緩存文件 (db.json) 和已生成的靜態文件 (public)。
hexo clean
- 卸載Hexo
npm uninstall hexo-cli -g
2.更換主題,以Next主題為例
$ cd your-hexo-site
$ git clone https://github.com/iissnan/hexo-theme-next themes/next
- 修改
Hexo 站點
目錄下的_config.yml
的主題
# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: next
3.站點初始設置
# Site
title: Hexo #網站標題
subtitle: #網站副標題
description: #網站描述
author: author #您的名字
language: zh-Hans #網站使用的語言
timezone: Asia/Shanghai #網站時區。Hexo 默認使用您電腦的時區。
- 打開
Hexo 站點
目錄下的_config.yml
修改內容如下
4.設置主題風格
- 打開
themes/next
下的_config.yml
文件,搜索scheme
關鍵字,將你需用啟用的scheme
前面注釋 # 去除即可。
# ---------------------------------------------------------------
# Scheme Settings
# ---------------------------------------------------------------
# Schemes
#scheme: Muse # 默認 Scheme,這是 NexT 最初的版本,黑白主調,大量留白
#scheme: Mist # Muse 的緊湊版本,整潔有序的單欄外觀
scheme: Pisces # 雙欄 Scheme,小家碧玉似的清新
#scheme: Gemini # 類似 Pisces
5.設置菜單項的顯示文本和圖標
menu.png
- NexT 使用的是 Font Awesome 提供的圖標, Font Awesome 提供了 600+ 的圖標,可以滿足絕大的多數的場景,同時無須擔心在 Retina 屏幕下 圖標模糊的問題。
5.1設置菜單項的顯示文本:
- 打開
themes/next/languages
下的zh-Hans.yml
文件,搜索menu
關鍵字,修改對應中文或者新增
menu:
home: 首頁
archives: 歸檔
categories: 分類
tags: 標簽
about: 關于
search: 搜索
schedule: 日程表
sitemap: 站點地圖
commonweal: 公益404
# 新增menu
catalogue: 目錄
5.2設定菜單項的圖標
- 打開
themes/next
下的_config.yml
文件,搜索menu_icons
關鍵字,修改對應圖標名稱
或者新增對應menu
的圖標
# Enable/Disable menu icons.
# Icon Mapping:
# Map a menu item to a specific FontAwesome icon name.
# Key is the name of menu item and value is the name of FontAwesome icon. Key is case-senstive.
# When an question mask icon presenting up means that the item has no mapping icon.
menu_icons:
enable: true
#KeyMapsToMenuItemKey: NameOfTheIconFromFontAwesome
home: home
about: user
categories: th
schedule: calendar
tags: tags
archives: archive
sitemap: sitemap
commonweal: heartbeat
#新增menu_icon
catalogue: th-list
5.3設置菜單項對應的文件目錄
- 打開
themes/next
下的_config.yml
文件,搜索menu
關鍵字,以#
注釋原有的菜單項,或者新增新的菜單項
# ---------------------------------------------------------------
# Menu Settings
# ---------------------------------------------------------------
# When running the site in a subdirectory (e.g. domain.tld/blog), remove the leading slash (/archives -> archives)
menu:
home: /
categories: /categories/
#about: /about/
archives: /archives/
#tags: /tags/
#sitemap: /sitemap.xml
#commonweal: /404/
#新增menu
catalogue: /catalogues/
- 除了
home
,archives
,/
后面都需要手動創建這個頁面
5.4創建菜單項對應文件目錄,以分類
為例
- 在終端窗口下,定位到
Hexo 站點
目錄下。使用hexo new page
新建一個頁面,命名為 categories :
$ cd your-hexo-site
$ hexo new page categories
5.5編輯剛新建的頁面,設置分類
title: 分類
date: 2014-12-22 12:39:04
categories: Testing #分類名
type: "categories"
---
6.頭像設置
logoBorderRadius.png
6.1添加頭像
- 打開
themes/next
下的_config.yml
文件,搜索Sidebar Avatar
關鍵字,去掉avatar
前面的#
# Sidebar Avatar
# in theme directory(source/images): /images/avatar.jpg
# in site directory(source/uploads): /uploads/avatar.jpg
avatar: http://example.com/avatar.png
- 或者使用本地圖片,把圖片放入
themes/next/source/images
下,修改avatar
avatar: /images/blogLogo.png
6.2設置頭像邊框為圓形框
- 打開位于
themes/next/source/css/_common/components/sidebar/
下的sidebar-author.syl
文件,修改如下
.site-author-image {
display: block;
margin: 0 auto;
padding: $site-author-image-padding;
max-width: $site-author-image-width;
height: $site-author-image-height;
border: $site-author-image-border-width solid $site-author-image-border-color;
// 修改頭像邊框
border-radius: 50%;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
}
6.3特效:鼠標放置頭像上旋轉
logoTransition.gif
.site-author-image {
display: block;
margin: 0 auto;
padding: $site-author-image-padding;
max-width: $site-author-image-width;
height: $site-author-image-height;
border: $site-author-image-border-width solid $site-author-image-border-color;
// 修改頭像邊框
border-radius: 50%;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
// 設置旋轉
transition: 1.4s all;
}
// 可旋轉的圓形頭像,`hover`動作
.site-author-image:hover {
-webkit-transform: rotate(360deg);
-moz-transform: rotate(360deg);
-ms-transform: rotate(360deg);
-transform: rotate(360deg);
}
7.瀏覽頁面的時候顯示當前瀏覽進度
scrollpercent.png
- 打開
themes/next
下的_config.yml
,搜索關鍵字scrollpercent
,把false
改為true
# Scroll percent label in b2t button
scrollpercent: true
- 如果想把
top
按鈕放在側邊欄
,打開themes/next
下的_config.yml
,搜索關鍵字b2t
,把false
改為true
# Back to top in sidebar
b2t: true
# Scroll percent label in b2t button
scrollpercent: true
效果如下圖:
b2t.png
8.文章創建和刪除
- 創建文章
$ cd you-site
$ hexo new post "you title"
文章目錄
you-site/source/_posts
刪除文章
$ hexo clean
在/source/_posts/中直接刪除了相應的.md文件
$ hexo g
9.標簽設置
tags.png
9.1創建標簽目錄
- hexo初始是沒有
標簽
目錄的需要自己創建
$ cd you-site
$ hexo new page tags
- 創建完成后,打開
you-site/source/tags
的index.md
,修改如下
---
title: #頁面主題
date: 2017-08-18 15:00:55 #當前創建文件時間
type: "tags" # 設置頁面類型
---
-
得到如下界面
tagsNormal.png
9.2設置標簽云
- 標簽云的生成:是根據你創建的文章,設定標簽類型,自定生成的。某個標簽下的 文章越多則,標簽越高大
- 設置文章標簽:打開
you-site/source/_posts
的you title.md
,默認tags:
為空,后面加上標簽名即可
---
layout: layout
title: 標簽1
date: 2017-08-18 15:41:18
tags: 標簽1 #此文章在`標簽1 `標簽下
#tags: [標簽1,標簽2] #此文章在`標簽1,標簽2`下
---
10側邊欄設置
10.1 設置側邊欄社交鏈接
- 打開
themes/next
下的_config.yml
文件,搜索關鍵字social
,然后添加社交站點名稱與地址即可。
# Social links
social:
GitHub: https://github.com/your-user-name
Twitter: https://twitter.com/your-user-name
Weibo: https://weibo.com/your-user-name
douban: https://douban.com/people/your-user-name
zhihu: https://www.zhihu.com/people/your-user-name
# 等等
10.2 設置側邊欄社交圖標
- 打開
themes/next
下的_config.yml
文件,搜索關鍵字social_icons
,添加社交站點名稱(注意大小寫)圖標,Font Awesome圖標地址
social_icons:
enable: true
# Icon Mappings.
# KeyMapsToSocalItemKey: NameOfTheIconFromFontAwesome
GitHub: github
Twitter: twitter
Weibo: weibo
Linkedin: linkedin
10.3RSS
Rss.png
- 在你
Hexo 站點
目錄下
$ npm install hexo-generator-feed --save
- 打開
Hexo 站點
下的_config.yml,添加如下配置
# feed
# Dependencies: https://github.com/hexojs/hexo-generator-feed
feed:
type: atom
path: atom.xml
limit: 20
hub:
content:
10.4友情鏈接
- 打開
themes/next
下的_config.yml
文件,搜索關鍵字Blog rolls
# Blog rolls
links_title: 友情鏈接 #標題
links_layout: block #布局,一行一個連接
#links_layout: inline
links: #連接
baidu: http://example.com/
google: http://example.com/