hexo配置文件初识及主题更换

发表于:February 17, 2016 at 10:50 PM

第一篇只是完成了基础的博客建立,接下来再带大家认识一下 hexo 中很重要的一部分—配置文件,里面包含了很多有用的配置选项,了解之后能使自己的博客更加定制化。同时默认的主题大家肯定也不会都喜欢,这个时候就需要更换主题。这一篇就带大家认识这两部分。

作者:Icarus 原文链接:hexo 配置文件初识及主题更换

配置文件 _config.yml

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

# Site #博客的基本信息
title: 自留地 #博客标题
subtitle: #博客副标题
description: 前端|伪文青|工科男 #博客描述,部分主题会用来生成简介
author: 卢睿韬 #博客作者
language: zh-Hans #语言
timezone:

# URL
## If your site is put in a subdirectory, set url as 'https://yoursite.com/child' and root as '/child/'
url: https://yoursite.com #你自己的域名
root: / #根目录位置,如果只是github pages的子目录需要更改
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: true
  tab_replace:

# 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
## https://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: 3
pagination_dir: page

# Extensions #拓展
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: next #主题更换

# Deployment #部署参数
## Docs: https://hexo.io/docs/deployment.html
deploy:
  type: git
  repo: https://github.com/xdlrt/xdlrt.github.io.git
  branch: master

index_generator:
  per_page: 3 ##首頁默认10篇文章标题 如果值为0不分页

archive_generator:
  per_page: 10 ##归档页面默认10篇文章标题
  yearly: true  ##生成年视图
  monthly: true ##生成月视图

tag_generator:
  per_page: 10 ##标签分类页面默认10篇文章

category_generator:
   per_page: 10 ###分类页面默认10篇文章

以上就是配置文件的基础设置。

更换主题 NexT

Hexo 安装主题的方式非常简单,只需要将主题文件放置于站点目录的 themes 下,然后修改下配置文件即可。这里我以 NexT 主题为例。 在 git CMD 操作下 cd 至博客根目录,执行如下代码:

$ git clone https://github.com/iissnan/hexo-theme-next themes/next

等待下载完成后,修改根目录下_config.yml 文件的 theme 字段为 next 即可启用 NexT 主题,十分简单便捷。 Schemes 目前共有三种:Muse Mist Pisces,三种都很简洁清新,我使用的是 Pisecs。 其它具体设置可参照NexT 官方文档