您的位置:首页 > 编程语言

手把手教从零开始在GitHub上使用Hexo搭建博客教程(二)-Hexo参数设置

2016-06-03 17:32 656 查看


前言

前文手把手教从零开始在GitHub上使用Hexo搭建博客教程(一)-附GitHub注册及配置介绍了github注册、git相关设置以及hexo基本操作。

本文主要介绍一下hexo的常用参数设置。

配置文件说明

网站配置文件是在根目录下的**_config.yml文件,是yaml格式的。

所有的配置项后面的冒号(:)与值之间要有一个空格。**

官方配置文件说明

# Hexo Configuration
## Docs: https://hexo.io/docs/configuration.html ## Source: https://github.com/hexojs/hexo/ 
# Site 网站信息
title: 网站标题
subtitle: 网站副标题
description: 网站描述
author: 网站作者名字
language: #网站语言,默认是英语(en)
timezone: #网站时区

# URL 网站设置
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: seayxu.github.io #网站的地址
root: / #网站的根目录,如果是子文件夹下,则填写子文件夹路径
permalink: :year/:month/:day/:title/ #文章链接地址格式
permalink_defaults:

# Directory 目录设置
source_dir: source #资源文件夹,默认是source
public_dir: public #公共文件夹,默认是public
tag_dir: tags #标签文件夹,默认是tags
archive_dir: archives #档案文件夹,默认是archives
category_dir: categories #分类文件夹,默认是categories
code_dir: downloads/code #代码文件夹,默认是downloads/code
i18n_dir: :lang #国际化文件夹,默认跟language相同
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:

# 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 #每页显示数量,设置为0表示不启用分页
pagination_dir: page #分页文件夹名称

# Extensions 扩展
## Plugins: https://hexo.io/plugins/ #插件
plugins:
hexo-generator-feed #RSS订阅插件
hexo-generator-sitemap  #sitemap插件

## Themes: https://hexo.io/themes/ #主题
theme: landscape #主体名称

# Deployment 部署
## Docs: https://hexo.io/docs/deployment.html deploy:
type: git
repo: git@github.com:SeayXu/seayxu.github.io.git #github仓库地址
branch: master # github分支

常用插件

如果是扩展插件,要在**_config.yml配置文件中添加插件信息,是plugins**配置项。

比如下面的两个插件:

plugins:
hexo-generator-feed #RSS订阅插件
hexo-generator-sitemap  #sitemap插件

然后,安装插件,后面要加上
--save
,表示依赖项。

RSS订阅插件

hexo-generator-feed:生成rss订阅文件

npm install hexo-generator-feed --save

添加配置信息

#sitemap
sitemap:
path: sitemap.xml


SiteMap插件

hexo-generator-sitemap:生成易于搜索引擎搜素的网站地图

npm install hexo-generator-sitemap --save

添加配置信息:

#feed
atom:
type: atom
path: atom.xml
limit: 20


可以在主题配置文件中添加相关配置,可以在页面上显示。

比如,添加链接信息

links:
Feed: /atom.xml
SiteMap: /sitemap.xml


Git插件

hexo-deployer-git:使用git同步代码到git仓库中

npm install hexo-deployer-git --save


内置插件

在Hexo 3.0中以下插件是内置的:

hexo-generator-archive
hexo-generator-category
hexo-generator-index
hexo-generator-tag
hexo-renderer-ejs
hexo-renderer-marked
hexo-renderer-stylus

hexo-server

更多插件可以查阅官方插件页

主题

默认的主题是landscape

如果不喜欢,可以在网上找到自己喜欢的主题,作为自己的主题使用。

官方主题地址:传送门

比如我目前使用的是基于jacman修改的。

切换主题

将找到的主题源码下载到themes文件夹中;

比如,jacman主题在github上,通过克隆到themes中:

git clone https://github.com/wuchong/jacman themes/jacman


在配置**_config.yml**文件中修改主题配置,比如修改
theme: landscape
theme: jacman


修改主题配置文件**_config.yml**,此配置文件在主题文件夹下面。

相关的配置信息可根据主题文档进行配置。

原文:手把手教从零开始在GitHub上使用Hexo搭建博客教程(二)-Hexo参数设置
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: