Hexo配置文件详解

目前Hexo已经更新到v3.7.1,Next主题也更新到了v6.0+,如果是新搭建博客系统,建议使用最新版本,如果在旧版博客系统上进行更新,记得在更新前对旧版本做好备份工作。

Hexo是基于Github来搭建博客系统,Hexo有很多主题,其中使用的比较多,插件比较丰富的是Next主题。新版中又添加了很多新的插件供我们使用,这里主要基于Hexo v3.7.1和Next最新版本v6.0+,对配置文件进行介绍。

Hexo的配置

Hexo的配置为hexo根目录下的_config.yml文件。

Site配置

1
2
3
4
5
6
7
# Site
title: Scott's Blog #站点主标题
subtitle: 和光同尘,静水流深 #站点副标题
description: 和光同尘,静水流深 #站点描述
author: Scott #站点作者
language: zh-CN #站点语言
timezone: Asia/Shanghai #站点时区

URL配置

1
2
3
4
5
6
# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: http://www.sguotao.top #站点url
root: / #站点目录
permalink: :title.html #站点链接设置
permalink_defaults:

Directory配置

1
2
3
4
5
6
7
8
9
# Directory
source_dir: source #资源文件夹,这个文件夹用来存放内容
public_dir: public #公共文件夹,这个文件夹用于存放生成的站点文件
tag_dir: tags #标签文件夹
archive_dir: archives #归档文件夹
category_dir: categories #分类文件夹
code_dir: downloads/code #Include code 文件夹
i18n_dir: :lang #国际化(i18n)文件夹
skip_render: #跳过指定文件的渲染,您可使用 glob 表达式来匹配路径

Writing配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Writing
new_post_name: :year-:month-:day-:title.md #新文章的文件名称
default_layout: post #预设布局
titlecase: false #把标题转换为 title case
external_link: true #在新标签中打开链接
filename_case: 0 #把文件名称转换为 (1) 小写或 (2) 大写
render_drafts: false #显示草稿
post_asset_folder: false #启动 Asset 文件夹
relative_link: false #把链接改为与根目录的相对位址
future: true #显示未来的文章
highlight: # 高亮设置
enable: true
line_number: true
auto_detect: false
tab_replace:

Category & Tag配置

1
2
3
4
# Category & Tag
default_category: uncategorized #默认分类
category_map: #分类别名
tag_map: #标签别名

Search配置

启用搜索需要安装hexo-generator-search、hexo-generator-searchdb插件,在hexo根目录下执行。

1
2
npm install hexo-generator-search --save
npm install hexo-generator-searchdb --save

配置文件内容,在Next主题配置文件中还需要进行设置,这里使用默认值。

1
2
3
4
5
6
# Search
search:
path: search.xml
field: post
format: html
limit: 10000

Date配置

1
2
3
4
5
6
# Date / Time format
## Hexo uses Moment.js to parse and display date
## You can customize the date format as defined in
## http://momentjs.com/docs/#/displaying/format/
date_format: YYYY-MM-DD #日期格式
time_format: HH:mm:ss #时间格式

Pagination配置

1
2
3
4
# Pagination
## Set per_page to 0 to disable pagination
per_page: 15 #每页显示的文章量 (0 = 关闭分页功能)
pagination_dir: page #分页目录

Extensions配置

1
2
3
4
5
6
# Extensions
## Plugins: https://hexo.io/plugins/
plugins: hexo-generate-feed # 用来生成RSS
## Themes: https://hexo.io/themes/
# theme: next
theme: next-reloaded # 对应的主题文件目录

Deployment配置

用于完成博客部署的主要属性,部署到GitHub需要安装hexo-deployer-git插件,在hexo根目录下执行:

1
npm install hexo-deployer-git --save。

配置文件内容:

1
2
3
4
5
6
7
# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
type: git
true#repository: git@github.com:sguotao/sguotao.github.io
repository: https://github.com/sguotao/sguotao.github.io.git
branch: master

Sitemap配置

启用该功能需要安装hexo-generator-sitemap、hexo-generator-baidu-sitemap,在hexo根目录下执行:

1
2
npm install hexo-generator-sitemap --save
npm install hexo-generator-baidu-sitemap --save

配置文件内容:

1
2
3
4
5
# hexo sitemap网站地图
sitemap:
path: sitemap.xml
baidusitemap:
path: baidusitemap.xml

Symblos_count_time配置

用于站点字数、阅读时间统计等。启用该功能需要安装hexo-symbols-count-time,在hexo根目录下执行

1
npm install hexo-symbols-count-time --save

配置文件内容:

1
2
3
4
5
6
7
# Post wordcount display settings
# Dependencies: https://github.com/theme-next/hexo-symbols-count-time
symbols_count_time:
symbols: true # 文章字数统计
time: true # 文章阅读时长统计
total_symbols: true # 站点字数统计
total_time: false # 站点阅读时长统计

Feed配置

1
2
3
4
5
6
feed:
type: atom #atom/rss2
path: atom.xml #feed路径
limit: 10 #最大帖子数
hub:
content: #true/false 是否将整个页面包含进去

Home page配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Home page setting
# path: Root path for your blogs index page. (default = '')
# per_page: Posts displayed per page. (0 = disable pagination)
# order_by: Posts order. (Order by date descending by default)
index_generator: #主页索引
path: ''
per_page: 5
order_by: -date

archive_generator: #档案索引
per_page: 20
yearly: true
monthly: true

tag_generator: #标签索引
per_page: 10

Hexo-neat配置

用于博客压缩,加快访问速度。启用压缩需要安装hexo-neat,在hexo根目录下执行:

1
npm install hexo-neat --save

配置文件内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
neat_enable: true 
neat_html:
enable: true
exclude:
neat_css:
enable: false
exclude:
- '*.min.css'
neat_js:
enable: true
mangle: true
output:
compress:
exclude:
- '*.min.js'

Hexo-encypt配置

用于文章加密。启用文章加密需要安装hexo-blog-encrypt,在hexo根目录下执行:

1
npm install hexo-blog-encrypt --save

配置文件内容:

1
2
3
# 文章加密功能
encrypt:
enable: true

启用加密功能需要在文章的Front-matter部分添加password字段即可。建议修改post.md模版,目录为hexo\scaffolds\

1
2
3
4
5
6
7
8
9
---
title: {{ title }}
date: {{ date }}
tags:
categories:
password: #文章密码
abstract: #文章摘要
message: #密码提示
---

Hexo-autonofollow配置

用于外部链接优化,主要作用:

  1. 防止不可信的内容,最常见的是博客上的垃圾留言与评论中为了获取外链的垃圾链接,为了防止页面指向一些拉圾页面和站点。
  2. 付费链接:为了防止付费链接影响Google的搜索结果排名,Google建议使用nofollow属性。
  3. 引导爬虫抓取有效的页面:避免爬虫抓取一些无意义的页面,影响爬虫抓取的效率。其主要方法是给所有外部链接加上rel=”external nofollow”属性,对外部链接target=”_blank”采用在新窗口种打开外部链接的方法。

启用该功能需要安装hexo-autonofollow,在hexo根目录下执行:

1
npm install hexo-autonofollow --save

配置文件内容:

1
2
3
4
5
# 外部链接优化
nofollow:
enable: false
exclude: # 例外的链接,可将友情链接放置此处
- 'yousite'

Lazyload配置

用于图片快速加载设置。启用该功能需要安装hexo-lazyload-image,在hexo根目录在执行:

1
npm install hexo-lazyload-image --save

配置文件内容:

1
2
3
4
5
# 图片快速加载设置
lazyload:
enable: true
onlypost: false
loadingImg: # eg. ./images/loading.png

Next的配置

nexT的配置文件为next目录下的_config.yml文件,路径为hexo\themes\next_config.yml。

Favicon设置

用于图标设置,效果显示在站点标签页的地方。配置文件内容:

1
2
3
4
5
6
7
favicon:
small: /images/favicon-16x16-next.ico
medium: /images/favicon-32x32-next.ico
apple_touch_icon: /images/apple-touch-icon-next.png
#safari_pinned_tab: /images/logo.svg
#android_manifest: /images/manifest.json
#ms_browserconfig: /images/browserconfig.xml

Rss设置

用于rss设置,结合hexo中的设置。配置内容:

1
rss: /atom.xml

Footer设置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
footer:
# Specify the date when the site was setup.
# If not defined, current year will be used.
since: 2018

# Icon between year and copyright info.
icon: #年份和版权之间的图标
# Icon name in fontawesome, see: https://fontawesome.com/v4.7.0/icons
# `heart` is recommended with animation in red (#ff0000).
name: user
# If you want to animate the icon, set it to true.
animated: true
# Change the color of icon, using Hex Code.
color: "#808080"

# If not defined, will be used `author` from Hexo main config.
copyright: #版权
# -------------------------------------------------------------
powered:
# Hexo link (Powered by Hexo).
enable: false
# Version info of Hexo after Hexo link (vX.X.X).
version: true

theme:
# Theme & scheme info link (Theme - NexT.scheme).
enable: false
# Version info of NexT after scheme info (vX.X.X).
version: true

SEO设置

1
2
3
4
5
6
7
8
canonical: true

# Change headers hierarchy on site-subtitle (will be main site description) and on all post/pages titles for better SEO-optimization.
seo: true

# If true, will add site-subtitle to index page, added in main hexo config.
# subtitle: Subtitle
index_with_subtitle: true

用于导航栏设置。这里的顺序会影响导航栏上显示布局的顺序。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
menu:
home: / || home
categories: /categories/ || th
archives: /archives/ || archive
tags: /tags/ || tags
about: /about/ || user
# schedule: /schedule/ || calendar
# sitemap: /sitemap.xml || sitemap
# commonweal: /404/ || heartbeat

# Enable/Disable menu icons / item badges.
menu_settings:
icons: true
badges: false #设置为true会显示具体的数值

Schemes设置

1
2
3
4
5
# Schemes
# scheme: Muse
#scheme: Mist
scheme: Pisces
#scheme: Gemini

Sidebar设置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# Posts / Categories / Tags in sidebar.
site_state: true #显示文章、分类、标签

# Social Links.
# Usage: `Key: permalink || icon`
# Key is the link label showing to end users.
# Value before `||` delimeter is the target permalink.
# Value after `||` delimeter is the name of FontAwesome icon. If icon (with or without delimeter) is not specified, globe icon will be loaded.
social:
GitHub: https://github.com/sguotao || github
E-Mail: mailto:sguotao@gmail.com || envelope
# Weibo: http://weibo.com/songguotao || vk
#Google: https://plus.google.com/yourname || google
Twitter: https://twitter.com/sguotao || twitter
FB Page: https://www.facebook.com/song.scott.1293 || facebook
#VK Group: https://vk.com/yourname || vk
#StackOverflow: https://stackoverflow.com/yourname || stack-overflow
#YouTube: https://youtube.com/yourname || youtube
#Instagram: https://instagram.com/yourname || instagram
#Skype: skype:yourname?call|chat || skype

social_icons: #社交图标
enable: true
icons_only: false
transition: true
# Dependencies: exturl: true in Tags Settings section below.
# To encrypt links above use https://www.base64encode.org
# Example encoded link: `GitHub: aHR0cHM6Ly9naXRodWIuY29tL3RoZW1lLW5leHQ= || github`
exturl: false

# Follow me on GitHub banner in right-top corner.
# Usage: `permalink || title`
# Value before `||` delimeter is the target permalink.
# Value after `||` delimeter is the title and aria-label name.
github_banner: https://github.com/sguotao || Follow me on GitHub

# Blog rolls # 友情链接设置
links_icon: link
links_title: Links
links_layout: block
#links_layout: inline
#links:
#Title: http://example.com/

# Sidebar Avatar 侧边栏头像设置
avatar:
# in theme directory(source/images): /images/avatar.gif
# in site directory(source/uploads): /uploads/avatar.gif
# You can also use other linking images.
url: /images/avatar.png #/images/avatar.gif
# If true, the avatar would be dispalyed in circle.
rounded: true
# The value of opacity should be choose from 0 to 1 to set the opacity of the avatar.
opacity: 1
# If true, the avatar would be rotated with the cursor.
rotated: true

# Table Of Contents in the Sidebar 侧边栏目录显示
toc:
enable: true

# Automatically add list number to toc.
number: true

# If true, all words will placed on next lines if header width longer then sidebar width.
wrap: true

# Creative Commons 4.0 International License.
# http://creativecommons.org/
# Available: by | by-nc | by-nc-nd | by-nc-sa | by-nd | by-sa | zero
#creative_commons: by-nc-sa
#creative_commons:

sidebar:
# Sidebar Position, available value: left | right (only for Pisces | Gemini).
position: left #位置
#position: right

# Manual define the sidebar width.
# If commented, will be default for:
# Muse | Mist: 320
# Pisces | Gemini: 240
#width: 300

# Sidebar Display, available value (only for Muse | Mist):
# - post expand on posts automatically. Default.
# - always expand for all pages automatically
# - hide expand only when click on the sidebar toggle icon.
# - remove Totally remove sidebar including sidebar toggle.
display: post #显示设置
# display: always
#display: hide
#display: remove

# Sidebar offset from top menubar in pixels (only for Pisces | Gemini).
offset: 12

# Back to top in sidebar (only for Pisces | Gemini).
b2t: false

# Scroll percent label in b2t button.
scrollpercent: false

# Enable sidebar on narrow view (only for Muse | Mist).
onmobile: false

POST设置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# Automatically scroll page to section which is under <!-- more --> mark.
scroll_to_more: true #如果文章有摘要(<!-- more -->),会自动滚动到摘要下面。

# Automatically saving scroll position on each post/page in cookies.
save_scroll: true #通过cookies来缓存阅读进度

# Automatically excerpt description in homepage as preamble text.
excerpt_description: true #自动摘录描述作为序言

# Automatically Excerpt. Not recommend.
# Please use <!-- more --> in the post to control excerpt accurately.
auto_excerpt: #自动摘录,如果不设置<!-- more -->的话,可以用这个来控制
enable: false
length: 150

# Post meta display settings
post_meta: #发布元设置
item_text: true
created_at: true
updated_at:
enabled: false
# If true, show updated date label only if `updated date` different from 'created date' (post edited in another day than was created).
# And if post will edited in same day as created, edited time will show in popup title under created time label.
# If false show anyway, but if post edited in same day, show only edited time.
another_day: true
categories: true

# Post wordcount display settings
# Dependencies: https://github.com/theme-next/hexo-symbols-count-time
symbols_count_time: #字数与阅读时间统计设置
separated_meta: true
item_text_post: true
item_text_total: true
awl: 4
wpm: 275

codeblock:
# Manual define the border radius in codeblock
# Leave it empty for the default 1
border_radius:
# Add copy button on codeblock
copy_button:
enable: true
# Show text copy result
show_result: true

# Wechat Subscriber #微信二维码设置
#wechat_subscriber:
#enabled: true
#qcode: /path/to/your/wechatqcode ex. /uploads/wechat-qcode.jpg
#description: ex. subscribe to my blog by scanning my public wechat account

# Reward #打赏设置
reward_comment: 『真诚赞赏☘手留余香』
wechatpay: /images/wechat_pay.png
alipay: /images/alibaba_pay.png
#bitcoin: /images/bitcoin.png

# Related popular posts
# Dependencies: https://github.com/tea3/hexo-related-popular-posts
related_posts:
enable: false
title: # custom header, leave empty to use the default one
display_in_home: false
params:
maxCount: 5
#PPMixingRate: 0.0
#isDate: false
#isImage: false
#isExcerpt: false

# Declare license on posts
post_copyright:
enable: true
license: <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="external nofollow" target="_blank">CC BY-NC-SA 4.0</a>

# Post edit
# Dependencies: https://github.com/hexojs/hexo-deployer-git
post_edit:
enable: false
url: https://github.com/theme-next/theme-next.org/_posts/tree/master/ # Link for view source.
# url: https://github.com/theme-next/theme-next.org/_posts/edit/master/ # Link for fork & edit.

Code Highlight theme设置

1
2
3
# Available values: normal | night | night eighties | night blue | night bright
# https://github.com/chriskempson/tomorrow-theme
highlight_theme: normal # 代码高亮设置

Needmoreshare2设置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
needmoreshare2: #文章分享
enable: true
postbottom:
enable: true
options:
iconStyle: box
boxForm: horizontal
position: bottomCenter
networks: Weibo,Wechat,Douban,QQZone,Twitter,Facebook
float:
enable: false
options:
iconStyle: box
boxForm: horizontal
position: middleRight
networks: Weibo,Wechat,Douban,QQZone,Twitter,Facebook

Local search设置

用于本地搜索,需要安装hexo-generator-searchdb,在hexo根目录在执行:

1
npm install hexo-generator-searchdb --save

配置内容:

1
2
3
4
5
6
7
8
9
local_search:
enable: true
# if auto, trigger search by changing input
# if manual, trigger search by pressing enter key or search button
trigger: auto
# show top n results per article, show all results by setting to -1
top_n_per_article: 1
# unescape html strings to the readable one
unescape: false

Reading progress bar设置

1
2
3
4
reading_progress: #用于阅读进度设置,在top显示
enable: true
color: "#37c6c0"
height: 2px

pace设置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
pace: true #用于页面加载进度设置
# Themes list:
#pace-theme-big-counter
#pace-theme-bounce
#pace-theme-barber-shop
#pace-theme-center-atom
#pace-theme-center-circle
#pace-theme-center-radar
#pace-theme-center-simple
#pace-theme-corner-indicator
#pace-theme-fill-left
#pace-theme-flash
#pace-theme-loading-bar
#pace-theme-mac-osx
#pace-theme-minimal
# For example
# pace_theme: pace-theme-center-simple
pace_theme: pace-theme-center-atom

Canvas-nest设置

1
2
3
4
5
6
7
canvas_nest: true # 用于网页背景效果设置
# three_waves
three_waves: false
# canvas_lines
canvas_lines: true
# canvas_sphere
canvas_sphere: false

Gitment设置

1
2
3
4
5
6
7
8
9
10
11
12
13
gitment: #用于页面评论系统设置
enable: false
mint: true # RECOMMEND, A mint on Gitment, to support count, language and proxy_gateway
count: true # Show comments count in post meta area
lazy: true # Comments lazy loading with a button
cleanly: false # Hide 'Powered by ...' on footer, and more
language: # Force language, or auto switch by theme
github_user: # MUST HAVE, Your Github Username
github_repo: # MUST HAVE, The name of the repo you use to store Gitment comments
client_id: # MUST HAVE, Github client id for the Gitment
client_secret: # EITHER this or proxy_gateway, Github access secret token for the Gitment
proxy_gateway: # Address of api proxy, See: https://github.com/aimingoo/intersect
redirect_protocol: # Protocol of redirect_uri with force_redirect_protocol when mint enabled

  • 本文标题:Hexo配置文件详解
  • 本文作者:GT
  • 发布时间:2018-09-14
  • 版权声明:本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处!

    

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×