使用Charts插件给Butterfly增加统计图表
参考:
https://blog.guole.fun/posts/18158/index.html
一. 安装
1 2
| npm i hexo-butterfly-charts --save
|
在主题配置文件_config.butterfly.yml 或 hexo 配置文件_config.yml 中增加以下内容:
| 参数 |
默认值 |
释义 |
| enable |
无 |
【必填】开启或关闭,true or false |
| postsChart.Title |
空 |
发布统计的标题 |
| postsChart.interval |
0 |
坐标轴值得间隔数。0 表示强制显示所有;可填写 0 以上的正整数,如 1 就是横坐标间隔 1 个再展示 |
| postsCalendar_Title |
空 |
发布日历的标题 |
| tagsChart.Title |
空 |
标签统计的标题 |
| tagsChart.interval |
0 |
坐标轴值得间隔数。0 表示强制显示所有;可填写 0 以上的正整数,如 1 就是横坐标间隔 1 个再展示 |
| categoriesChart_Title |
空 |
分类统计的标题 |
| categoriesRadar_Title |
空 |
分类雷达的标题 |
| echarts_CDN |
baomitu 资源 |
echarts 自定义 CDN |
_config.butterfly.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
charts: enable: true postsChart: title: 文章发布统计 interval: 1 tagsChart: title: Top 10 标签统计 interval: 1 postsCalendar_Title: 文章发布统计 categoriesChart_Title: 分类统计 categoriesRadar_Title: 分类雷达 echarts_CDN:
|
二. 使用
1. 将发布日历添加到 归档 页面
- 安装插件后,在
/Butterfly/layout/archive.pug 文件中,#archive 下面添加一行#posts-calendar.js-pjax, 新添加的比上一行多缩进两个空格。
1 2 3 4 5 6 7 8 9
| extends includes/layout.pug
block content include ./includes/mixins/article-sort.pug .article-sort-title= _p('page.articles') + ' - ' + site.posts.length +articleSort(page.posts) include includes/pagination.pug
|

其他页面,只需 md 文件中插入这个标签:
1
| <div id="posts-calendar" class="js-pjax"></div>
|
2. 将 发布统计 添加到 归档 页面
- 安装插件后,在
/Butterfly/layout/archive.pug 文件中,#archive 下面添加一行#posts-chart.js-pjax, 新添加的比上一行多缩进两个空格。
1 2 3 4 5 6 7 8 9
| extends includes/layout.pug
block content include ./includes/mixins/article-sort.pug .article-sort-title= _p('page.articles') + ' - ' + site.posts.length +articleSort(page.posts) include includes/pagination.pug
|

其他页面,只需 md 文件中插入这个标签:
1
| <div id="posts-chart" class="js-pjax"></div>
|
3. 将 标签统计 插入到 标签 页面
- 编辑主题目录
/Butterfly/layout/includes/page/tags.pug 文件,在开头添加一行#tags-chart(data-length = "10").js-pjax,data-length = "10" 表示显示 Top 10
1 2 3 4 5 6
| .tag-cloud-title.is-center= _p('page.tag') | - span.tag-cloud-amount= site.tags.length .tag-cloud-list.is-center !=cloudTags({source: site.tags, minfontsize: 1.2, maxfontsize: 2.1, limit: 0, unit: 'em'})
|


其他页面,只需 md 文件中插入这个标签:
1 2
| <!-- "data-length" = how many tags to show, default 10 --> <div id="tags-chart" data-length="10" class="js-pjax"></div>
|
4. 将 分类统计(无标题)和 分类雷达图(无标题) 添加到 分类 页面。
- 编辑主题目录
/Butterfly/layout/includes/page/categories.pug 文件,在第 5 行添加#categories-chart.js-pjax 和#categories-radar.js-pjax。
1 2 3 4 5 6 7
| .category-lists .category-title.is-center= _p('page.category') | - span.category-amount= site.categories.length div!= list_categories()
|

其他页面,只需 md 文件中插入这个标签:
分类统计(无标题)
1
| <div id="categories-chart" class="js-pjax"></div>
|
分类雷达图(无标题)
1
| <div id="categories-radar" class="js-pjax"></div>
|
三. 效果
分类统计与分类雷达图

分类标签图

文章发布统计
