From 625f62321202726fdf5e8e01704eb433183b6689 Mon Sep 17 00:00:00 2001 From: liuyib <1656081615@qq.com> Date: Sat, 3 Aug 2019 09:02:44 +0800 Subject: [PATCH] refactor: Modify arguments of tag plugin --- docs/zh-CN/advanced/assist.md | 34 ++++++++++++++++----- scripts/tags/note.js | 4 ++- scripts/tags/table.js | 21 ++++++------- source/css/_components/tag-plugin/note.styl | 18 +++++------ 4 files changed, 49 insertions(+), 28 deletions(-) diff --git a/docs/zh-CN/advanced/assist.md b/docs/zh-CN/advanced/assist.md index 47096df..dc86edd 100644 --- a/docs/zh-CN/advanced/assist.md +++ b/docs/zh-CN/advanced/assist.md @@ -36,19 +36,19 @@ Hexo 主题一般都会扩展一些自己特有的标签插件,在这方面做 此外,Stun 主题也有自己扩展的一些标签插件,这些标签插件如下: -### 插入表格数据 +### 插入表格数据 如果想要在文章中显示一个表格,你可以使用 markdown 原生支持的语法,但是如果你想要让表格里的数据存储在外部文件中,那么你可以使用下面这种语法: ``` -{% table [path], [thead1, thead2, ...] %} +{% table [path] [thead1,thead2,...] %} ``` 参数: `[path]`:数据文件的路径 -`[thead1, thead2, ...]`:表格头部的文字(表格有几列就要写几项) +`[thead1,thead2,...]`:表格头部的文字(用半角逗号分隔,逗号前后不要有空格) ::: warning 数据文件必须放在 `/source/` 目录下,建议放在 `/source/_data/` 目录下。 @@ -80,14 +80,14 @@ Hexo 主题一般都会扩展一些自己特有的标签插件,在这方面做 2. 在文章或页面的 markdown 源文件中,插入如下标签。 ``` -{% table _data/reward.json, 时间, 赞助人, 金额, 留言 %} +{% table _data/reward.json 时间,赞助人,金额,留言 %} ``` 3. 重启 Hexo 服务器,效果如下。 ![](https://raw.githubusercontent.com/liuyib/picBed/master/hexo-theme-stun/doc/20190802171506.png) -### Bootstrap 标注 +### Bootstrap 标注 语法如下: @@ -109,14 +109,34 @@ any text 举例: -``` +```md + {% note success %} **Success** +This is success note. +{% endnote %} + + +{% note success no-icon %} +**Success** + +This is success note. +{% endnote %} + + +{% note success %} +This is success note. +{% endnote %} + + +{% note success no-icon %} This is success note. {% 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) diff --git a/scripts/tags/note.js b/scripts/tags/note.js index 99d917b..05af1e6 100644 --- a/scripts/tags/note.js +++ b/scripts/tags/note.js @@ -3,7 +3,9 @@ 'use strict'; function note(args, content) { - return `
+ var args = args.join(' '); + + return `
${hexo.render .renderSync({ text: content, engine: 'markdown' }) .split('\n') diff --git a/scripts/tags/table.js b/scripts/tags/table.js index ccad758..d38dd6a 100644 --- a/scripts/tags/table.js +++ b/scripts/tags/table.js @@ -6,9 +6,8 @@ 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); + var headers = args[1].split(','); fs.exists(path).then(function(exist) { if (!exist) { @@ -17,24 +16,24 @@ function table(args) { } }); - return fs.readFile(path).then(function(data) { - if (!data) { + return fs.readFile(path).then(function(datas) { + if (!datas) { hexo.log.warn('Include file empty.'); return; } - var data = JSON.parse(data); + var datas = JSON.parse(datas); var result = ''; - headers.forEach(item => { - result += ``; + headers.forEach(header => { + result += ``; }); result += ''; - data.forEach(item => { + datas.forEach(data => { result += ''; - for (const key in item) { - if (item.hasOwnProperty(key)) { - const value = item[key]; + for (const key in data) { + if (data.hasOwnProperty(key)) { + const value = data[key]; result += `` } diff --git a/source/css/_components/tag-plugin/note.styl b/source/css/_components/tag-plugin/note.styl index 8b24121..baa75c6 100644 --- a/source/css/_components/tag-plugin/note.styl +++ b/source/css/_components/tag-plugin/note.styl @@ -22,15 +22,15 @@ &.success::before content: '\f058' - color: #5cb85c + color: #42b983 &.warning::before content: '\f06a' - color: #f0ad4e + color: #ecc91e &.danger::before content: '\f056' - color: #d9534f + color: #dc3b3b &.default border-left-color: #777 @@ -39,22 +39,22 @@ color: #777 &.success - border-left-color: #5cb85c + border-left-color: #42b983 strong - color: #5cb85c + color: #42b983 &.warning - border-left-color: #f0ad4e + border-left-color: #ecc91e strong - color: #f0ad4e + color: #ecc91e &.danger - border-left-color: #d9534f + border-left-color: #dc3b3b strong - color: #d9534f + color: #dc3b3b h1, h2, h3, h4, h5, h6 margin: 0 -- GitLab
${item.trim()}${header}
${value}