hexo+Next主题优化

616 阅读3分钟

1.next主题风格

next自带4种主题可选,找到主题配置文件如:E:\blog\themes\next 中的_config.yml文件打开,ctrl+f搜索 scheme 关键字,选用主题只需要删掉前面的#,其他不用的记得加上#。

主题设置.png

2.设置语言

打开根目录下如:E:\blog 中的_config.yml文件,搜索 language 关键字,改为language: zh-CN,其他语言可去文档中查看。

语言设置.png

3.添加菜单栏中的内容

菜单栏选项.png

打开主题配置文件_config.yml 搜索关键字menu,需要用到的删除#解开

修改菜单栏.png

4.设置侧边栏在左还是右

打开主题配置文件_config.yml 搜索关键字sidebar ,需要用到的删除#解开

菜单栏左右.png

5.设置头像

将头像图片放置在E:\GitHub\blog\themes\next\source\images 打开主题配置文件_config.yml 搜索关键字avatar,url的值设置为头像图片保存的路径 url: /images/avatar.gif

头像.png

如果想将头像改为圆形,将rotated: false 改为 rotated: true 需要旋转的话rounded也改为true

6.文章末尾添加版权信息

文章版权信息.png

打开主题配置文件,搜索关键字 creative_commons 将sidebar和post改为true

版权信息修改.png

7.添加背景动画

背景动画.png

打开主题配置文件,搜索关键字 Canvas-nest 将false改为true

背景.png

8.添加看板娘

看板娘.png

用git bash在站点根目录执行如下代码:

$ npm install hexo-helper-live2d --save

打开文件/themes/next/layout/_layout.swig,将下面代码放到之前

{{ live2d() }}

最后在站点配置文件末尾添加代码

live2d:
  model: hijiki
  position: left
  bottom: -30
  mobileShow: false  #手机端不显示

具体配置看官方 传送门

9.返回顶部按钮

返回顶部.png

打开主题配置文件,搜索关键字 back2top

返回顶部.png

enable:用于设置是否开启回到顶部按钮 sidebar:用于设置是否将按钮放到侧边栏中 scrollpercent:用于设置是否显示阅读进度百分比

10.顶部阅读进度条

在博文页面顶部添加Reading Progress进度条,表示阅读进度

安装

切换到Next主题文件夹

cd themes/next

安装模块到source/lib文件夹

git clone https://github.com/theme-next/theme-next-reading-progress source/lib/reading_progress

打开Next主题路径下的配置文件_config.yml,搜索reading_progress定位到如下代码并将enable:设置为true

# Reading progress bar
# Dependencies: https://github.com/theme-next/theme-next-reading-progress
reading_progress:
  enable: true
  color: "#ffc0cb" # 调整线条颜色
  height: 2px # 调整线条高度

11.页面搜索功能

根目录下执行下列命令安装插件

npm install hexo-generator-searchdb --save

配置

打开Next主题的配置文件_config.yml并搜索local_search,修改为

# Local search
# Dependencies: https://github.com/theme-next/hexo-generator-searchdb
local_search:
  enable: true
  # 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

12.页面背景图

将选好的背景图片放在博客根目录/themes/next/source/images中 打开根目录/themes/next/source/css/_custom中的custom.styl文件

  1. 添加如下代码
body {
    background:url(/images/background.jpg);//图片路径
    background-repeat: no-repeat;//是否重复平铺
    background-attachment:fixed;//是否随着网页上下滚动而滚动,fixed为固定
    background-position:50% 50%;//图片位置
    background-size: cover;//图片展示大小
    -webkit-background-size: cover;
    -o-background-size: cover;
    -moz-background-size: cover;
    -ms-background-size: cover;

     #footer > div > div {
        color:#000000;//底部文字颜色
    }
}

.header-inner {
    background: #ffffffe8;//设置侧边栏透明
    opacity: 1;//这里设置为1,否则搜索栏会消失
}
.main-inner {
        background: #fff;
        opacity: 0.9;//设置文章主体透明度
}

透明度不要调太低,影响阅读

13.访客统计

Next主题已经内置了不蒜子统计,在Next主题的配置文件_config.yml中搜索busuanzi_count并将enable设置为trueicon可以自定义设置

# Show Views / Visitors of the website / page with busuanzi.
# Get more information on http://ibruce.info/2015/04/04/busuanzi
busuanzi_count:
  enable: true
  total_visitors: true # 总访客数量,在页脚显示
  total_visitors_icon: user
  total_views: true # 总阅读数量,在页脚显示
  total_views_icon: eye
  post_views: true # 单篇文章阅读数量,在标题下显示
  post_views_icon: eye

GitHub博客