Hexo 及 NexT 基本配置与使用

前一篇文章介绍了如何搭建博客,可是没有介绍如何使用和个性化配置博客。所以这篇文章主要来介绍Hexo的主题及其配置以及如何来写本身的博客。html

主题下载与应用

Hexo提供各类各样的主题,咱们能够进入官网去选择本身喜欢的主题,而后在GitHub上有其具体的介绍。git

接下来咱们以NexT主题为例进行介绍。github

截至目前为止,NexT主题已经从v5.1.x更新至v6.6.0,仓库也从原来的老仓库迁移到这里。所以NexT主题的不少配置都和之前不同了,我当时在网上看的时候全是老版本的配置方法,花费了很多时间。最后发现其实能够本身看着themes下的_config.yml进行配置,不少插件都在theme-next这个仓库有。浏览器

下载 NexT

切换到主目录,而后克隆整个仓库到themes/nextbash

cd hexo
    git clone https://github.com/theme-next/hexo-theme-next themes/next
复制代码

以后咱们会发现 themes下多了个next文件夹,即咱们的主题文件夹。hexo

配置

整个 Hexo 博客有两个主要的配置文件,第一个是主目录下的_config.yml,另外一个是咱们的主题配置文件,是thems/next/_config.ymlpost

如今咱们开始将咱们下载的主题应用到咱们的博客中,咱们只需修改主目录下的_config.yml,以下:网站

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

theme: next
复制代码

而后hexo s启动博客便可。 须要注意的是:每当咱们修改了主目录下的_config.yml,只有重启博客服务才能生效;而修改thems/next/_config.yml是不须要重启博客服务的。ui

一样咱们能够在主目录下的_config.yml进行其余设置,咱们能够看到里面有网站基本设置,以下:url

title: Hexo           
subtitle:
description:
keywords:
author: John Doe
language:
timezone:
复制代码
参数 描述
title 网站标题
subtitle 网站副标题
description 网站描述
author 做者名字
language 网站语言,NexT v6.0.3之后中文设为 zh-CN

具体所有配置参考官方文档

咱们暂时不须要所有理解其意思,只要把网站的基本描述改成你本身的就好。

主题设定

选择 Scheme

Scheme 的切换经过更改主题配置文件,打开thems/next/_config.yml,搜索 scheme 关键字。 你会看到有三行 scheme 的配置,将你需用启用的 scheme 前面注释 # 去除便可。

# Schemes
scheme: Muse
#scheme: Mist
#scheme: Pisces
#scheme: Gemini
复制代码

Scheme 是 NexT 提供的一种特性,借助于 Scheme,NexT 为你提供多种不一样的外观。同时,几乎全部的配置均可以 在 Scheme 之间共用。
Muse - 默认 Scheme,这是 NexT 最初的版本,黑白主调,大量留白
Mist - Muse 的紧凑版本,整洁有序的单栏外观
Pisces - 双栏 Scheme,小家碧玉似的清新

选择对应的外观,刷新浏览器便可预览。

设置菜单

打开thems/next/_config.yml,找到以下代码

menu:
  home: / || home
  #about: /about/ || user
  #tags: /tags/ || tags
  #categories: /categories/ || th
  archives: /archives/ || archive
  #schedule: /schedule/ || calendar
  #sitemap: /sitemap.xml || sitemap
  #commonweal: /404/ || heartbeat
复制代码

这里是进行菜单配置,去掉哪一个注释,就会多一个相应的菜单选项。

当须要abouttagscategories 须要手动建立这个页面,若是不建立点击则不会出现相应页面。

使用以下命令建立这些文件夹

hexo new page "about"
hexo new page "tags"
hexo new page "categories"
复制代码

以后source文件夹下就会出现三个这样的文件夹。

设置头像

打开thems/next/_config.yml,找到以下代码

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.gif
  # If true, the avatar would be dispalyed in circle.
  rounded: false
  # 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: false
复制代码

修改字段 avatar, 值设置成头像的连接地址,参考这个连接

以上主题设置能够参考Next文档

tags 和 categories 设置

当菜单中有了 tagscategories 时,咱们须要在 Front-matter 中添加 type 属性。所谓 Front-matter 是文件最上方以 --- 分隔的区域,用于指定个别文件的变量。

tags/index.md

---
title: 标签
date: 2018-12-05 10:00:29
type: "tags"
---

复制代码

categories/index.md 同理。

只有这样当咱们新建一篇博客时,指定的tagscategories才会同步,hexo才会识别出来你的 tagscategories。因此接下来咱们看如何新建一篇博客。

新建博客

新建博客很简单,使用以下命令

hexo new "文章题目"
复制代码

这样就会在source目录下自动建立一个名为 文章题目.md 的文件,咱们只要在这个文件上写文章就好了。一样咱们须要每篇文章指定一个或多个 tags 和 一个 categories。这样你的菜单中tags 页面 和categories页面就会有内容了。

---
title: 文章题目
date: 2018-12-05 15:42:22
tags:
- PS3
- Games
categories:
- Diary
---

复制代码

这样整个 NexT 基本配置就结束了,以后将会介绍一些 更高级的配置

相关文章
相关标签/搜索