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

refactor: Modify arguments of tag plugin

上级 c9d5e81c
...@@ -36,19 +36,19 @@ Hexo 主题一般都会扩展一些自己特有的标签插件,在这方面做 ...@@ -36,19 +36,19 @@ Hexo 主题一般都会扩展一些自己特有的标签插件,在这方面做
此外,Stun 主题也有自己扩展的一些标签插件,这些标签插件如下: 此外,Stun 主题也有自己扩展的一些标签插件,这些标签插件如下:
### 插入表格数据 <Badge text="stable"/> <Badge text="v1.2.0"/> ### 插入表格数据 <Badge text="beta" type="warning"/> <Badge text="v1.2.0"/>
如果想要在文章中显示一个表格,你可以使用 markdown 原生支持的语法,但是如果你想要让表格里的数据存储在外部文件中,那么你可以使用下面这种语法: 如果想要在文章中显示一个表格,你可以使用 markdown 原生支持的语法,但是如果你想要让表格里的数据存储在外部文件中,那么你可以使用下面这种语法:
``` ```
{% table [path], [thead1, thead2, ...] %} {% table [path] [thead1,thead2,...] %}
``` ```
参数: 参数:
`[path]`:数据文件的路径 `[path]`:数据文件的路径
`[thead1, thead2, ...]`:表格头部的文字(表格有几列就要写几项 `[thead1,thead2,...]`:表格头部的文字(用半角逗号分隔,逗号前后不要有空格
::: warning ::: warning
数据文件必须放在 `/source/` 目录下,建议放在 `/source/_data/` 目录下。 数据文件必须放在 `/source/` 目录下,建议放在 `/source/_data/` 目录下。
...@@ -80,14 +80,14 @@ Hexo 主题一般都会扩展一些自己特有的标签插件,在这方面做 ...@@ -80,14 +80,14 @@ Hexo 主题一般都会扩展一些自己特有的标签插件,在这方面做
2. 在文章或页面的 markdown 源文件中,插入如下标签。 2. 在文章或页面的 markdown 源文件中,插入如下标签。
``` ```
{% table _data/reward.json, 时间, 赞助人, 金额, 留言 %} {% table _data/reward.json 时间,赞助人,金额,留言 %}
``` ```
3. 重启 Hexo 服务器,效果如下。 3. 重启 Hexo 服务器,效果如下。
![](https://raw.githubusercontent.com/liuyib/picBed/master/hexo-theme-stun/doc/20190802171506.png) ![](https://raw.githubusercontent.com/liuyib/picBed/master/hexo-theme-stun/doc/20190802171506.png)
### Bootstrap 标注 <Badge text="stable"/> <Badge text="v1.2.0"/> ### Bootstrap 标注 <Badge text="beta" type="warning"/> <Badge text="v1.2.0"/>
语法如下: 语法如下:
...@@ -109,14 +109,34 @@ any text ...@@ -109,14 +109,34 @@ any text
举例: 举例:
``` ```md
<!-- header icon -->
{% note success %} {% note success %}
**Success** **Success**
This is success note.
{% endnote %}
<!-- header no-icon -->
{% note success no-icon %}
**Success**
This is success note.
{% endnote %}
<!-- no-header icon -->
{% note success %}
This is success note.
{% endnote %}
<!-- no-header no-icon -->
{% note success no-icon %}
This is success note. This is success note.
{% endnote %} {% endnote %}
``` ```
全部效果如下: 全部效果如下:
![](https://raw.githubusercontent.com/liuyib/picBed/master/hexo-theme-stun/doc/20190802221712.png) ![](https://raw.githubusercontent.com/liuyib/picBed/master/hexo-theme-stun/doc/20190803082614.png)
![](https://raw.githubusercontent.com/liuyib/picBed/master/hexo-theme-stun/doc/20190803081736.png)
...@@ -3,7 +3,9 @@ ...@@ -3,7 +3,9 @@
'use strict'; 'use strict';
function note(args, content) { function note(args, content) {
return `<div class="note-plugin ${args.join(' ')}"> var args = args.join(' ');
return `<div class="note-plugin ${args}">
${hexo.render ${hexo.render
.renderSync({ text: content, engine: 'markdown' }) .renderSync({ text: content, engine: 'markdown' })
.split('\n') .split('\n')
......
...@@ -6,9 +6,8 @@ var pathFn = require('path'); ...@@ -6,9 +6,8 @@ var pathFn = require('path');
var fs = require('hexo-fs'); var fs = require('hexo-fs');
function table(args) { function table(args) {
args = args.join(' ').split(',');
var path = pathFn.join(hexo.source_dir, args[0]); var path = pathFn.join(hexo.source_dir, args[0]);
var headers = args.slice(1); var headers = args[1].split(',');
fs.exists(path).then(function(exist) { fs.exists(path).then(function(exist) {
if (!exist) { if (!exist) {
...@@ -17,24 +16,24 @@ function table(args) { ...@@ -17,24 +16,24 @@ function table(args) {
} }
}); });
return fs.readFile(path).then(function(data) { return fs.readFile(path).then(function(datas) {
if (!data) { if (!datas) {
hexo.log.warn('Include file empty.'); hexo.log.warn('Include file empty.');
return; return;
} }
var data = JSON.parse(data); var datas = JSON.parse(datas);
var result = '<table><thead><tr>'; var result = '<table><thead><tr>';
headers.forEach(item => { headers.forEach(header => {
result += `<th>${item.trim()}</th>`; result += `<th>${header}</th>`;
}); });
result += '</tr></thead><tbody>'; result += '</tr></thead><tbody>';
data.forEach(item => { datas.forEach(data => {
result += '<tr style="text-align: center;">'; result += '<tr style="text-align: center;">';
for (const key in item) { for (const key in data) {
if (item.hasOwnProperty(key)) { if (data.hasOwnProperty(key)) {
const value = item[key]; const value = data[key];
result += `<td>${value}</td>` result += `<td>${value}</td>`
} }
......
...@@ -22,15 +22,15 @@ ...@@ -22,15 +22,15 @@
&.success::before &.success::before
content: '\f058' content: '\f058'
color: #5cb85c color: #42b983
&.warning::before &.warning::before
content: '\f06a' content: '\f06a'
color: #f0ad4e color: #ecc91e
&.danger::before &.danger::before
content: '\f056' content: '\f056'
color: #d9534f color: #dc3b3b
&.default &.default
border-left-color: #777 border-left-color: #777
...@@ -39,22 +39,22 @@ ...@@ -39,22 +39,22 @@
color: #777 color: #777
&.success &.success
border-left-color: #5cb85c border-left-color: #42b983
strong strong
color: #5cb85c color: #42b983
&.warning &.warning
border-left-color: #f0ad4e border-left-color: #ecc91e
strong strong
color: #f0ad4e color: #ecc91e
&.danger &.danger
border-left-color: #d9534f border-left-color: #dc3b3b
strong strong
color: #d9534f color: #dc3b3b
h1, h2, h3, h4, h5, h6 h1, h2, h3, h4, h5, h6
margin: 0 margin: 0
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册