使用Hexo开源博客系统,轻松搭建你的个人博客(2)- 配置篇

时间:2022-04-19 09:04:39

上一章节,我们介绍了Hexo的基础搭建,搭建完大家一定发现,是英文版本的,并且页面有点丑陋。这一章节,就来跟大家介绍Hexo的配置和主题的设置。

站点信息

上一章有跟大家提到过_config.yml这个文件,这个我们先称之为站点全局的配置文件,后续我们说到主题的时候,也会有一个这样的文件,暂时称它主题配置文件。

我们先来看一下全局配置文件主要有哪些内容:

# 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: # 网站url设置
root: # 网站根目录链接
permalink: :year/:month/:title.html # 文章链接,默认是按照 /年/月/日/文章标题 设置的链接
permalink_defaults: # 默认链接形式
......
# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: #主题

这些可根据需要设置,其余默认即可,git配置和站点地图配置后续用到再介绍。

信息配置完记得执行hexo g && hexo s,刷新浏览器查看效果。

安装Next主题

主题大家可以在官网下载(https://hexo.io/themes)也可以到GitHub搜索,我推荐使用Next主题,该主题几乎占领了Hexo博客的半壁*。

Next主题下载地址:https://github.com/theme-next/hexo-theme-next.git

这边介绍的版本是Next6,在Next6版本上其实增加了很多Next5需要手动配置的东西,并且Next5已经停止维护了,所以建议使用Next6版本。

下载Next主题

两种方式:

1.使用git clone命令将Next仓库克隆到hexo目录下的themes/next,需要在根目录下执行,命令为:git clone https://github.com/theme-next/hexo-theme-next.git themes/next

2.直接在Github页面上选择绿色的按钮Clone or Download下载压缩包,然后解压到themes目录下,名字可自行修改。

设置为Next主题

打开全局配置文件_config.yml,找到theme,设置如下:

# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: hexo-theme-next #此处填入你在themes目录下的next主题目录名

测试Next主题

在Git Bash中执行如下命令:

hexo clean && hexo g && hexo s

命令执行完成后在浏览器中输入http://localhost:4000即可查看安装好的Next主题。

配置Next主题

在主题目录下面,也有一个_config.yml的配置文件,我们就叫它主题配置文件,下面我们开始配置。

网站图标设置

打开_config.yml,找到favicon的位置,如下所示:

favicon:
small: /images/favicon-16x16-next.png
medium: /images/favicon-32x32-next.png
apple_touch_icon: /images/apple-touch-icon-next.png
safari_pinned_tab: /images/logo.svg
#android_manifest: /images/manifest.json
#ms_browserconfig: /images/browserconfig.xml

将图片放到你的next主题下面的source/images目录下面,然后在主题配置文件中设置即可。

关闭底部由hexo强力驱动

在footer中,将powered和theme下的属性全部设置为false

footer:
...
powered:
# Hexo link (Powered by Hexo).
enable: false
# Version info of Hexo after Hexo link (vX.X.X).
version: false theme:
# Theme & scheme info link (Theme - NexT.scheme).
enable: false
# Version info of NexT after scheme info (vX.X.X).
version: false

菜单栏设置

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 # Enable / Disable menu icons / item badges.
menu_settings:
enable: true #表示是否显示菜单图标icons
badges: false # 显示每个菜单下面有多少个内容

||后面是fontawesome中的图标名称,如果想要修改图标,可以去FontAwesome官网找自己喜欢的图标样式。

主题风格设置

# Schemes
#scheme: Muse
#scheme: Mist
#scheme: Pisces
scheme: Gemini

默认是Muse,我是使用Gemini,大家可以每个都试看看,看喜欢哪个。

社交链接设置

social:
GitHub: https://github.com/codernice || github
#E-Mail: mailto:yourname@gmail.com || envelope
#Weibo: https://weibo.com/yourname || weibo
#Google: https://plus.google.com/yourname || google
#Twitter: https://twitter.com/yourname || twitter
#FB Page: https://www.facebook.com/yourname || facebook
#VK Group: https://vk.com/yourname || vk
#*: https://*.com/yourname || stack-overflow
#YouTube: https://youtube.com/yourname || youtube
#Instagram: https://instagram.com/yourname || instagram
#Skype: skype:yourname?call|chat || skype

yourname改成你自己在对应网站的ID,前面的#注释去掉即可。

友情链接设置

# Blog rolls
links_icon: link
links_title: Links
links_layout: block
#links_layout: inline
links:
#Title: http://example.com

#Title: http://example.com换成对于网站名称和链接即可

开启阅读更多按钮

auto_excerpt:
enable: true
length: 150

默认是false,首页上会显示整篇文章,设置为true开启阅读更多按钮。

文章元数据设置

post_meta:
item_text: true
created_at: true
updated_at:
enable: false
another_day: true
categories: true

显示在home页的文章创建于、更新于、阅读次数之类的数据

文章字数统计设置

# Post wordcount display settings
# Dependencies: https://github.com/theme-next/hexo-symbols-count-time
symbols_count_time:
separated_meta: true
item_text_post: true
item_text_total: false
awl: 4
wpm: 275

该设置必须要添加hexo-symbols-count-time模块依赖,在hexo站点根目录下使用npm install hexo-symbols-count-time --save命令安装模块。

侧边栏头像设置

# Sidebar Avatar
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: 你的头像地址
# If true, the avatar would be dispalyed in circle.
rounded: true # 设置头像是否为圆形
# The value of opacity should be choose from 0 to 1 to set the opacity of the avatar.
opacity: 1 # 设置不透明度,1为完全不透明,0为完全透明
# If true, the avatar would be rotated with the cursor.
rotated: true # 设置鼠标放到头像上是否旋转

代码块设置

codeblock:
# Manual define the border radius in codeblock, leave it blank for the default value: 1
border_radius: 7 # 按钮圆滑度
# Add copy button on codeblock
copy_button:
enable: true # 设置是否开启代码块复制按钮
# Show text copy result
show_result: true # 是否显示复制成功信息

开启文章打赏按钮

# Reward (Donate)
reward_settings:
# If true, reward would be displayed in every article by default.
# You can show or hide reward in a specific article throuth `reward: true | false` in Front Matter.
enable: true #开启打赏功能
animation: false
#comment: Donate comment here reward:
wechatpay: # 微信收款图片地址
alipay: # 支付宝收款图片地址
#bitcoin: /images/bitcoin.png

开启相关文章推荐功能

related_posts:
enable: true #开启
title: # custom header, leave empty to use the default one
display_in_home: false #显示在首页
params:
maxCount: 5
#PPMixingRate: 0.0
#isDate: false
#isImage: false
#isExcerpt: false

需要安装hexo-related-popular-posts模块,在hexo站点根目录下执行npm install hexo-related-popular-posts --save安装模块。

代码块风格设置

# Code Highlight theme
# Available values: normal | night | night eighties | night blue | night bright
# https://github.com/chriskempson/tomorrow-theme
highlight_theme: normal

有normal 、night 、 night eighties 、 night blue 、night bright这几种风格,大家可以都试看看。

添加valine评论系统

# Valine
# You can get your appid and appkey from https://leancloud.cn
# More info available at https://valine.js.org
valine:
enable: true # 开启valine评论
appid: # your leancloud application appid
appkey: # your leancloud application appkey
notify: false # mail notifier, See: https://github.com/xCss/Valine/wiki
verify: false # Verification code
placeholder: # comment box placeholder
avatar: monsterid # gravatar style
guest_info: nick,mail,link # custom comment header
pageSize: 10 # pagination size
language: # language, available values: en, zh-cn
visitor: false # leancloud-counter-security is not supported for now. When visitor is set to be true, appid and appkey are recommended to be the same as leancloud_visitors' for counter compatibility. Article reading statistic https://valine.js.org/visitor.html
comment_count: true # if false, comment count will only be displayed in post page, not in home page

valine是第三方插件,需要到https://leancloud.cn注册账号,获取到appid和appkey后放到这里即可。avatar是设置默认头像,可以到https://valine.js.org/avatar选择默认头像,然后在这里设置名字即可。

开启百度分享

# Baidu Share
# Available values: button | slide
# Warning: Baidu Share does not support https.
baidushare:
type: button # 设置分享按钮的风格,有button何slide形式

开启needmoreshare分享

needmoreshare2:
enable: false
postbottom:
enable: false
options:
iconStyle: box
boxForm: horizontal
position: bottomCenter
networks: Weibo,Wechat,Douban,QQZone,Twitter,Facebook
float:
enable: false
options:
iconStyle: box
boxForm: horizontal
position: middleRight
networks: Weibo,Wechat,Douban,QQZone,Twitter,Facebook

needmoreshare2依赖theme-next-needmoreshare2模块,要开启的朋友可以到https://github.com/theme-next/theme-next-needmoreshare2找到方法。

设置文章阅读量

leancloud_visitors:
enable: true
app_id:
app_key:
# Dependencies: https://github.com/theme-next/hexo-leancloud-counter-security
# If you don't care about security in leancloud counter and just want to use it directly
# (without hexo-leancloud-counter-security plugin), set `security` to `false`.
security: false
betterPerformance: true

appid和appkey跟上面开启valine评论使用的leanCloud是一样的。如果发现文章阅读量不显示,可以到leanCloud后台的存储菜单下,创建Class,命名为Counter.

开启不蒜子统计功能

busuanzi_count:
enable: true
total_visitors: true #开启总访客(uv)
total_visitors_icon: user
total_views: true #开启总访问数(pv)
total_views_icon: eye
post_views: false
post_views_icon: eye

这边的post_views和上面的leanCloud_visitors冲突,两者都是显示文章阅读量,只开启一个就可以了。

开启本地博客搜索功能

local_search:
enable: false
# If auto, trigger search by changing input.
# If manual, trigger search by pressing enter key or search button.
trigger: auto
# Show top n results per article, show all results by setting to -1
top_n_per_article: 1
# Unescape html strings to the readable one.
unescape: false

该功能依赖hexo-generator-searchdb插件,使用命令npm install hexo-generator-searchdb --save来进行安装,然后在全局配置文件的末尾,加入以下代码即可。

search:
path: search.xml
field: post
format: html
limit: 10000

总结

以上就是hexo博客常用的基本配置以及基于Next主题的一些设置,更多功能大家可在使用中逐摸索,欢迎讨论交流。

需要安装的模块依赖

1.字数统计:npm install hexo-symbols-count-time --save

2.相关文章推荐:npm install hexo-related-popular-posts --save

3.本地博客搜索功能:npm install hexo-generator-searchdb --save,然后在全局配置文件末尾加入代码

第三方插件

1.valine评论系统:需要到https://leancloud.cn注册账号,获取到appid和appkey

2.文章阅读量:同样需要用到leancloud的appid和appkey

使用Hexo开源博客系统,轻松搭建你的个人博客(2)- 配置篇的更多相关文章

  1. 开源入侵检测系统OSSEC搭建之二:客户端安装

    上一篇文章中已经将OSSEC服务端的安装以及客户端的Key导出操作做了解说,接下来在另一台虚拟机中安装客户端,与安装服务端类似同样需要安装ossec,步骤如下. 一.下载ossec-hids-2.8. ...

  2. 开源入侵检测系统OSSEC搭建之一:服务端安装

    OSSEC是一款开源的多平台的入侵检测系统,可以运行于Windows, Linux, OpenBSD/FreeBSD, 以及 MacOS等操作系统中.主要功能有日志分析.完整性检查.rootkit检测 ...

  3. 使用Hugo,只需5分钟,轻松搭建一个自己的博客

    前面跟大家介绍过hexo这款静态博客系统,功能强大,基本能满足博客的各种需求.今天,我再跟大家介绍一款优秀的静态博客系统,那就是Hugo. Hugo是由Go语言实现的静态网站生成器.简单.易用.高效. ...

  4. 使用Hexo开源博客系统,轻松搭建你的个人博客(1)

    Hexo 是一个轻量级.简洁.高效且高逼格的博客框架.Hexo 使用 Markdown(或其他渲染引擎)解析文章,在几秒内,即可利用靓丽的主题生成静态网页.同时有着丰富的主题,官网或者GitHub都可 ...

  5. Node.js的开源博客系统Ghost搭建教程

    准备工作 Node.js版本:0.10.x.0.12.x.4.2.x.安装步骤可参考:Node.js环境搭建 Ghost版本:0.7.4:中文集成版(33.6M),中文标准版(3.39M),英文原版( ...

  6. Linux博客系统服务器搭建

    linux(CentOS)服务器搭建 前言 拿到购买的服务器信息后,会给出一个服务器的账号的密码,看你自己设置,账号一般为root. 拿到后,可在阿里云官网登录进入服务器.然后就可以进行一下的流程从而 ...

  7. 开源入侵检测系统OSSEC搭建之三:Web界面安装

    注意:以下操作需在OSSEC服务端进行设置 一.下载analogi,存放于/var/www/html/下并赋予权限 [root@localhost ~]# wget https://github.co ...

  8. Docker+SpringBoot+Mybatis+thymeleaf的Java博客系统开源啦

    个人博客 对于技术人员来说,拥有自己的个人博客应该是一件令人向往的事情,可以记录和分享自己的观点,想到这件事就觉得有意思,但是刚开始写博客的时候脑海中是没有搭建个人博客这一想法的,因为刚起步的时候连我 ...

  9. 从零开始搭建solo个人博客系统

    目录 1.博客系统的搭建流程 2.服务器选购 2.1阿里云学生主机 2.2普通云主机 3.域名购买与备案(可选) 3.1域名购买 3.2域名服务器备案 3.3域名服务器解析 4.solo安装 4.1 ...

随机推荐

  1. Ambari自动化卸载shell脚本

    #!/bin/bash # Program: # uninstall ambari automatic # History: # 2014/01/13 - Ivan - 2862099249@qq.c ...

  2. org.dom4j.DocumentException : 1 字节的 UTF-8 序列的字节 1 无效。 Nested exception: 1 字节的 UTF-8 序列的字节 1 无效。

    org.dom4j.DocumentException : 1 字节的 UTF-8 序列的字节 1 无效. Nested exception: 1 字节的 UTF-8 序列的字节 1 无效. 网上查了 ...

  3. DLUTOJ #1394 Magic Questions

    传送门 Time Limit: 3 Sec  Memory Limit: 128 MB Description Alice likes playing games. So she will take ...

  4. Java API —— Date类

    1.Date类概述 类 Date 表示特定的瞬间,精确到毫秒.  2.构造方法 public Date():分配 Date 对象并初始化此对象,以表示分配它的时间(精确到毫秒). public Dat ...

  5. Widget only supports Widgets as children

    Widget only supports Widgets as children https://www.baidu.com/s?wd=Widget%20only%20supports%20Widge ...

  6. SQL练习之不反复执行相同的计算

    下面是Demo所需要的代码: CREATE TABLE Fee ( Income ,), overhead ,) ) ,) ,) ,) ,) ,) ,) 现在有一个报表系统,需要根据Fee表获得以下数 ...

  7. get和post提交数据的区别

    get是客户端向服务器索取数据的请求,设定的初衷是,客户端(浏览器)给服务器发送请求,然后服务器再返回给客户端其要求的数据. 那么为什么说get也能提交数据呢? 我们仔细理解第一句话“客户端(浏览器) ...

  8. Caused by: org.h2.jdbc.JdbcSQLException: Table "T_STUDENT_INFO" not found; SQL statement

    1.错误描述 org.hibernate.exception.SQLGrammarException: error executing work at org.hibernate.exception. ...

  9. 详解EBS接口开发之供应商导入(补充)--错误信息处理

    check reject details on records of AP_SUPPLIER_INT SELECT s.parent_table,s.reject_lookup_code,S.LAST ...

  10. DDGScreenShot--iOS 图片处理--多图片拼接 (swift)

    写在前面 最近总结了关于图片处理相关的内容,之前在二三四五工作的时候,也做过关于这方面的分享,图片的处理内容很多,会分很多模块来讲解. 今天简单讲多图片的拼接. 上代码 func composeIma ...