提交 1d86188a 编写于 作者: EvanOne(文一)'s avatar EvanOne(文一)

feat: Add tag plugin of 'table'

上级 0699e519
......@@ -2,7 +2,7 @@
## 快捷键
- 快速切换文章 <Badge text="beta" type="warn"/> <Badge text="v1.1.3"/>
### 快速切换文章 <Badge text="beta" type="warn"/> <Badge text="v1.1.3"/>
::: tip
该功能在 `v1.1.0` 版本中快捷键为(`←`:切换到上一篇文章,`→`:切换到下一篇文章),在 `v1.1.3` 版本中快捷键修改为(Ctrl + `←`,Ctrl + `→`)。
......@@ -24,6 +24,65 @@ shortcuts:
> 考虑到这里的快捷键可能会和用户系统或软件的冲突,所以在 Stun 主题 `v1.1.3` 版本中,这个功能加入了配置项,用户可以自己决定是否开启,默认不启用。并且在 Stun 主题以后的版本中,可能会留出配置项让用户自定义快捷键。
- 快速关闭搜索框 <Badge text="stable"/> <Badge text="v1.0.3"/>
### 快速关闭搜索框 <Badge text="stable"/> <Badge text="v1.0.3"/>
关闭搜索框有三种方式,1. 点击关闭按钮,2. 点击蒙版,3. 按下 `Esc` 键。
## 标签插件
该功能相当于 Hexo 对 markdown 语法的一种扩展,用于快速在文章中插入指定的内容。你可以访问[这里](https://hexo.io/zh-cn/docs/tag-plugins)查看 Hexo 都支持哪些标签插件。
Hexo 主题一般都会扩展一些自己特有的标签插件,在这方面做得最好的是 NexT 主题,你可以查看 NexT 主题所特有的标签插件:[https://theme-next.org/docs/tag-plugins/](https://theme-next.org/docs/tag-plugins/)
此外,Stun 主题也有自己扩展的一些标签插件,这些标签插件如下:
### 插入表格数据 <Badge text="stable"/> <Badge text="v1.2.0"/>
如果想要在文章中显示一个表格,你可以使用 markdown 原生支持的语法,但是如果你想要让表格里的数据存储在外部文件中,那么你可以使用下面这种语法:
```
{% table [path], [thead1, thead2, ...] %}
```
参数:
`[path]`:数据文件的路径
`[thead1, thead2, ...]`:表格头部的文字(表格有几列就要写几项)
::: warning
数据文件必须放在 `/source/` 目录下,建议放在 `/source/_data/` 目录下。
:::
举例:
在文章或页面中显示一个打赏列表。
1.`/source/_data/` 目录下新建文件 `reward.json`,填入数据。
``` json
[
{
"time": "2019-6-1",
"sponsor": "张三",
"money": "9.9",
"remark": "支持一下~"
},
{
"time": "2019-6-16",
"sponsor": "李四",
"money": "11",
"remark": "前来支持,继续加油!"
}
]
```
2. 在文章或页面的 markdown 源文件中,插入如下标签。
```
{% table _data/reward.json, 时间, 赞助人, 金额, 留言 %}
```
3. 重启 Hexo 服务器,效果如下。
![](https://raw.githubusercontent.com/liuyib/picBed/master/hexo-theme-stun/doc/20190802171506.png)
......@@ -941,7 +941,7 @@ external_link:
color: "#aaa"
```
## FancyBox <Badge text="stable"/> <Badge text="v1.1.4"/>
### FancyBox <Badge text="stable"/> <Badge text="v1.1.4"/>
如果想要使用 fancybox 功能,只需要修改主题配置文件即可:
......
......@@ -27,7 +27,7 @@ sidebar:
overview: Overview
catalog: Catalog
subscribe: Subscribe
articles: Articles
archives: Archives
categories: Categories
tags: Tags
read_info: You have read
......@@ -92,6 +92,7 @@ footer:
uv: Visitors
pv: Views
# Global notification
notification:
copy:
success: Copy Success
......
......@@ -27,7 +27,7 @@ sidebar:
overview: 站点概览
catalog: 文章目录
subscribe: 订阅
articles: 文章
archives: 归档
categories: 分类
tags: 标签
read_info: 你已阅读了
......@@ -92,6 +92,7 @@ footer:
uv: 访问人数
pv: 浏览总量
# 全局消息提示信息
notification:
copy:
success: 复制成功
......
......@@ -68,7 +68,7 @@ aside#sidebar
span.sidebar-state-item.sidebar-state-posts
a(href=menuArchives)
div.sidebar-state-item-count= site.posts.length
div.sidebar-state-item-name= _p("sidebar.articles")
div.sidebar-state-item-name= _p("sidebar.archives")
if theme.menu.categories
span.sidebar-state-item.sidebar-state-categories
a(href=menuCategories)
......
/* global hexo */
'use strict';
var pathFn = require('path');
var fs = require('hexo-fs');
function table(args) {
args = args.join(' ').split(',');
var path = pathFn.join(hexo.source_dir, args[0]);
var headers = args.slice(1);
fs.exists(path).then(function(exist) {
if (!exist) {
hexo.log.error('Include file not found!');
return;
}
});
return fs.readFile(path).then(function(data) {
if (!data) {
hexo.log.warn('Include file empty.');
return;
}
var data = JSON.parse(data);
var result = '<table><thead><tr>';
headers.forEach(item => {
result += `<th>${item.trim()}</th>`;
});
result += '</tr></thead><tbody>';
data.forEach(item => {
result += '<tr style="text-align: center;">';
for (const key in item) {
if (item.hasOwnProperty(key)) {
const value = item[key];
result += `<td>${value}</td>`
}
}
result += '</tr>';
});
result += '</tbody></table>';
return result;
});
}
hexo.extend.tag.register('table', table, { ends: false, async: true });
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册