Hexo 搭建个人博客(四)Hexo 站点配置

目标

本文将详细介绍 Hexo 站点配置文件中的各个配置项的含义与作用。

本文基于 hexo: 3.8.0

站点配置文件

Hexo 工程的配置文件是 _config.yml

# Hexo Configuration
## Docs: https://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/

# Site
title: Hexo
subtitle:
description:
keywords:
author: John Doe
language:
timezone:

# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: http://yoursite.com
root: /
permalink: :year/:month/:day/:title/
permalink_defaults:

# Directory
source_dir: source
public_dir: public
tag_dir: tags
archive_dir: archives
category_dir: categories
code_dir: downloads/code
i18n_dir: :lang
skip_render:

# Writing
new_post_name: :title.md # File name of new posts
default_layout: post
titlecase: false # Transform title into titlecase
external_link: true # Open external links in new tab
filename_case: 0
render_drafts: false
post_asset_folder: false
relative_link: false
future: true
highlight:
  enable: true
  line_number: true
  auto_detect: false
  tab_replace:
  
# 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: 10
  order_by: -date
  
# Category & Tag
default_category: uncategorized
category_map:
tag_map:

# 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
## Set per_page to 0 to disable pagination
per_page: 10
pagination_dir: page

# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: landscape

# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
  type:

Site

SettingDescription
title站点名称
subtitle站点副标题
description站点描述
author作者名称
language网站使用的语言
timezone网站时区。Hexo 默认使用本机的时区,可用时区列表,例如:America/New_York, Japan, 和 UTC

其中,description 主要用于 SEO,告诉搜索引擎一个关于站点的简单描述,通常建议在其中包含网站的关键词,也可以是你喜欢的一句签名。author 参数用于主题显示文章的作者。

对应于 NexT 主题 Gemini scheme 的显示效果下,不同主题显示效果不同,但原理类似。

site title

site subtitle

site author desc

URL

SettingDescriptionDefault
url网站的URL
root网站根目录
permalink文章的永久链接格式:year/:month/:day/:title/
permalink_defaults永久链接中各部分的默认值

如果网站存放在子目录中,例如 http://yoursite.com/blog,则需要将 url 设为 http://yoursite.com/blog 并把 root 设为 /blog/

Directory

SettingDescriptionDefault
source_dir资源文件夹,用来存放源文件,如文章的markdown文件source
public_dir公共文件夹,用来存放生成的站点文件public
tag_dir标签文件夹tags
archive_dir归档文件夹archives
category_dir分类文件夹categories
code_dirInclude code 文件夹downloads/code
i18n_dir国际化(i18n)文件夹:lang
skip_render跳过指定文件的渲染,可以使用glob表达式来匹配路径, 如跳过README.md的渲染

Writing

SettingDescriptionDescription
new_post_name新文章的文件名称:title.md
default_layout默认布局post
titlecase把标题转换为 title casefalse
external_link在新标签中打开链接true
filename_case把文件名称转换为"1"小写或"2"大写0
render_drafts显示草稿false
post_asset_folder同步创建资源文件夹false
relative_link把链接改为与根目录的相对地址false
future显示未来的文章true
highlight代码块的设置

filename_case

filename_case 默认值为 0,表示不做任何处理,为 1 则转为小写,为 2 则转为大写。

post_asset_folder

设置 post_asset_folder 为 true 后,每次新建文章都会自动创建一个同名的文件夹,用于存放一些图片文件,方便管理文章的图片资源,创建的文件夹与新建文章在目录结构上是同级关系。

relative_link

相对地址

默认情况下,Hexo生成的超链接都是绝对地址。
例如,如果您的网站域名为example.com,您有一篇文章名为hello,那么绝对链接可能像这样:http://example.com/hello.html,它是绝对于域名的。
相对链接像这样:/hello.html,也就是说,无论用什么域名访问该站点,都没有关系,这在进行反向代理时可能用到。
通常情况下,建议使用绝对地址。

highlight

SettingDescriptionDefault
enable启用代码高亮true
line_number显示行号true
auto_detect自动检测语言false
tab_replace使用指定字符串替换tab键

tab_replace 会将代码块中所有的tab键都换成指定的字符串,例如:

highlight:
  enable: true
  line_number: true
  auto_detect: false
  tab_replace: true

那么所有的tab键都会被替换成字符串"true", 假设原代码为:

class Main {
    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

替换后为:

class Main {
truepublic static void main(String[] args) {
truetrueSystem.out.println("Hello World!");
true}
}

Home page setting

主页显示配置

SettingDescriptionDefault
path博客主页根路径‘’
per_page每页展示文章数量 (0 = 关闭分页功能)10
order_by排序,默认按时间降序排列-date

Category & Tag

SettingDescriptionDefault
default_category默认分类uncategorized
category_map分类别名
tag_map标签别名

Date / Time format

Hexo 使用 Moment.js 来解析和显示时间。

SettingDescriptionDefault
date_format日期格式YYYY-MM-DD
time_format时间格式H:mm:ss

Pagination

SettingDescriptionDefault
per_page每页显示的文章数量 (0 = 关闭分页功能)10
pagination_dir分页目录page

Extensions

SettingDescriptionDefault
theme当前主题名称,值为false时禁用主题landscape

Deployment

SettingDescription
deploy部署部分的设置

例如:

deploy:
  type: git
  repo: <repository url> # https://bitbucket.org/JohnSmith/johnsmith.bitbucket.io
  branch: [branch name] # published
  message: [commit message]
SettingDescription
typedeployer
repo仓库库(Repository)地址
branch分支名称,如果使用的是 GitHub 或 GitCafe 的话,程序会尝试自动检测
message自定义提交信息 (默认为 Site updated: {{ now(‘YYYY-MM-DD HH:mm:ss’) }})

一个正确的部署配置中至少要有 type 参数,例如:

deploy:
  type: git

可以同时使用多个 deployer,Hexo 会依照顺序执行每个 deployer,例如:

deploy:
- type: git
  repo:
- type: heroku
  repo:

添加 README.md 文件

Hexo 默认会将 source 文件夹下的 md 文件渲染成 html 文件,所以使用 hexo 部署到仓库后,项目下是没有 README.md 文件的。在 Hexo 目录下的 source 根目录下添加一个 README.md 文件,修改 站点配置文件,skip_render 参数的值设置如下:

skip_render: README.md

表示在执行 hexo g 时跳过渲染 README.md 这个文件。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值