hexo-component-inferno 1.0.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/hexo/generator/insight.js +8 -1
- package/lib/hexo/generator/insight.test.js +16 -0
- package/lib/hexo/helper/cdn.js +1 -2
- package/lib/hexo/helper/cdn.test.js +9 -9
- package/lib/hexo/tag/message.js +100 -0
- package/lib/hexo/tag/message.test.js +70 -0
- package/lib/hexo/tag/tabs.js +290 -0
- package/lib/hexo/tag/tabs.test.js +97 -0
- package/lib/schema/comment/disqusjs.json +4 -5
- package/lib/schema/comment/twikoo.json +17 -0
- package/lib/schema/comment/waline.json +28 -36
- package/lib/schema/schema/comment/changyan.json +21 -0
- package/lib/schema/schema/comment/disqus.json +17 -0
- package/lib/schema/schema/comment/disqusjs.json +53 -0
- package/lib/schema/schema/comment/facebook.json +13 -0
- package/lib/schema/schema/comment/gitalk.json +81 -0
- package/lib/schema/schema/comment/gitment.json +47 -0
- package/lib/schema/schema/comment/isso.json +17 -0
- package/lib/schema/schema/comment/livere.json +17 -0
- package/lib/schema/schema/comment/twikoo.json +17 -0
- package/lib/schema/schema/comment/utterances.json +59 -0
- package/lib/schema/schema/comment/valine.json +105 -0
- package/lib/schema/schema/comment/waline.json +164 -0
- package/lib/schema/schema/donate/afdian.json +17 -0
- package/lib/schema/schema/donate/alipay.json +17 -0
- package/lib/schema/schema/donate/buymeacoffee.json +17 -0
- package/lib/schema/schema/donate/patreon.json +17 -0
- package/lib/schema/schema/donate/paypal.json +22 -0
- package/lib/schema/schema/donate/wechat.json +17 -0
- package/lib/schema/schema/misc/manifest.json +66 -0
- package/lib/schema/schema/misc/meta.json +11 -0
- package/lib/schema/schema/misc/open_graph.json +78 -0
- package/lib/schema/schema/misc/poly_links.json +35 -0
- package/lib/schema/schema/misc/structured_data.json +47 -0
- package/lib/schema/schema/plugin/baidu_analytics.json +14 -0
- package/lib/schema/schema/plugin/bing_webmaster.json +14 -0
- package/lib/schema/schema/plugin/busuanzi.json +7 -0
- package/lib/schema/schema/plugin/cnzz.json +19 -0
- package/lib/schema/schema/plugin/cookie_consent.json +38 -0
- package/lib/schema/schema/plugin/gallery.json +7 -0
- package/lib/schema/schema/plugin/google_analytics.json +14 -0
- package/lib/schema/schema/plugin/hotjar.json +14 -0
- package/lib/schema/schema/plugin/katex.json +7 -0
- package/lib/schema/schema/plugin/mathjax.json +7 -0
- package/lib/schema/schema/plugin/outdated_browser.json +7 -0
- package/lib/schema/schema/plugin/progressbar.json +7 -0
- package/lib/schema/schema/plugin/statcounter.json +19 -0
- package/lib/schema/schema/plugin/twitter_conversion_tracking.json +14 -0
- package/lib/schema/schema/search/algolia.json +13 -0
- package/lib/schema/schema/search/baidu.json +13 -0
- package/lib/schema/schema/search/google_cse.json +17 -0
- package/lib/schema/schema/search/insight.json +13 -0
- package/lib/schema/schema/share/addthis.json +17 -0
- package/lib/schema/schema/share/addtoany.json +13 -0
- package/lib/schema/schema/share/bdshare.json +13 -0
- package/lib/schema/schema/share/sharejs.json +13 -0
- package/lib/schema/schema/share/sharethis.json +17 -0
- package/lib/schema/schema/widget/adsense.json +21 -0
- package/lib/schema/schema/widget/archives.json +13 -0
- package/lib/schema/schema/widget/categories.json +13 -0
- package/lib/schema/schema/widget/followit.json +26 -0
- package/lib/schema/schema/widget/links.json +47 -0
- package/lib/schema/schema/widget/recent_posts.json +13 -0
- package/lib/schema/schema/widget/subscribe_email.json +22 -0
- package/lib/schema/schema/widget/tags.json +30 -0
- package/lib/schema/schema/widget/toc.json +31 -0
- package/lib/schema/widget/tags.json +17 -0
- package/lib/view/comment/changyan.js +2 -2
- package/lib/view/comment/disqus.js +2 -2
- package/lib/view/comment/disqusjs.js +2 -2
- package/lib/view/comment/facebook.js +2 -2
- package/lib/view/comment/gitalk.js +2 -2
- package/lib/view/comment/gitment.js +2 -2
- package/lib/view/comment/isso.js +2 -2
- package/lib/view/comment/livere.js +2 -2
- package/lib/view/comment/twikoo.js +102 -0
- package/lib/view/comment/utterances.js +2 -2
- package/lib/view/comment/valine.js +2 -2
- package/lib/view/comment/waline.js +31 -36
- package/lib/view/common/article_media.js +2 -2
- package/lib/view/donate/afdian.js +2 -2
- package/lib/view/donate/alipay.js +2 -2
- package/lib/view/donate/buymeacoffee.js +2 -2
- package/lib/view/donate/patreon.js +2 -2
- package/lib/view/donate/paypal.js +2 -2
- package/lib/view/donate/wechat.js +2 -2
- package/lib/view/misc/article_licensing.js +2 -2
- package/lib/view/misc/meta.js +2 -2
- package/lib/view/misc/open_graph.js +12 -4
- package/lib/view/misc/paginator.js +2 -2
- package/lib/view/misc/structured_data.js +2 -2
- package/lib/view/misc/web_app.js +2 -2
- package/lib/view/plugin/baidu_analytics.js +2 -2
- package/lib/view/plugin/bing_webmaster.js +2 -2
- package/lib/view/plugin/busuanzi.js +2 -2
- package/lib/view/plugin/cnzz.js +2 -2
- package/lib/view/plugin/cookie_consent.js +2 -2
- package/lib/view/plugin/gallery.js +2 -2
- package/lib/view/plugin/google_analytics.js +2 -2
- package/lib/view/plugin/hotjar.js +2 -2
- package/lib/view/plugin/katex.js +2 -2
- package/lib/view/plugin/mathjax.js +2 -2
- package/lib/view/plugin/outdated_browser.js +2 -2
- package/lib/view/plugin/progressbar.js +2 -2
- package/lib/view/plugin/statcounter.js +2 -2
- package/lib/view/plugin/twitter_conversion_tracking.js +2 -2
- package/lib/view/search/algolia.js +2 -2
- package/lib/view/search/baidu.js +2 -2
- package/lib/view/search/google_cse.js +2 -2
- package/lib/view/search/insight.js +2 -2
- package/lib/view/share/addthis.js +2 -2
- package/lib/view/share/addtoany.js +2 -2
- package/lib/view/share/bdshare.js +2 -2
- package/lib/view/share/sharejs.js +2 -2
- package/lib/view/share/sharethis.js +2 -2
- package/lib/view/widget/adsense.js +2 -2
- package/lib/view/widget/archives.js +2 -2
- package/lib/view/widget/categories.js +2 -2
- package/lib/view/widget/followit.js +2 -2
- package/lib/view/widget/links.js +2 -2
- package/lib/view/widget/recent_posts.js +2 -2
- package/lib/view/widget/subscribe_email.js +2 -2
- package/lib/view/widget/tags.js +16 -15
- package/lib/view/widget/toc.js +2 -2
- package/package.json +9 -11
|
@@ -43,11 +43,18 @@ module.exports = function (hexo) {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
const site = {
|
|
46
|
-
pages: locals.pages.map(mapPost),
|
|
47
46
|
posts: locals.posts.map(mapPost),
|
|
48
47
|
tags: locals.tags.map(mapTag),
|
|
49
48
|
categories: locals.categories.map(mapTag)
|
|
50
49
|
};
|
|
50
|
+
const index_pages = ((this.theme.config || {}).search || {}).index_pages;
|
|
51
|
+
|
|
52
|
+
if (index_pages === false) {
|
|
53
|
+
site.pages = [];
|
|
54
|
+
} else {
|
|
55
|
+
site.pages = locals.pages.map(mapPost);
|
|
56
|
+
}
|
|
57
|
+
|
|
51
58
|
return {
|
|
52
59
|
path: '/content.json',
|
|
53
60
|
data: JSON.stringify(site)
|
|
@@ -79,4 +79,20 @@ test('Export assets file from asset folder', async () => {
|
|
|
79
79
|
expect(data.tags.length).toBe(2);
|
|
80
80
|
expect(data.tags.find(tag => tag.name === 'tag1' && tag.slug === 'tag1' && tag.link.includes('tag1'))).not.toBeUndefined();
|
|
81
81
|
expect(data.tags.find(tag => tag.name === 'tag2' && tag.slug === 'tag2' && tag.link.includes('tag2'))).not.toBeUndefined();
|
|
82
|
+
});
|
|
83
|
+
test('Exclude pages from index when `index_pages` is false', async () => {
|
|
84
|
+
const locals = hexo.locals.toObject();
|
|
85
|
+
locals.config = hexo.config;
|
|
86
|
+
locals.posts = posts;
|
|
87
|
+
locals.pages = pages;
|
|
88
|
+
locals.categories = categories;
|
|
89
|
+
locals.tags = tags;
|
|
90
|
+
hexo.theme.config.search = {
|
|
91
|
+
index_pages: false
|
|
92
|
+
};
|
|
93
|
+
const generator = hexo.extend.generator.get('insight').bind(hexo);
|
|
94
|
+
const result = await generator(locals);
|
|
95
|
+
const data = JSON.parse(result.data);
|
|
96
|
+
expect(data.posts.length).toBe(2);
|
|
97
|
+
expect(data.pages.length).toBe(0);
|
|
82
98
|
});
|
package/lib/hexo/helper/cdn.js
CHANGED
|
@@ -48,8 +48,7 @@ const CDNJS_FIXTURES = {
|
|
|
48
48
|
// disqusjs is not hosted on CDN.js
|
|
49
49
|
disqusjs: (ver, fname) => [],
|
|
50
50
|
cookieconsent: (ver, fname) => ['cookieconsent', ver, fname.startsWith('build/') ? fname.substr(6) : fname],
|
|
51
|
-
|
|
52
|
-
'@waline/client': (ver, fname) => []
|
|
51
|
+
'@waline/client': (ver, fname) => ['waline', ver, fname]
|
|
53
52
|
};
|
|
54
53
|
const UNPKG_FIXTURES = {
|
|
55
54
|
mathjax: (ver, fname) => ['mathjax', ver, fname.indexOf('.min.') > -1 ? fname.replace(/\.min\./gi, '.') : fname],
|
|
@@ -17,59 +17,59 @@ describe('Get JavaScript library URL', () => {
|
|
|
17
17
|
let cases;
|
|
18
18
|
beforeEach(async () => {
|
|
19
19
|
const cdn = hexo.extend.helper.get('cdn').bind(hexo);
|
|
20
|
-
cases = [() => cdn('jquery', '3.0.0', 'dist/jquery.min.js'), () => cdn('moment', '2.24.0', 'min/moment.min.js'), () => cdn('outdatedbrowser', '1.1.5', 'outdatedbrowser/outdatedbrowser.min.js'), () => cdn('highlight.js', '9.18.1', 'styles/a11y-dark.css'), () => cdn('mathjax', '2.7.6', 'unpacked/MathJax.min.js'), () => cdn('pace-js', '1.0.2', 'pace.min.js'), () => cdn('katex', '0.11.1', 'dist/katex.min.js'), () => cdn('clipboard', '2.0.6', 'dist/clipboard.min.js'), () => cdn('disqusjs', '1.2.6', 'dist/disqus.min.js'), () => cdn('algoliasearch', '4.0.3', 'dist/algoliasearch-lite.umd.js'), () => cdn('instantsearch.js', '4.3.1', 'dist/instantsearch.production.min.js'), () => cdn('cookieconsent', '3.1.1', 'build/cookieconsent.min.js'), () => cdn('@waline/client', '1.
|
|
20
|
+
cases = [() => cdn('jquery', '3.0.0', 'dist/jquery.min.js'), () => cdn('moment', '2.24.0', 'min/moment.min.js'), () => cdn('outdatedbrowser', '1.1.5', 'outdatedbrowser/outdatedbrowser.min.js'), () => cdn('highlight.js', '9.18.1', 'styles/a11y-dark.css'), () => cdn('mathjax', '2.7.6', 'unpacked/MathJax.min.js'), () => cdn('pace-js', '1.0.2', 'pace.min.js'), () => cdn('katex', '0.11.1', 'dist/katex.min.js'), () => cdn('clipboard', '2.0.6', 'dist/clipboard.min.js'), () => cdn('disqusjs', '1.2.6', 'dist/disqus.min.js'), () => cdn('algoliasearch', '4.0.3', 'dist/algoliasearch-lite.umd.js'), () => cdn('instantsearch.js', '4.3.1', 'dist/instantsearch.production.min.js'), () => cdn('cookieconsent', '3.1.1', 'build/cookieconsent.min.js'), () => cdn('@waline/client', '1.5.4', 'dist/Waline.min.js'), () => cdn('example', '1.0.0', 'example.js')];
|
|
21
21
|
});
|
|
22
22
|
test('jsdelivr', () => {
|
|
23
|
-
const expected = ['https://cdn.jsdelivr.net/npm/jquery@3.0.0/dist/jquery.min.js', 'https://cdn.jsdelivr.net/npm/moment@2.24.0/min/moment.min.js', 'https://cdn.jsdelivr.net/npm/outdatedbrowser@1.1.5/outdatedbrowser/outdatedbrowser.min.js', 'https://cdn.jsdelivr.net/npm/highlight.js@9.18.1/styles/a11y-dark.css', 'https://cdn.jsdelivr.net/npm/mathjax@2.7.6/unpacked/MathJax.min.js', 'https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js', 'https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.js', 'https://cdn.jsdelivr.net/npm/clipboard@2.0.6/dist/clipboard.min.js', 'https://cdn.jsdelivr.net/npm/disqusjs@1.2.6/dist/disqus.min.js', 'https://cdn.jsdelivr.net/npm/algoliasearch@4.0.3/dist/algoliasearch-lite.umd.js', 'https://cdn.jsdelivr.net/npm/instantsearch.js@4.3.1/dist/instantsearch.production.min.js', 'https://cdn.jsdelivr.net/npm/cookieconsent@3.1.1/build/cookieconsent.min.js', 'https://cdn.jsdelivr.net/npm/@waline/client@1.
|
|
23
|
+
const expected = ['https://cdn.jsdelivr.net/npm/jquery@3.0.0/dist/jquery.min.js', 'https://cdn.jsdelivr.net/npm/moment@2.24.0/min/moment.min.js', 'https://cdn.jsdelivr.net/npm/outdatedbrowser@1.1.5/outdatedbrowser/outdatedbrowser.min.js', 'https://cdn.jsdelivr.net/npm/highlight.js@9.18.1/styles/a11y-dark.css', 'https://cdn.jsdelivr.net/npm/mathjax@2.7.6/unpacked/MathJax.min.js', 'https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js', 'https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.js', 'https://cdn.jsdelivr.net/npm/clipboard@2.0.6/dist/clipboard.min.js', 'https://cdn.jsdelivr.net/npm/disqusjs@1.2.6/dist/disqus.min.js', 'https://cdn.jsdelivr.net/npm/algoliasearch@4.0.3/dist/algoliasearch-lite.umd.js', 'https://cdn.jsdelivr.net/npm/instantsearch.js@4.3.1/dist/instantsearch.production.min.js', 'https://cdn.jsdelivr.net/npm/cookieconsent@3.1.1/build/cookieconsent.min.js', 'https://cdn.jsdelivr.net/npm/@waline/client@1.5.4/dist/Waline.min.js', 'https://cdn.jsdelivr.net/npm/example@1.0.0/example.js'];
|
|
24
24
|
cases.forEach((func, i) => expect(func()).toBe(expected[i]));
|
|
25
25
|
});
|
|
26
26
|
test('unpkg', () => {
|
|
27
27
|
hexo.config.providers = {
|
|
28
28
|
cdn: 'unpkg'
|
|
29
29
|
};
|
|
30
|
-
const expected = ['https://unpkg.com/jquery@3.0.0/dist/jquery.min.js', 'https://unpkg.com/moment@2.24.0/min/moment.min.js', 'https://unpkg.com/outdatedbrowser@1.1.5/outdatedbrowser/outdatedbrowser.min.js', 'https://unpkg.com/highlight.js@9.18.1/styles/a11y-dark.css', 'https://unpkg.com/mathjax@2.7.6/unpacked/MathJax.js', 'https://unpkg.com/pace-js@1.0.2/pace.min.js', 'https://unpkg.com/katex@0.11.1/dist/katex.min.js', 'https://unpkg.com/clipboard@2.0.6/dist/clipboard.min.js', 'https://unpkg.com/disqusjs@1.2.6/dist/disqus.js', 'https://unpkg.com/algoliasearch@4.0.3/dist/algoliasearch-lite.umd.js', 'https://unpkg.com/instantsearch.js@4.3.1/dist/instantsearch.production.min.js', 'https://unpkg.com/cookieconsent@3.1.1/build/cookieconsent.min.js', 'https://unpkg.com/@waline/client@1.
|
|
30
|
+
const expected = ['https://unpkg.com/jquery@3.0.0/dist/jquery.min.js', 'https://unpkg.com/moment@2.24.0/min/moment.min.js', 'https://unpkg.com/outdatedbrowser@1.1.5/outdatedbrowser/outdatedbrowser.min.js', 'https://unpkg.com/highlight.js@9.18.1/styles/a11y-dark.css', 'https://unpkg.com/mathjax@2.7.6/unpacked/MathJax.js', 'https://unpkg.com/pace-js@1.0.2/pace.min.js', 'https://unpkg.com/katex@0.11.1/dist/katex.min.js', 'https://unpkg.com/clipboard@2.0.6/dist/clipboard.min.js', 'https://unpkg.com/disqusjs@1.2.6/dist/disqus.js', 'https://unpkg.com/algoliasearch@4.0.3/dist/algoliasearch-lite.umd.js', 'https://unpkg.com/instantsearch.js@4.3.1/dist/instantsearch.production.min.js', 'https://unpkg.com/cookieconsent@3.1.1/build/cookieconsent.min.js', 'https://unpkg.com/@waline/client@1.5.4/dist/Waline.min.js', 'https://unpkg.com/example@1.0.0/example.js'];
|
|
31
31
|
cases.forEach((func, i) => expect(func()).toBe(expected[i]));
|
|
32
32
|
});
|
|
33
33
|
test('cdnjs', () => {
|
|
34
34
|
hexo.config.providers = {
|
|
35
35
|
cdn: 'cdnjs'
|
|
36
36
|
};
|
|
37
|
-
const expected = ['https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js', 'https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js', 'https://cdnjs.cloudflare.com/ajax/libs/outdated-browser/1.1.5/outdatedbrowser.min.js', 'https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.1/styles/a11y-dark.min.css', 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.6/MathJax.js', 'https://cdnjs.cloudflare.com/ajax/libs/pace/1.0.2/pace.min.js', 'https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.11.1/katex.min.js', 'https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js', 'https://cdn.jsdelivr.net/npm/disqusjs@1.2.6/dist/disqus.min.js', 'https://cdnjs.cloudflare.com/ajax/libs/algoliasearch/4.0.3/algoliasearch-lite.umd.js', 'https://cdnjs.cloudflare.com/ajax/libs/instantsearch.js/4.3.1/instantsearch.production.min.js', 'https://cdnjs.cloudflare.com/ajax/libs/cookieconsent/3.1.1/cookieconsent.min.js', 'https://
|
|
37
|
+
const expected = ['https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js', 'https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js', 'https://cdnjs.cloudflare.com/ajax/libs/outdated-browser/1.1.5/outdatedbrowser.min.js', 'https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.1/styles/a11y-dark.min.css', 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.6/MathJax.js', 'https://cdnjs.cloudflare.com/ajax/libs/pace/1.0.2/pace.min.js', 'https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.11.1/katex.min.js', 'https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js', 'https://cdn.jsdelivr.net/npm/disqusjs@1.2.6/dist/disqus.min.js', 'https://cdnjs.cloudflare.com/ajax/libs/algoliasearch/4.0.3/algoliasearch-lite.umd.js', 'https://cdnjs.cloudflare.com/ajax/libs/instantsearch.js/4.3.1/instantsearch.production.min.js', 'https://cdnjs.cloudflare.com/ajax/libs/cookieconsent/3.1.1/cookieconsent.min.js', 'https://cdnjs.cloudflare.com/ajax/libs/waline/1.5.4/Waline.min.js', 'https://cdnjs.cloudflare.com/ajax/libs/example/1.0.0/example.js'];
|
|
38
38
|
cases.forEach((func, i) => expect(func()).toBe(expected[i]));
|
|
39
39
|
});
|
|
40
40
|
test('loli', () => {
|
|
41
41
|
hexo.config.providers = {
|
|
42
42
|
cdn: 'loli'
|
|
43
43
|
};
|
|
44
|
-
const expected = ['https://cdnjs.loli.net/ajax/libs/jquery/3.0.0/jquery.min.js', 'https://cdnjs.loli.net/ajax/libs/moment.js/2.24.0/moment.min.js', 'https://cdnjs.loli.net/ajax/libs/outdated-browser/1.1.5/outdatedbrowser.min.js', 'https://cdnjs.loli.net/ajax/libs/highlight.js/9.18.1/styles/a11y-dark.min.css', 'https://cdnjs.loli.net/ajax/libs/mathjax/2.7.6/MathJax.js', 'https://cdnjs.loli.net/ajax/libs/pace/1.0.2/pace.min.js', 'https://cdnjs.loli.net/ajax/libs/KaTeX/0.11.1/katex.min.js', 'https://cdnjs.loli.net/ajax/libs/clipboard.js/2.0.6/clipboard.min.js', 'https://cdn.jsdelivr.net/npm/disqusjs@1.2.6/dist/disqus.min.js', 'https://cdnjs.loli.net/ajax/libs/algoliasearch/4.0.3/algoliasearch-lite.umd.js', 'https://cdnjs.loli.net/ajax/libs/instantsearch.js/4.3.1/instantsearch.production.min.js', 'https://cdnjs.loli.net/ajax/libs/cookieconsent/3.1.1/cookieconsent.min.js', 'https://
|
|
44
|
+
const expected = ['https://cdnjs.loli.net/ajax/libs/jquery/3.0.0/jquery.min.js', 'https://cdnjs.loli.net/ajax/libs/moment.js/2.24.0/moment.min.js', 'https://cdnjs.loli.net/ajax/libs/outdated-browser/1.1.5/outdatedbrowser.min.js', 'https://cdnjs.loli.net/ajax/libs/highlight.js/9.18.1/styles/a11y-dark.min.css', 'https://cdnjs.loli.net/ajax/libs/mathjax/2.7.6/MathJax.js', 'https://cdnjs.loli.net/ajax/libs/pace/1.0.2/pace.min.js', 'https://cdnjs.loli.net/ajax/libs/KaTeX/0.11.1/katex.min.js', 'https://cdnjs.loli.net/ajax/libs/clipboard.js/2.0.6/clipboard.min.js', 'https://cdn.jsdelivr.net/npm/disqusjs@1.2.6/dist/disqus.min.js', 'https://cdnjs.loli.net/ajax/libs/algoliasearch/4.0.3/algoliasearch-lite.umd.js', 'https://cdnjs.loli.net/ajax/libs/instantsearch.js/4.3.1/instantsearch.production.min.js', 'https://cdnjs.loli.net/ajax/libs/cookieconsent/3.1.1/cookieconsent.min.js', 'https://cdnjs.loli.net/ajax/libs/waline/1.5.4/Waline.min.js', 'https://cdnjs.loli.net/ajax/libs/example/1.0.0/example.js'];
|
|
45
45
|
cases.forEach((func, i) => expect(func()).toBe(expected[i]));
|
|
46
46
|
});
|
|
47
47
|
test('bootcdn', () => {
|
|
48
48
|
hexo.config.providers = {
|
|
49
49
|
cdn: 'bootcdn'
|
|
50
50
|
};
|
|
51
|
-
const expected = ['https://cdn.bootcdn.net/ajax/libs/jquery/3.0.0/jquery.min.js', 'https://cdn.bootcdn.net/ajax/libs/moment.js/2.24.0/moment.min.js', 'https://cdn.bootcdn.net/ajax/libs/outdated-browser/1.1.5/outdatedbrowser.min.js', 'https://cdn.bootcdn.net/ajax/libs/highlight.js/9.18.1/styles/a11y-dark.min.css', 'https://cdn.bootcdn.net/ajax/libs/mathjax/2.7.6/MathJax.js', 'https://cdn.bootcdn.net/ajax/libs/pace/1.0.2/pace.min.js', 'https://cdn.bootcdn.net/ajax/libs/KaTeX/0.11.1/katex.min.js', 'https://cdn.bootcdn.net/ajax/libs/clipboard.js/2.0.6/clipboard.min.js', 'https://cdn.jsdelivr.net/npm/disqusjs@1.2.6/dist/disqus.min.js', 'https://cdn.bootcdn.net/ajax/libs/algoliasearch/4.0.3/algoliasearch-lite.umd.js', 'https://cdn.bootcdn.net/ajax/libs/instantsearch.js/4.3.1/instantsearch.production.min.js', 'https://cdn.bootcdn.net/ajax/libs/cookieconsent/3.1.1/cookieconsent.min.js', 'https://cdn.
|
|
51
|
+
const expected = ['https://cdn.bootcdn.net/ajax/libs/jquery/3.0.0/jquery.min.js', 'https://cdn.bootcdn.net/ajax/libs/moment.js/2.24.0/moment.min.js', 'https://cdn.bootcdn.net/ajax/libs/outdated-browser/1.1.5/outdatedbrowser.min.js', 'https://cdn.bootcdn.net/ajax/libs/highlight.js/9.18.1/styles/a11y-dark.min.css', 'https://cdn.bootcdn.net/ajax/libs/mathjax/2.7.6/MathJax.js', 'https://cdn.bootcdn.net/ajax/libs/pace/1.0.2/pace.min.js', 'https://cdn.bootcdn.net/ajax/libs/KaTeX/0.11.1/katex.min.js', 'https://cdn.bootcdn.net/ajax/libs/clipboard.js/2.0.6/clipboard.min.js', 'https://cdn.jsdelivr.net/npm/disqusjs@1.2.6/dist/disqus.min.js', 'https://cdn.bootcdn.net/ajax/libs/algoliasearch/4.0.3/algoliasearch-lite.umd.js', 'https://cdn.bootcdn.net/ajax/libs/instantsearch.js/4.3.1/instantsearch.production.min.js', 'https://cdn.bootcdn.net/ajax/libs/cookieconsent/3.1.1/cookieconsent.min.js', 'https://cdn.bootcdn.net/ajax/libs/waline/1.5.4/Waline.min.js', 'https://cdn.bootcdn.net/ajax/libs/example/1.0.0/example.js'];
|
|
52
52
|
cases.forEach((func, i) => expect(func()).toBe(expected[i]));
|
|
53
53
|
});
|
|
54
54
|
test('75cdn', () => {
|
|
55
55
|
hexo.config.providers = {
|
|
56
56
|
cdn: '75cdn'
|
|
57
57
|
};
|
|
58
|
-
const expected = ['https://lib.baomitu.com/jquery/3.0.0/jquery.min.js', 'https://lib.baomitu.com/moment.js/2.24.0/moment.min.js', 'https://lib.baomitu.com/outdated-browser/1.1.5/outdatedbrowser.min.js', 'https://lib.baomitu.com/highlight.js/9.18.1/styles/a11y-dark.min.css', 'https://lib.baomitu.com/mathjax/2.7.6/MathJax.js', 'https://lib.baomitu.com/pace/1.0.2/pace.min.js', 'https://lib.baomitu.com/KaTeX/0.11.1/katex.min.js', 'https://lib.baomitu.com/clipboard.js/2.0.6/clipboard.min.js', 'https://cdn.jsdelivr.net/npm/disqusjs@1.2.6/dist/disqus.min.js', 'https://lib.baomitu.com/algoliasearch/4.0.3/algoliasearch-lite.umd.js', 'https://lib.baomitu.com/instantsearch.js/4.3.1/instantsearch.production.min.js', 'https://lib.baomitu.com/cookieconsent/3.1.1/cookieconsent.min.js', 'https://
|
|
58
|
+
const expected = ['https://lib.baomitu.com/jquery/3.0.0/jquery.min.js', 'https://lib.baomitu.com/moment.js/2.24.0/moment.min.js', 'https://lib.baomitu.com/outdated-browser/1.1.5/outdatedbrowser.min.js', 'https://lib.baomitu.com/highlight.js/9.18.1/styles/a11y-dark.min.css', 'https://lib.baomitu.com/mathjax/2.7.6/MathJax.js', 'https://lib.baomitu.com/pace/1.0.2/pace.min.js', 'https://lib.baomitu.com/KaTeX/0.11.1/katex.min.js', 'https://lib.baomitu.com/clipboard.js/2.0.6/clipboard.min.js', 'https://cdn.jsdelivr.net/npm/disqusjs@1.2.6/dist/disqus.min.js', 'https://lib.baomitu.com/algoliasearch/4.0.3/algoliasearch-lite.umd.js', 'https://lib.baomitu.com/instantsearch.js/4.3.1/instantsearch.production.min.js', 'https://lib.baomitu.com/cookieconsent/3.1.1/cookieconsent.min.js', 'https://lib.baomitu.com/waline/1.5.4/Waline.min.js', 'https://lib.baomitu.com/example/1.0.0/example.js'];
|
|
59
59
|
cases.forEach((func, i) => expect(func()).toBe(expected[i]));
|
|
60
60
|
});
|
|
61
61
|
test('Custom CDN', () => {
|
|
62
62
|
hexo.config.providers = {
|
|
63
63
|
cdn: 'https://my.cdn/${ package }@${ version }/${ filename }'
|
|
64
64
|
};
|
|
65
|
-
const expected = ['https://my.cdn/jquery@3.0.0/dist/jquery.min.js', 'https://my.cdn/moment@2.24.0/min/moment.min.js', 'https://my.cdn/outdatedbrowser@1.1.5/outdatedbrowser/outdatedbrowser.min.js', 'https://my.cdn/highlight.js@9.18.1/styles/a11y-dark.css', 'https://my.cdn/mathjax@2.7.6/unpacked/MathJax.min.js', 'https://my.cdn/pace-js@1.0.2/pace.min.js', 'https://my.cdn/katex@0.11.1/dist/katex.min.js', 'https://my.cdn/clipboard@2.0.6/dist/clipboard.min.js', 'https://my.cdn/disqusjs@1.2.6/dist/disqus.min.js', 'https://my.cdn/algoliasearch@4.0.3/dist/algoliasearch-lite.umd.js', 'https://my.cdn/instantsearch.js@4.3.1/dist/instantsearch.production.min.js', 'https://my.cdn/cookieconsent@3.1.1/build/cookieconsent.min.js', 'https://my.cdn/@waline/client@1.
|
|
65
|
+
const expected = ['https://my.cdn/jquery@3.0.0/dist/jquery.min.js', 'https://my.cdn/moment@2.24.0/min/moment.min.js', 'https://my.cdn/outdatedbrowser@1.1.5/outdatedbrowser/outdatedbrowser.min.js', 'https://my.cdn/highlight.js@9.18.1/styles/a11y-dark.css', 'https://my.cdn/mathjax@2.7.6/unpacked/MathJax.min.js', 'https://my.cdn/pace-js@1.0.2/pace.min.js', 'https://my.cdn/katex@0.11.1/dist/katex.min.js', 'https://my.cdn/clipboard@2.0.6/dist/clipboard.min.js', 'https://my.cdn/disqusjs@1.2.6/dist/disqus.min.js', 'https://my.cdn/algoliasearch@4.0.3/dist/algoliasearch-lite.umd.js', 'https://my.cdn/instantsearch.js@4.3.1/dist/instantsearch.production.min.js', 'https://my.cdn/cookieconsent@3.1.1/build/cookieconsent.min.js', 'https://my.cdn/@waline/client@1.5.4/dist/Waline.min.js', 'https://my.cdn/example@1.0.0/example.js'];
|
|
66
66
|
cases.forEach((func, i) => expect(func()).toBe(expected[i]));
|
|
67
67
|
});
|
|
68
68
|
test('Custom CDN.js-style CDN', () => {
|
|
69
69
|
hexo.config.providers = {
|
|
70
70
|
cdn: '[cdnjs]https://my.cdn/ajax/libs/${ package }/${ version }/${ filename }'
|
|
71
71
|
};
|
|
72
|
-
const expected = ['https://my.cdn/ajax/libs/jquery/3.0.0/jquery.min.js', 'https://my.cdn/ajax/libs/moment.js/2.24.0/moment.min.js', 'https://my.cdn/ajax/libs/outdated-browser/1.1.5/outdatedbrowser.min.js', 'https://my.cdn/ajax/libs/highlight.js/9.18.1/styles/a11y-dark.min.css', 'https://my.cdn/ajax/libs/mathjax/2.7.6/MathJax.js', 'https://my.cdn/ajax/libs/pace/1.0.2/pace.min.js', 'https://my.cdn/ajax/libs/KaTeX/0.11.1/katex.min.js', 'https://my.cdn/ajax/libs/clipboard.js/2.0.6/clipboard.min.js', 'https://cdn.jsdelivr.net/npm/disqusjs@1.2.6/dist/disqus.min.js', 'https://my.cdn/ajax/libs/algoliasearch/4.0.3/algoliasearch-lite.umd.js', 'https://my.cdn/ajax/libs/instantsearch.js/4.3.1/instantsearch.production.min.js', 'https://my.cdn/ajax/libs/cookieconsent/3.1.1/cookieconsent.min.js', 'https://cdn
|
|
72
|
+
const expected = ['https://my.cdn/ajax/libs/jquery/3.0.0/jquery.min.js', 'https://my.cdn/ajax/libs/moment.js/2.24.0/moment.min.js', 'https://my.cdn/ajax/libs/outdated-browser/1.1.5/outdatedbrowser.min.js', 'https://my.cdn/ajax/libs/highlight.js/9.18.1/styles/a11y-dark.min.css', 'https://my.cdn/ajax/libs/mathjax/2.7.6/MathJax.js', 'https://my.cdn/ajax/libs/pace/1.0.2/pace.min.js', 'https://my.cdn/ajax/libs/KaTeX/0.11.1/katex.min.js', 'https://my.cdn/ajax/libs/clipboard.js/2.0.6/clipboard.min.js', 'https://cdn.jsdelivr.net/npm/disqusjs@1.2.6/dist/disqus.min.js', 'https://my.cdn/ajax/libs/algoliasearch/4.0.3/algoliasearch-lite.umd.js', 'https://my.cdn/ajax/libs/instantsearch.js/4.3.1/instantsearch.production.min.js', 'https://my.cdn/ajax/libs/cookieconsent/3.1.1/cookieconsent.min.js', 'https://my.cdn/ajax/libs/waline/1.5.4/Waline.min.js', 'https://my.cdn/ajax/libs/example/1.0.0/example.js'];
|
|
73
73
|
cases.forEach((func, i) => expect(func()).toBe(expected[i]));
|
|
74
74
|
});
|
|
75
75
|
});
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Register custom Hexo tag {% message %}.
|
|
3
|
+
* @module hexo/tag/message
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Register custom Hexo tag {% message %}.
|
|
8
|
+
* <p>
|
|
9
|
+
* This tag is rendered as a Bulma message box.
|
|
10
|
+
*
|
|
11
|
+
* <h5>Tag Parameters:<h5>
|
|
12
|
+
* <table class="params">
|
|
13
|
+
* <tr>
|
|
14
|
+
* <th>Name</th>
|
|
15
|
+
* <th>Type</th>
|
|
16
|
+
* <th class="description">Description</th>
|
|
17
|
+
* </tr>
|
|
18
|
+
* <tr>
|
|
19
|
+
* <td class="name"><code>color</code></td>
|
|
20
|
+
* <td class="type"><span class="param-type"><code>string</code></span></td>
|
|
21
|
+
* <td class="description">[Optional] Color of the message. Available values are: dark, primary, link, info, success, warning, danger.</td>
|
|
22
|
+
* </tr>
|
|
23
|
+
* <tr>
|
|
24
|
+
* <td class="name"><code>icon</code></td>
|
|
25
|
+
* <td class="type"><span class="param-type"><code>string</code></span></td>
|
|
26
|
+
* <td class="description">[Optional] Icon shown in the message header. Use FontAwesome icon class name for this field.</td>
|
|
27
|
+
* </tr>
|
|
28
|
+
* <tr>
|
|
29
|
+
* <td class="name"><code>title</code></td>
|
|
30
|
+
* <td class="type"><span class="param-type"><code>string</code></span></td>
|
|
31
|
+
* <td class="description">[Optional] Message title in the message header. Markdown is supported.</td>
|
|
32
|
+
* </tr>
|
|
33
|
+
* <tr>
|
|
34
|
+
* <td class="name"><code>size</code></td>
|
|
35
|
+
* <td class="type"><span class="param-type"><code>string</code></span></td>
|
|
36
|
+
* <td class="description last">[Optional] Size of the message box. Available values are: small, medium, large. Default size is normal.</td>
|
|
37
|
+
* </tr>
|
|
38
|
+
* </table>
|
|
39
|
+
*
|
|
40
|
+
* @see https://bulma.io/documentation/components/message/.
|
|
41
|
+
*
|
|
42
|
+
* @param {Hexo} hexo The Hexo instance.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* {% message color:warning 'icon:fas fa-info-circle' 'title:*ATTENTION*' size:small %}
|
|
46
|
+
* **This is a warning message.**
|
|
47
|
+
* {% endmessage %}
|
|
48
|
+
*/
|
|
49
|
+
module.exports = function (hexo) {
|
|
50
|
+
function processTag(options, content) {
|
|
51
|
+
let icon = '';
|
|
52
|
+
let title = '';
|
|
53
|
+
let classes = '';
|
|
54
|
+
let header = '';
|
|
55
|
+
|
|
56
|
+
for (const option of options) {
|
|
57
|
+
const [key, value] = option.split(':');
|
|
58
|
+
|
|
59
|
+
switch (key) {
|
|
60
|
+
case 'size':
|
|
61
|
+
classes += ` is-${value}`;
|
|
62
|
+
break;
|
|
63
|
+
|
|
64
|
+
case 'color':
|
|
65
|
+
classes += ` is-${value}`;
|
|
66
|
+
break;
|
|
67
|
+
|
|
68
|
+
case 'icon':
|
|
69
|
+
icon = `<i class="${value} mr-2"></i>`;
|
|
70
|
+
break;
|
|
71
|
+
|
|
72
|
+
case 'title':
|
|
73
|
+
title = value;
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (icon !== '' || title !== '') {
|
|
79
|
+
const inner = hexo.render.renderSync({
|
|
80
|
+
text: icon + title,
|
|
81
|
+
engine: 'markdown'
|
|
82
|
+
});
|
|
83
|
+
header = `<div class="message-header">${inner}</div>`;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return `<article class="message${classes}">
|
|
87
|
+
${header}
|
|
88
|
+
<div class="message-body">
|
|
89
|
+
${hexo.render.renderSync({
|
|
90
|
+
text: content,
|
|
91
|
+
engine: 'markdown'
|
|
92
|
+
})}
|
|
93
|
+
</div>
|
|
94
|
+
</article>`;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
hexo.extend.tag.register('message', processTag, {
|
|
98
|
+
ends: true
|
|
99
|
+
});
|
|
100
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
const {
|
|
2
|
+
join
|
|
3
|
+
} = require('path');
|
|
4
|
+
|
|
5
|
+
const Hexo = require('hexo');
|
|
6
|
+
|
|
7
|
+
const cheerio = require('cheerio');
|
|
8
|
+
|
|
9
|
+
const register = require('./message');
|
|
10
|
+
|
|
11
|
+
const rootDir = join(__dirname, '../../../fixture/site');
|
|
12
|
+
const hexo = new Hexo(rootDir, {
|
|
13
|
+
silent: true
|
|
14
|
+
});
|
|
15
|
+
const cheerioOptions = {
|
|
16
|
+
xml: {
|
|
17
|
+
normalizeWhitespace: true
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
beforeAll(async () => {
|
|
21
|
+
await hexo.init();
|
|
22
|
+
await hexo.load();
|
|
23
|
+
register(hexo);
|
|
24
|
+
await hexo.loadPlugin(require.resolve('hexo-renderer-marked'));
|
|
25
|
+
});
|
|
26
|
+
test('create default message', async () => {
|
|
27
|
+
const render = hexo.extend.tag.render.bind(hexo.extend.tag);
|
|
28
|
+
let source = '{% message %}**content**{% endmessage %}';
|
|
29
|
+
let actual = cheerio.load(await render(source), cheerioOptions, false).html();
|
|
30
|
+
expect(actual).toEqual('<article class="message"> <div class="message-body"> ' + '<p><strong>content</strong></p> </div> </article>');
|
|
31
|
+
source = '{% message %}\n# title\n{% endmessage %}';
|
|
32
|
+
actual = cheerio.load(await render(source), cheerioOptions, false).html();
|
|
33
|
+
expect(actual).toEqual('<article class="message"> <div class="message-body"> ' + '<h1 id="title"><a href="#title" class="headerlink" title="title"/>title</h1> ' + '</div> </article>');
|
|
34
|
+
});
|
|
35
|
+
test('create message with different colors', async () => {
|
|
36
|
+
const render = hexo.extend.tag.render.bind(hexo.extend.tag);
|
|
37
|
+
|
|
38
|
+
for (const color of ['dark', 'primary', 'link', 'info', 'success', 'warning', 'danger']) {
|
|
39
|
+
const source = `{% message color:${color} %}content{% endmessage %}`;
|
|
40
|
+
const actual = cheerio.load(await render(source), cheerioOptions, false).html();
|
|
41
|
+
expect(actual).toEqual(`<article class="message is-${color}"> <div class="message-body"> <p>content</p> ` + '</div> </article>');
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
test('create message with different sizes', async () => {
|
|
45
|
+
const render = hexo.extend.tag.render.bind(hexo.extend.tag);
|
|
46
|
+
|
|
47
|
+
for (const size of ['small', 'medium', 'large']) {
|
|
48
|
+
const source = `{% message size:${size} %}content{% endmessage %}`;
|
|
49
|
+
const actual = cheerio.load(await render(source), cheerioOptions, false).html();
|
|
50
|
+
expect(actual).toEqual(`<article class="message is-${size}"> <div class="message-body"> <p>content</p> ` + '</div> </article>');
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
test('create message with an icon', async () => {
|
|
54
|
+
const render = hexo.extend.tag.render.bind(hexo.extend.tag);
|
|
55
|
+
const source = '{% message "icon:fas fas-file" %}content{% endmessage %}';
|
|
56
|
+
const actual = cheerio.load(await render(source), cheerioOptions, false).html();
|
|
57
|
+
expect(actual).toEqual('<article class="message"> <div class="message-header"><p>' + '<i class="fas fas-file mr-2"/></p> </div> <div class="message-body"> <p>content</p> ' + '</div> </article>');
|
|
58
|
+
});
|
|
59
|
+
test('create message with a title', async () => {
|
|
60
|
+
const render = hexo.extend.tag.render.bind(hexo.extend.tag);
|
|
61
|
+
const source = '{% message "title:*message title*" %}content{% endmessage %}';
|
|
62
|
+
const actual = cheerio.load(await render(source), cheerioOptions, false).html();
|
|
63
|
+
expect(actual).toEqual('<article class="message"> <div class="message-header"><p>' + '<em>message title</em></p> </div> <div class="message-body"> <p>content</p> ' + '</div> </article>');
|
|
64
|
+
});
|
|
65
|
+
test('create message with all properties', async () => {
|
|
66
|
+
const render = hexo.extend.tag.render.bind(hexo.extend.tag);
|
|
67
|
+
const source = '{% message color:success size:small "icon:fas fas-file" ' + '"title:*message title*" %}content{% endmessage %}';
|
|
68
|
+
const actual = cheerio.load(await render(source), cheerioOptions, false).html();
|
|
69
|
+
expect(actual).toEqual('<article class="message is-success is-small"> <div class="message-header"><p>' + '<i class="fas fas-file mr-2"/><em>message title</em></p> </div> ' + '<div class="message-body"> <p>content</p> </div> </article>');
|
|
70
|
+
});
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Register custom Hexo tag {% tabs %}.
|
|
3
|
+
* @module hexo/tag/tabs
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Register custom Hexo tag {% tabs %}.
|
|
8
|
+
* <p>
|
|
9
|
+
* This tag is rendered as a Bulma tabs component.
|
|
10
|
+
* <p>
|
|
11
|
+
* Each individual tab must be wrapped with <code><!-- tab [...tab_param] --><!-- endtab --></code>
|
|
12
|
+
*
|
|
13
|
+
* <h5>Tag Parameters:<h5>
|
|
14
|
+
* <table class="params">
|
|
15
|
+
* <tr>
|
|
16
|
+
* <th>Name</th>
|
|
17
|
+
* <th>Type</th>
|
|
18
|
+
* <th class="description">Description</th>
|
|
19
|
+
* </tr>
|
|
20
|
+
* <tr>
|
|
21
|
+
* <td class="name"><code>align</code></td>
|
|
22
|
+
* <td class="type"><span class="param-type"><code>string</code></span></td>
|
|
23
|
+
* <td class="description">[Optional] Alignment of the tabs. Available values are: left, centered, right, fullwidth. Default alignment is left.</td>
|
|
24
|
+
* </tr>
|
|
25
|
+
* <tr>
|
|
26
|
+
* <td class="name"><code>size</code></td>
|
|
27
|
+
* <td class="type"><span class="param-type"><code>string</code></span></td>
|
|
28
|
+
* <td class="description">[Optional] Size of the tabs. Available values are: small, medium, large. Default size is normal.</td>
|
|
29
|
+
* </tr>
|
|
30
|
+
* <tr>
|
|
31
|
+
* <td class="name"><code>style</code></td>
|
|
32
|
+
* <td class="type"><span class="param-type"><code>string</code></span></td>
|
|
33
|
+
* <td class="description">[Optional] Style of the tabs. Available values are: boxed, toggle, toggle-rounded. Default style is none.</td>
|
|
34
|
+
* </tr>
|
|
35
|
+
* </table>
|
|
36
|
+
*
|
|
37
|
+
* <h5>Tab Parameters:<h5>
|
|
38
|
+
* <table class="params">
|
|
39
|
+
* <tr>
|
|
40
|
+
* <th>Name</th>
|
|
41
|
+
* <th>Type</th>
|
|
42
|
+
* <th class="description">Description</th>
|
|
43
|
+
* </tr>
|
|
44
|
+
* <tr>
|
|
45
|
+
* <td class="name"><code>id</code></td>
|
|
46
|
+
* <td class="type"><span class="param-type"><code>string</code></span></td>
|
|
47
|
+
* <td class="description">[Optional] The ID of the current tab. This value must be unique on each page.</td>
|
|
48
|
+
* </tr>
|
|
49
|
+
* <tr>
|
|
50
|
+
* <td class="name"><code>active</code></td>
|
|
51
|
+
* <td class="type"><span class="param-type"><code>boolean</code></span></td>
|
|
52
|
+
* <td class="description">[Optional] Whether to show current tab by default. Only one of the tabs can be set to active.</td>
|
|
53
|
+
* </tr>
|
|
54
|
+
* <tr>
|
|
55
|
+
* <td class="name"><code>title</code></td>
|
|
56
|
+
* <td class="type"><span class="param-type"><code>string</code></span></td>
|
|
57
|
+
* <td class="description">[Optional] Title of the current tab.</td>
|
|
58
|
+
* </tr>
|
|
59
|
+
* <tr>
|
|
60
|
+
* <td class="name"><code>icon</code></td>
|
|
61
|
+
* <td class="type"><span class="param-type"><code>string</code></span></td>
|
|
62
|
+
* <td class="description">[Optional] Icon of the current tab. Use FontAwesome icon class name for this field.</td>
|
|
63
|
+
* </tr>
|
|
64
|
+
* </table>
|
|
65
|
+
*
|
|
66
|
+
* @see https://bulma.io/documentation/components/tabs/.
|
|
67
|
+
*
|
|
68
|
+
* @param {Hexo} hexo The Hexo instance.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* {% tabs align:fullwidth size:small style:toggle-rounded %}
|
|
72
|
+
* <!-- tab active id:tab_hello title:Hello -->
|
|
73
|
+
* This is hello.
|
|
74
|
+
* <!-- endtab -->
|
|
75
|
+
* <!-- tab id:tab_info 'icon:fas fa-info' 'title:Info Tab' -->This is info.<!-- endtab -->
|
|
76
|
+
* {% endmessage %}
|
|
77
|
+
*/
|
|
78
|
+
module.exports = function (hexo) {
|
|
79
|
+
function splitTabOptions(s) {
|
|
80
|
+
const options = [];
|
|
81
|
+
const EOL = -1;
|
|
82
|
+
let i = 0;
|
|
83
|
+
let state = 1;
|
|
84
|
+
let begin = 0;
|
|
85
|
+
|
|
86
|
+
while (i <= s.length) {
|
|
87
|
+
const c = i < s.length ? s.charAt(i) : '';
|
|
88
|
+
|
|
89
|
+
switch (state) {
|
|
90
|
+
case 1:
|
|
91
|
+
if (c === ' ') {
|
|
92
|
+
state = 1;
|
|
93
|
+
begin = i + 1;
|
|
94
|
+
} else if (c === '"') {
|
|
95
|
+
state = 2;
|
|
96
|
+
begin = i + 1;
|
|
97
|
+
} else if (c === "'") {
|
|
98
|
+
state = 4;
|
|
99
|
+
begin = i + 1;
|
|
100
|
+
} else if (c === '') {
|
|
101
|
+
state = EOL;
|
|
102
|
+
} else {
|
|
103
|
+
state = 7;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
break;
|
|
107
|
+
|
|
108
|
+
case 2:
|
|
109
|
+
if (c === '\\') {
|
|
110
|
+
state = 3;
|
|
111
|
+
} else if (c === '"') {
|
|
112
|
+
state = 6;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
break;
|
|
116
|
+
|
|
117
|
+
case 3:
|
|
118
|
+
state = 2;
|
|
119
|
+
break;
|
|
120
|
+
|
|
121
|
+
case 4:
|
|
122
|
+
if (c === '\\') {
|
|
123
|
+
state = 5;
|
|
124
|
+
} else if (c === "'") {
|
|
125
|
+
state = 6;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
break;
|
|
129
|
+
|
|
130
|
+
case 5:
|
|
131
|
+
state = 4;
|
|
132
|
+
break;
|
|
133
|
+
|
|
134
|
+
case 6:
|
|
135
|
+
options.push(s.substring(begin, i - 1));
|
|
136
|
+
begin = i + 1;
|
|
137
|
+
|
|
138
|
+
if (c === ' ') {
|
|
139
|
+
state = 1;
|
|
140
|
+
} else if (c === '') {
|
|
141
|
+
state = EOL;
|
|
142
|
+
} else {
|
|
143
|
+
throw new Error(`malformatted tab options: ${s}`);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
break;
|
|
147
|
+
|
|
148
|
+
case 7:
|
|
149
|
+
if (c === ' ') {
|
|
150
|
+
options.push(s.substring(begin, i));
|
|
151
|
+
begin = i + 1;
|
|
152
|
+
state = 1;
|
|
153
|
+
} else if (c === '') {
|
|
154
|
+
options.push(s.substring(begin, i));
|
|
155
|
+
begin = i + 1;
|
|
156
|
+
state = EOL;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
i++;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (state !== EOL) {
|
|
166
|
+
throw new Error(`malformatted tab options: ${s}`);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return options;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function processTag(options, content) {
|
|
173
|
+
let classes = '';
|
|
174
|
+
|
|
175
|
+
for (const option of options) {
|
|
176
|
+
const [key, value] = option.split(':');
|
|
177
|
+
|
|
178
|
+
switch (key) {
|
|
179
|
+
case 'align':
|
|
180
|
+
classes += ` is-${value}`;
|
|
181
|
+
break;
|
|
182
|
+
|
|
183
|
+
case 'size':
|
|
184
|
+
classes += ` is-${value}`;
|
|
185
|
+
break;
|
|
186
|
+
|
|
187
|
+
case 'style':
|
|
188
|
+
if (value === 'toggle-rounded') {
|
|
189
|
+
classes += ' is-toggle';
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
classes += ` is-${value}`;
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const pattern = /<!--\s*tab\s*(.*?)\s*-->([\s\S]*?)<!--\s*endtab\s*-->/g;
|
|
198
|
+
let match;
|
|
199
|
+
let tabElements = '';
|
|
200
|
+
let contentElements = '';
|
|
201
|
+
|
|
202
|
+
while ((match = pattern.exec(content)) !== null) {
|
|
203
|
+
const [, tabOptions, tabContent] = match;
|
|
204
|
+
let id = 'tab-' + Date.now() + (Math.random() * 1000 | 0);
|
|
205
|
+
let icon = '';
|
|
206
|
+
let title = '';
|
|
207
|
+
let active = false;
|
|
208
|
+
|
|
209
|
+
for (const option of splitTabOptions(tabOptions)) {
|
|
210
|
+
const [key, value] = option.split(':');
|
|
211
|
+
|
|
212
|
+
switch (key) {
|
|
213
|
+
case 'id':
|
|
214
|
+
id = value;
|
|
215
|
+
break;
|
|
216
|
+
|
|
217
|
+
case 'active':
|
|
218
|
+
active = true;
|
|
219
|
+
break;
|
|
220
|
+
|
|
221
|
+
case 'icon':
|
|
222
|
+
icon = `<span class="icon is-small ml-0">
|
|
223
|
+
<i class="${value}" aria-hidden="true"></i>
|
|
224
|
+
</span>`;
|
|
225
|
+
break;
|
|
226
|
+
|
|
227
|
+
case 'title':
|
|
228
|
+
title = value;
|
|
229
|
+
break;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
tabElements += `<li${active ? ' class="is-active"' : ''}>
|
|
234
|
+
<a href="#${id}">
|
|
235
|
+
${hexo.render.renderSync({
|
|
236
|
+
text: icon + title,
|
|
237
|
+
engine: 'markdown'
|
|
238
|
+
})}
|
|
239
|
+
</a>
|
|
240
|
+
</li>`;
|
|
241
|
+
contentElements += `<div id="${id}" class="tab-content${active ? '' : ' is-hidden'}">
|
|
242
|
+
${hexo.render.renderSync({
|
|
243
|
+
text: tabContent,
|
|
244
|
+
engine: 'markdown'
|
|
245
|
+
})}
|
|
246
|
+
</div>`;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return `<div class="tabs my-3${classes}">
|
|
250
|
+
<ul class="mx-0 my-0">
|
|
251
|
+
${tabElements}
|
|
252
|
+
</ul>
|
|
253
|
+
</div>
|
|
254
|
+
${contentElements}`;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const script = `<script>
|
|
258
|
+
(function () {
|
|
259
|
+
function switchTab() {
|
|
260
|
+
if (!location.hash) {
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
Array
|
|
264
|
+
.from(document.querySelectorAll('.tab-content'))
|
|
265
|
+
.forEach($tab => {
|
|
266
|
+
$tab.classList.add('is-hidden');
|
|
267
|
+
});
|
|
268
|
+
Array
|
|
269
|
+
.from(document.querySelectorAll('.tabs li'))
|
|
270
|
+
.forEach($tab => {
|
|
271
|
+
$tab.classList.remove('is-active');
|
|
272
|
+
});
|
|
273
|
+
const $activeTab = document.querySelector(location.hash);
|
|
274
|
+
if ($activeTab) {
|
|
275
|
+
$activeTab.classList.remove('is-hidden');
|
|
276
|
+
}
|
|
277
|
+
const $tabMenu = document.querySelector(\`a[href="\${location.hash}"]\`);
|
|
278
|
+
if ($tabMenu) {
|
|
279
|
+
$tabMenu.parentElement.classList.add('is-active');
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
switchTab();
|
|
283
|
+
window.addEventListener('hashchange', switchTab, false);
|
|
284
|
+
})();
|
|
285
|
+
</script>`;
|
|
286
|
+
hexo.extend.injector.register('head_end', script);
|
|
287
|
+
hexo.extend.tag.register('tabs', processTag, {
|
|
288
|
+
ends: true
|
|
289
|
+
});
|
|
290
|
+
};
|