手把手教從零開始在GitHub上使用Hexo搭建博客教程(二)-Hexo參數設置

手把手教GitHub+Hexo博客搭建教程(二)

前言

前文手把手教從零開始在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: [email protected]: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修改的。

切換主題

  1. 將找到的主題源碼下載到themes文件夾中;
    比如,jacman主題在github上,通過克隆到themes中:

    git clone https://github.com/wuchong/jacman themes/jacman
  2. 在配置**_config.yml**文件中修改主題配置,比如修改theme: landscapetheme: jacman
  3. 修改主題配置文件**_config.yml**,此配置文件在主題文件夾下面。
    相關的配置信息可根據主題文檔進行配置。

原文:手把手教從零開始在GitHub上使用Hexo搭建博客教程(二)-Hexo參數設置

發佈了51 篇原創文章 · 獲贊 2 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章