lbp的blog

纸上得来终觉浅,绝知此事要躬行

0%

hexo使用

hexo基本使用,next(7.8.0)主题配置。各种使用技巧,常用问题

基本命令

1
2
3
4
hexo new draft ab.md #创建草稿
hexo new draft /dir/ab.md #创建带路径草稿
hexo publish ** #发布草稿文章
hexo server --draft #显示草稿

next 安装

  • clone 到本地
    1
    git clone https://github.com/theme-next/hexo-theme-next themes/next
  • 在站点 _config.yml 中配置
    1
    theme: next

图片

插入图片

  1. 安装插件 npm install https://github.com/7ym0n/hexo-asset-image --save
  2. 更改配置 post_asset_folder: true

完成以上两步之后, 执行 hexo new example 在生成 example.md 文件时,会生成同名文件夹 example, 在文章中直接使用md语法插入图片即可

示例图片

package

图片名称

如果在next主题中想要看到图片底部的标题, 可以设置 fancybox: true

1
2
3
# FancyBox is a tool that offers a nice and elegant way to add zooming functionality for images.
# For more information: https://fancyapps.com/fancybox
fancybox: ture

站点标签/分类

给站点配置 分类标签 的操作相同

  1. 执行 hexo new page categories/tags
  2. 步骤1 生成的 md 文件添加 type: categories/tags
  3. 修改主题文件中的 menu 配置
  4. 在文章页头中配置 categories/ tags

可以直接修改 scaffolds 中的模板,方便创建文章后添加标签

在给文章添加多个分类时,参考 分类和标签

首页展示摘要

next 7.6.0 中移除了 auto_excerpt , 可以在文章中插入 <!-- more --> 来精确控制摘要

阅读次数统计

1
2
3
4
5
6
7
8
busuanzi_count:
enable: true # 设true 开启
total_visitors: true # 总阅读人数(uv数)
total_visitors_icon: user # 阅读总人数的图标
total_views: true # 总阅读次数(pv数)
total_views_icon: eye # 阅读总次数的图标
post_views: true # 开启内容阅读次数
post_views_icon: eye # 内容页阅读数的图标

阅读次数统计

添加gitalk评论

Gitalk 是一个基于 GitHub Issue 和 Preact 开发的评论插件。配置起来相对简单

  • 创建一个用来存放评论的代码库
  • 创建一个 GitHub Application
  • 在主题中配置 gitalk

Gitalk评论样式

代码块样式设置

在主题 _config.yml 中修改如下配置

1
2
3
4
5
6
7
8
9
10
11
12
codeblock:
# Code Highlight theme
# Available values: normal | night | night eighties | night blue | night bright | solarized | solarized dark | galactic
# See: https://github.com/chriskempson/tomorrow-theme
highlight_theme: night
# Add copy button on codeblock
copy_button:
enable: true
# Show text copy result.
show_result: true
# Available values: default | flat | mac
style: mac

嵌入codepen代码

点击 codepen 右下角的 embed 按钮,把生成的代码,复制到 md 文件中即可

按照更新时间排序

如下所示, order_by 配置为 -updated
默认为 -date 是按照创建时间进行排序

1
2
3
4
index_generator:
path: ''
per_page: 10
order_by: -updated

hexo当前文章中使用锚点

可以直接使用#标题作为锚点,如下:

1
2
// 锚点名称区分大小写
[显示名称](#标题)

hexo中引用自身文章

隐藏文章

安装插件 npm install hexo-hide-posts --save

插件配置如下

1
2
3
4
5
6
7
8
9
10
# hexo-hide-posts
hide_posts:
# 可以改成其他你喜欢的名字
filter: hidden
# 指定你想要传递隐藏文章的位置,比如让所有隐藏文章在存档页面可见
# 常见的位置有:index, tag, category, archive, sitemap, feed, etc.
# 留空则默认全部隐藏
public_generators: []
# 为隐藏的文章添加 noindex meta 标签,阻止搜索引擎收录
noindex: true

参考

Hexo-NexT (v7.0+) 主题配置
hexo-theme-next
hexo-plugins