hexo-component-inferno 3.1.2 → 4.1.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/asset/js/algolia.js +51 -10
- package/asset/js/google_cse.js +50 -7
- package/asset/js/insight.js +48 -7
- package/lib/hexo/filter/locals.js +2 -2
- package/lib/hexo/helper/cdn.js +10 -2
- package/lib/schema/comment/artalk.json +37 -0
- package/lib/schema/comment/beaudar.json +62 -0
- package/lib/schema/comment/cusdis.json +34 -0
- package/lib/schema/comment/giscus.json +7 -1
- package/lib/schema/comment/utterances.json +15 -1
- package/lib/schema/comment/valine.json +2 -2
- package/lib/schema/comment/waline.json +1 -1
- package/lib/schema/plugin/matomo.json +25 -0
- package/lib/schema/plugin/umami.json +25 -0
- package/lib/schema/plugin/waline_pageview.json +14 -0
- package/lib/schema/search/algolia.json +4 -0
- package/lib/schema/widget/archives.json +5 -0
- package/lib/schema/widget/categories.json +5 -0
- package/lib/schema/widget/tags.json +1 -1
- package/lib/util/appearance.js +40 -0
- package/lib/util/i18n.js +24 -0
- package/lib/util/script.js +110 -0
- package/lib/view/comment/artalk.js +118 -0
- package/lib/view/comment/beaudar.js +133 -0
- package/lib/view/comment/changyan.js +5 -5
- package/lib/view/comment/cusdis.js +119 -0
- package/lib/view/comment/disqus.js +1 -1
- package/lib/view/comment/disqusjs.js +6 -5
- package/lib/view/comment/facebook.js +1 -1
- package/lib/view/comment/giscus.js +32 -22
- package/lib/view/comment/gitalk.js +6 -5
- package/lib/view/comment/gitment.js +6 -5
- package/lib/view/comment/isso.js +7 -3
- package/lib/view/comment/livere.js +1 -1
- package/lib/view/comment/twikoo.js +3 -4
- package/lib/view/comment/utterances.js +26 -17
- package/lib/view/comment/valine.js +3 -6
- package/lib/view/comment/waline.js +16 -9
- package/lib/view/common/article_media.js +2 -2
- package/lib/view/donate/afdian.js +1 -1
- package/lib/view/donate/alipay.js +1 -1
- package/lib/view/donate/buymeacoffee.js +1 -1
- package/lib/view/donate/patreon.js +1 -1
- package/lib/view/donate/paypal.js +1 -1
- package/lib/view/donate/wechat.js +1 -1
- package/lib/view/misc/article_licensing.js +1 -1
- package/lib/view/misc/meta.js +1 -1
- package/lib/view/misc/open_graph.js +1 -1
- package/lib/view/misc/paginator.js +9 -5
- package/lib/view/misc/structured_data.js +1 -1
- package/lib/view/misc/web_app.js +2 -2
- package/lib/view/plugin/baidu_analytics.js +1 -1
- package/lib/view/plugin/bing_webmaster.js +1 -1
- package/lib/view/plugin/busuanzi.js +1 -1
- package/lib/view/plugin/cnzz.js +1 -1
- package/lib/view/plugin/cookie_consent.js +1 -1
- package/lib/view/plugin/gallery.js +2 -2
- package/lib/view/plugin/google_analytics.js +1 -1
- package/lib/view/plugin/hotjar.js +1 -1
- package/lib/view/plugin/katex.js +1 -1
- package/lib/view/plugin/mathjax.js +1 -1
- package/lib/view/plugin/matomo.js +89 -0
- package/lib/view/plugin/outdated_browser.js +1 -1
- package/lib/view/plugin/progressbar.js +1 -1
- package/lib/view/plugin/statcounter.js +1 -1
- package/lib/view/plugin/twitter_conversion_tracking.js +1 -1
- package/lib/view/plugin/umami.js +88 -0
- package/lib/view/plugin/waline_pageview.js +98 -0
- package/lib/view/search/algolia.js +11 -5
- package/lib/view/search/baidu.js +5 -3
- package/lib/view/search/google_cse.js +4 -2
- package/lib/view/search/insight.js +1 -1
- package/lib/view/share/addthis.js +1 -1
- package/lib/view/share/addtoany.js +1 -1
- package/lib/view/share/bdshare.js +1 -1
- package/lib/view/share/sharejs.js +1 -1
- package/lib/view/share/sharethis.js +1 -1
- package/lib/view/widget/adsense.js +1 -1
- package/lib/view/widget/archives.js +45 -12
- package/lib/view/widget/categories.js +23 -7
- package/lib/view/widget/followit.js +1 -1
- package/lib/view/widget/links.js +1 -1
- package/lib/view/widget/recent_posts.js +1 -1
- package/lib/view/widget/subscribe_email.js +1 -1
- package/lib/view/widget/tags.js +19 -6
- package/lib/view/widget/toc.js +1 -1
- package/package.json +10 -5
- package/lib/core/migrate.test.js +0 -48
- package/lib/core/schema.test.js +0 -520
- package/lib/core/view.test.js +0 -41
- package/lib/hexo/filter/locals.test.js +0 -118
- package/lib/hexo/generator/assets.test.js +0 -32
- package/lib/hexo/generator/categories.test.js +0 -41
- package/lib/hexo/generator/category.test.js +0 -84
- package/lib/hexo/generator/insight.test.js +0 -95
- package/lib/hexo/generator/manifest.test.js +0 -52
- package/lib/hexo/generator/tags.test.js +0 -41
- package/lib/hexo/helper/cdn.test.js +0 -128
- package/lib/hexo/helper/page.test.js +0 -62
- package/lib/hexo/tag/message.test.js +0 -72
- package/lib/hexo/tag/tabs.test.js +0 -98
- package/lib/schema/schema/comment/changyan.json +0 -21
- package/lib/schema/schema/comment/disqus.json +0 -17
- package/lib/schema/schema/comment/disqusjs.json +0 -53
- package/lib/schema/schema/comment/facebook.json +0 -13
- package/lib/schema/schema/comment/giscus.json +0 -105
- package/lib/schema/schema/comment/gitalk.json +0 -81
- package/lib/schema/schema/comment/gitment.json +0 -47
- package/lib/schema/schema/comment/isso.json +0 -17
- package/lib/schema/schema/comment/livere.json +0 -17
- package/lib/schema/schema/comment/twikoo.json +0 -28
- package/lib/schema/schema/comment/utterances.json +0 -59
- package/lib/schema/schema/comment/valine.json +0 -105
- package/lib/schema/schema/comment/waline.json +0 -176
- package/lib/schema/schema/donate/afdian.json +0 -17
- package/lib/schema/schema/donate/alipay.json +0 -17
- package/lib/schema/schema/donate/buymeacoffee.json +0 -17
- package/lib/schema/schema/donate/patreon.json +0 -17
- package/lib/schema/schema/donate/paypal.json +0 -22
- package/lib/schema/schema/donate/wechat.json +0 -17
- package/lib/schema/schema/misc/manifest.json +0 -66
- package/lib/schema/schema/misc/meta.json +0 -11
- package/lib/schema/schema/misc/open_graph.json +0 -78
- package/lib/schema/schema/misc/poly_links.json +0 -35
- package/lib/schema/schema/misc/structured_data.json +0 -47
- package/lib/schema/schema/plugin/baidu_analytics.json +0 -14
- package/lib/schema/schema/plugin/bing_webmaster.json +0 -14
- package/lib/schema/schema/plugin/busuanzi.json +0 -7
- package/lib/schema/schema/plugin/cnzz.json +0 -19
- package/lib/schema/schema/plugin/cookie_consent.json +0 -38
- package/lib/schema/schema/plugin/gallery.json +0 -7
- package/lib/schema/schema/plugin/google_analytics.json +0 -14
- package/lib/schema/schema/plugin/hotjar.json +0 -14
- package/lib/schema/schema/plugin/katex.json +0 -7
- package/lib/schema/schema/plugin/mathjax.json +0 -7
- package/lib/schema/schema/plugin/outdated_browser.json +0 -7
- package/lib/schema/schema/plugin/progressbar.json +0 -7
- package/lib/schema/schema/plugin/statcounter.json +0 -19
- package/lib/schema/schema/plugin/twitter_conversion_tracking.json +0 -14
- package/lib/schema/schema/search/algolia.json +0 -13
- package/lib/schema/schema/search/baidu.json +0 -13
- package/lib/schema/schema/search/google_cse.json +0 -17
- package/lib/schema/schema/search/insight.json +0 -19
- package/lib/schema/schema/share/addthis.json +0 -17
- package/lib/schema/schema/share/addtoany.json +0 -13
- package/lib/schema/schema/share/bdshare.json +0 -13
- package/lib/schema/schema/share/sharejs.json +0 -13
- package/lib/schema/schema/share/sharethis.json +0 -17
- package/lib/schema/schema/widget/adsense.json +0 -21
- package/lib/schema/schema/widget/archives.json +0 -13
- package/lib/schema/schema/widget/categories.json +0 -13
- package/lib/schema/schema/widget/followit.json +0 -26
- package/lib/schema/schema/widget/links.json +0 -47
- package/lib/schema/schema/widget/recent_posts.json +0 -13
- package/lib/schema/schema/widget/subscribe_email.json +0 -22
- package/lib/schema/schema/widget/tags.json +0 -30
- package/lib/schema/schema/widget/toc.json +0 -31
- package/lib/util/cache.test.js +0 -24
- package/lib/util/classname.test.js +0 -13
- package/lib/util/yaml.test.js +0 -18
- package/lib/view/widget/toc.test.js +0 -30
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const util = require('util');
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const yaml = require('js-yaml');
|
|
5
|
-
const Hexo = require('hexo');
|
|
6
|
-
const register = require('./locals');
|
|
7
|
-
const rootDir = path.join(__dirname, '../../../fixture/site');
|
|
8
|
-
const hexo = new Hexo(rootDir, {
|
|
9
|
-
silent: true
|
|
10
|
-
});
|
|
11
|
-
const regex = new RegExp(/\[Function: bound (.*)\]/gi);
|
|
12
|
-
let siteConfig, themeConfig, pageConfigInSiteDir, postConfigInSiteDir, pageConfigInThemeDir, postConfigInThemeDir;
|
|
13
|
-
const basePageConfig = {
|
|
14
|
-
title: 'about',
|
|
15
|
-
comments: false,
|
|
16
|
-
int: 10000,
|
|
17
|
-
float: 0.0001,
|
|
18
|
-
bool: true,
|
|
19
|
-
str: '10000',
|
|
20
|
-
empty: null,
|
|
21
|
-
arr: [10000, 20000, 30000],
|
|
22
|
-
obj: {
|
|
23
|
-
field: 10000
|
|
24
|
-
},
|
|
25
|
-
int_ex: 10000,
|
|
26
|
-
float_ex: 0.0001,
|
|
27
|
-
bool_ex: true,
|
|
28
|
-
str_ex: '10000',
|
|
29
|
-
empty_ex: null,
|
|
30
|
-
arr_ex: [10000, 20000, 30000],
|
|
31
|
-
obj_ex: {
|
|
32
|
-
field: 10000
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
beforeAll(async () => {
|
|
36
|
-
await hexo.init();
|
|
37
|
-
await hexo.load();
|
|
38
|
-
siteConfig = yaml.load(fs.readFileSync(path.join(hexo.base_dir, '_config.yml')));
|
|
39
|
-
themeConfig = yaml.load(fs.readFileSync(path.join(hexo.theme_dir, '_config.yml')));
|
|
40
|
-
pageConfigInSiteDir = yaml.load(fs.readFileSync(path.join(hexo.base_dir, '_config.page.yml')));
|
|
41
|
-
postConfigInSiteDir = yaml.load(fs.readFileSync(path.join(hexo.base_dir, '_config.post.yml')));
|
|
42
|
-
pageConfigInThemeDir = yaml.load(fs.readFileSync(path.join(hexo.theme_dir, '_config.page.yml')));
|
|
43
|
-
postConfigInThemeDir = yaml.load(fs.readFileSync(path.join(hexo.theme_dir, '_config.post.yml')));
|
|
44
|
-
register(hexo);
|
|
45
|
-
});
|
|
46
|
-
test('Register all helper functions to "locals.helper"', async () => {
|
|
47
|
-
const Locals = hexo._generateLocals();
|
|
48
|
-
const helpers = hexo.extend.helper.list();
|
|
49
|
-
const locals = await hexo.extend.filter.exec('template_locals', new Locals('about/index.html'), {
|
|
50
|
-
context: hexo
|
|
51
|
-
});
|
|
52
|
-
expect(Object.keys(locals.helper).sort()).toEqual(Object.keys(helpers).concat('__', '_p').sort());
|
|
53
|
-
for (const name in locals.helper) {
|
|
54
|
-
expect(typeof locals.helper[name]).toBe('function');
|
|
55
|
-
const match = regex.exec(util.inspect(locals.helper[name]));
|
|
56
|
-
if (match && match.length > 1) {
|
|
57
|
-
expect(match[1]).toBe(helpers[name].name);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
test('Correctly merge theme config with site config', async () => {
|
|
62
|
-
const Locals = hexo._generateLocals();
|
|
63
|
-
const locals = await hexo.extend.filter.exec('template_locals', new Locals('about/index.html'), {
|
|
64
|
-
context: hexo
|
|
65
|
-
});
|
|
66
|
-
expect(locals.config.title).toBe(themeConfig.title);
|
|
67
|
-
expect(locals.config.int).toBe(themeConfig.int);
|
|
68
|
-
expect(locals.config.float).toBe(themeConfig.float);
|
|
69
|
-
expect(locals.config.bool).toBe(themeConfig.bool);
|
|
70
|
-
expect(locals.config.str).toBe(themeConfig.str);
|
|
71
|
-
expect(locals.config.empty).toBe(themeConfig.empty);
|
|
72
|
-
expect(locals.config.arr).toEqual(themeConfig.arr);
|
|
73
|
-
expect(locals.config.obj).toEqual(themeConfig.obj);
|
|
74
|
-
expect(locals.config.theme).toEqual(siteConfig.theme);
|
|
75
|
-
});
|
|
76
|
-
test('Page/post layout configs override theme and site configs', async () => {
|
|
77
|
-
const Locals = hexo._generateLocals();
|
|
78
|
-
const configs = [Object.assign({}, basePageConfig, {
|
|
79
|
-
layout: 'page'
|
|
80
|
-
}), Object.assign({}, basePageConfig, {
|
|
81
|
-
layout: 'post'
|
|
82
|
-
})];
|
|
83
|
-
for (const page of configs) {
|
|
84
|
-
const locals = await hexo.extend.filter.exec('template_locals', new Locals('about/index.html', page), {
|
|
85
|
-
context: hexo
|
|
86
|
-
});
|
|
87
|
-
expect(locals.config.comments).toBeUndefined();
|
|
88
|
-
// theme page/post layout configs override ones under site root
|
|
89
|
-
const keys = ['title', 'int', 'float', 'bool', 'str', 'empty', 'arr', 'obj'];
|
|
90
|
-
for (const key of keys) {
|
|
91
|
-
expect(locals.config[key]).toEqual(page.layout === 'page' ? pageConfigInThemeDir[key] : postConfigInThemeDir[key]);
|
|
92
|
-
}
|
|
93
|
-
const keysEx = ['title_ex', 'int_ex', 'float_ex', 'bool_ex', 'str_ex', 'empty_ex', 'arr_ex', 'obj_ex'];
|
|
94
|
-
for (const key of keysEx) {
|
|
95
|
-
expect(locals.config[key]).toEqual(page.layout === 'page' ? pageConfigInSiteDir[key] : postConfigInSiteDir[key]);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
test('Configs in page/post front-matter override all other config sources', async () => {
|
|
100
|
-
const Locals = hexo._generateLocals();
|
|
101
|
-
const configs = [Object.assign({}, basePageConfig, {
|
|
102
|
-
__page: true,
|
|
103
|
-
layout: 'page'
|
|
104
|
-
}), Object.assign({}, basePageConfig, {
|
|
105
|
-
__post: true,
|
|
106
|
-
layout: 'post'
|
|
107
|
-
})];
|
|
108
|
-
for (const page of configs) {
|
|
109
|
-
const locals = await hexo.extend.filter.exec('template_locals', new Locals('about/index.html', page), {
|
|
110
|
-
context: hexo
|
|
111
|
-
});
|
|
112
|
-
expect(locals.config.title).toBe(page.layout === 'page' ? pageConfigInThemeDir.title : postConfigInThemeDir.title);
|
|
113
|
-
expect(locals.config.comments).toBeUndefined();
|
|
114
|
-
['int', 'float', 'bool', 'str', 'empty', 'arr', 'obj', 'int_ex', 'float_ex', 'bool_ex', 'str_ex', 'empty_ex', 'arr_ex', 'obj_ex'].forEach(key => {
|
|
115
|
-
expect(locals.config[key]).toEqual(page[key]);
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
});
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
const {
|
|
2
|
-
readFileSync
|
|
3
|
-
} = require('fs');
|
|
4
|
-
const {
|
|
5
|
-
join
|
|
6
|
-
} = require('path');
|
|
7
|
-
const Hexo = require('hexo');
|
|
8
|
-
const register = require('./assets');
|
|
9
|
-
const rootDir = join(__dirname, '../../../fixture/site');
|
|
10
|
-
const assetsDir = join(__dirname, '../../../asset');
|
|
11
|
-
const hexo = new Hexo(rootDir, {
|
|
12
|
-
silent: true
|
|
13
|
-
});
|
|
14
|
-
beforeAll(async () => {
|
|
15
|
-
await hexo.init();
|
|
16
|
-
await hexo.load();
|
|
17
|
-
register(hexo);
|
|
18
|
-
});
|
|
19
|
-
test("Export files from asset/ folder that are not in theme's source folder", async () => {
|
|
20
|
-
const locals = hexo.locals.toObject();
|
|
21
|
-
const generator = hexo.extend.generator.get('static_assets').bind(hexo);
|
|
22
|
-
const result = await generator(locals);
|
|
23
|
-
['/js/algolia.js', '/js/google_cse.js'].forEach(file => {
|
|
24
|
-
expect(result.find(route => route.path === file)).not.toBeUndefined();
|
|
25
|
-
expect(result.find(route => route.path === file).data).toBe(readFileSync(join(assetsDir, file), {
|
|
26
|
-
encoding: 'utf-8'
|
|
27
|
-
}));
|
|
28
|
-
});
|
|
29
|
-
['/js/insight.js', '/js/.eslintrc.json'].forEach(file => {
|
|
30
|
-
expect(result.find(route => route.path === file)).toBeUndefined();
|
|
31
|
-
});
|
|
32
|
-
});
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const Hexo = require('hexo');
|
|
3
|
-
const register = require('./categories');
|
|
4
|
-
const rootDir = path.join(__dirname, '../../../fixture/site');
|
|
5
|
-
const hexo = new Hexo(rootDir, {
|
|
6
|
-
silent: true
|
|
7
|
-
});
|
|
8
|
-
const Page = hexo.model('Page');
|
|
9
|
-
const Post = hexo.model('Post');
|
|
10
|
-
let pages = [];
|
|
11
|
-
beforeAll(async () => {
|
|
12
|
-
await hexo.init();
|
|
13
|
-
pages = await Page.insert([{
|
|
14
|
-
source: 'bio/index.md',
|
|
15
|
-
path: 'bio/',
|
|
16
|
-
updated: 1e8 - 3
|
|
17
|
-
}, {
|
|
18
|
-
source: 'about/index.md',
|
|
19
|
-
path: 'about/',
|
|
20
|
-
updated: 1e8 - 4
|
|
21
|
-
}]);
|
|
22
|
-
pages.concat(await Post.insert([{
|
|
23
|
-
source: 'bar',
|
|
24
|
-
slug: 'bar',
|
|
25
|
-
updated: 1e8 + 1
|
|
26
|
-
}, {
|
|
27
|
-
source: 'baz',
|
|
28
|
-
slug: 'baz',
|
|
29
|
-
updated: 1e8 - 1
|
|
30
|
-
}]));
|
|
31
|
-
await hexo.load();
|
|
32
|
-
register(hexo);
|
|
33
|
-
});
|
|
34
|
-
test('Add /categories route and add a flag (__categories) to the locals', async () => {
|
|
35
|
-
const locals = hexo.locals.toObject();
|
|
36
|
-
const generator = hexo.extend.generator.get('categories').bind(hexo);
|
|
37
|
-
const result = await generator(locals);
|
|
38
|
-
expect(result.path).toBe('categories/');
|
|
39
|
-
expect(result.layout).toEqual(['categories']);
|
|
40
|
-
expect(result.data.__categories).toBe(true);
|
|
41
|
-
});
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const Hexo = require('hexo');
|
|
3
|
-
const register = require('./category');
|
|
4
|
-
const rootDir = path.join(__dirname, '../../../fixture/site');
|
|
5
|
-
const hexo = new Hexo(rootDir, {
|
|
6
|
-
silent: true
|
|
7
|
-
});
|
|
8
|
-
const Post = hexo.model('Post');
|
|
9
|
-
let posts = [];
|
|
10
|
-
beforeAll(async () => {
|
|
11
|
-
await hexo.init();
|
|
12
|
-
posts = await Post.insert([{
|
|
13
|
-
title: 'foo',
|
|
14
|
-
source: 'foo',
|
|
15
|
-
slug: 'foo',
|
|
16
|
-
date: 1e8
|
|
17
|
-
}, {
|
|
18
|
-
title: 'bar',
|
|
19
|
-
source: 'bar',
|
|
20
|
-
slug: 'bar',
|
|
21
|
-
date: 1e8 + 1
|
|
22
|
-
}, {
|
|
23
|
-
title: 'baz',
|
|
24
|
-
source: 'baz',
|
|
25
|
-
slug: 'baz',
|
|
26
|
-
date: 1e8 - 1
|
|
27
|
-
}, {
|
|
28
|
-
title: 'boo',
|
|
29
|
-
source: 'boo',
|
|
30
|
-
slug: 'boo',
|
|
31
|
-
date: 1e8 + 2
|
|
32
|
-
}]);
|
|
33
|
-
await posts[0].setCategories(['foo']);
|
|
34
|
-
await posts[1].setCategories(['foo', 'bar']);
|
|
35
|
-
await posts[2].setCategories(['foo', 'bar', 'baz']);
|
|
36
|
-
await posts[3].setCategories(['baz', 'bar', 'foo']);
|
|
37
|
-
await hexo.load();
|
|
38
|
-
register(hexo);
|
|
39
|
-
});
|
|
40
|
-
test('Add /category/* routes and add parents array to the locals', async () => {
|
|
41
|
-
const locals = hexo.locals.toObject();
|
|
42
|
-
const generator = hexo.extend.generator.get('category').bind(hexo);
|
|
43
|
-
const result = await generator(locals);
|
|
44
|
-
expect(result.length).toBe(6);
|
|
45
|
-
for (const route of result) {
|
|
46
|
-
expect(route.layout).toStrictEqual(['category', 'archive', 'index']);
|
|
47
|
-
}
|
|
48
|
-
expect(result[0].path).toBe('categories/foo/');
|
|
49
|
-
expect(result[0].data.category).toBe('foo');
|
|
50
|
-
expect(result[0].data.posts.length).toBe(3);
|
|
51
|
-
expect(result[0].data.parents.length).toBe(0);
|
|
52
|
-
expect(result[1].path).toBe('categories/foo/bar/');
|
|
53
|
-
expect(result[1].data.category).toBe('bar');
|
|
54
|
-
expect(result[1].data.posts.length).toBe(2);
|
|
55
|
-
expect(result[1].data.parents.length).toBe(1);
|
|
56
|
-
expect(result[1].data.parents[0].name).toBe('foo');
|
|
57
|
-
expect(result[1].data.parents[0].path).toBe('categories/foo/');
|
|
58
|
-
expect(result[2].path).toBe('categories/foo/bar/baz/');
|
|
59
|
-
expect(result[2].data.category).toBe('baz');
|
|
60
|
-
expect(result[2].data.posts.length).toBe(1);
|
|
61
|
-
expect(result[2].data.parents.length).toBe(2);
|
|
62
|
-
expect(result[2].data.parents[0].name).toBe('foo');
|
|
63
|
-
expect(result[2].data.parents[0].path).toBe('categories/foo/');
|
|
64
|
-
expect(result[2].data.parents[1].name).toBe('bar');
|
|
65
|
-
expect(result[2].data.parents[1].path).toBe('categories/foo/bar/');
|
|
66
|
-
expect(result[3].path).toBe('categories/baz/');
|
|
67
|
-
expect(result[3].data.category).toBe('baz');
|
|
68
|
-
expect(result[3].data.posts.length).toBe(1);
|
|
69
|
-
expect(result[3].data.parents.length).toBe(0);
|
|
70
|
-
expect(result[4].path).toBe('categories/baz/bar/');
|
|
71
|
-
expect(result[4].data.category).toBe('bar');
|
|
72
|
-
expect(result[4].data.posts.length).toBe(1);
|
|
73
|
-
expect(result[4].data.parents.length).toBe(1);
|
|
74
|
-
expect(result[4].data.parents[0].name).toBe('baz');
|
|
75
|
-
expect(result[4].data.parents[0].path).toBe('categories/baz/');
|
|
76
|
-
expect(result[5].path).toBe('categories/baz/bar/foo/');
|
|
77
|
-
expect(result[5].data.category).toBe('foo');
|
|
78
|
-
expect(result[5].data.posts.length).toBe(1);
|
|
79
|
-
expect(result[5].data.parents.length).toBe(2);
|
|
80
|
-
expect(result[5].data.parents[0].name).toBe('baz');
|
|
81
|
-
expect(result[5].data.parents[0].path).toBe('categories/baz/');
|
|
82
|
-
expect(result[5].data.parents[1].name).toBe('bar');
|
|
83
|
-
expect(result[5].data.parents[1].path).toBe('categories/baz/bar/');
|
|
84
|
-
});
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
const {
|
|
2
|
-
join
|
|
3
|
-
} = require('path');
|
|
4
|
-
const Hexo = require('hexo');
|
|
5
|
-
const register = require('./insight');
|
|
6
|
-
const rootDir = join(__dirname, '../../../fixture/site');
|
|
7
|
-
const hexo = new Hexo(rootDir, {
|
|
8
|
-
silent: true
|
|
9
|
-
});
|
|
10
|
-
const Page = hexo.model('Page');
|
|
11
|
-
const Post = hexo.model('Post');
|
|
12
|
-
const Category = hexo.model('Category');
|
|
13
|
-
const Tag = hexo.model('Tag');
|
|
14
|
-
let posts, pages, categories, tags;
|
|
15
|
-
beforeAll(async () => {
|
|
16
|
-
await hexo.init();
|
|
17
|
-
posts = await Post.insert([{
|
|
18
|
-
title: 'post1',
|
|
19
|
-
source: 'bar',
|
|
20
|
-
slug: 'bar',
|
|
21
|
-
updated: 1e8 + 1
|
|
22
|
-
}, {
|
|
23
|
-
title: 'post2 <input>',
|
|
24
|
-
source: 'baz',
|
|
25
|
-
slug: 'baz',
|
|
26
|
-
updated: 1e8 - 1
|
|
27
|
-
}]);
|
|
28
|
-
pages = await Page.insert([{
|
|
29
|
-
title: 'page1',
|
|
30
|
-
source: 'bio/index.md',
|
|
31
|
-
path: 'bio/',
|
|
32
|
-
updated: 1e8 - 3
|
|
33
|
-
}, {
|
|
34
|
-
title: 'page2',
|
|
35
|
-
source: 'about/index.md',
|
|
36
|
-
path: 'about/',
|
|
37
|
-
updated: 1e8 - 4
|
|
38
|
-
}]);
|
|
39
|
-
categories = await Category.insert([{
|
|
40
|
-
name: 'cat_parent',
|
|
41
|
-
parent: null
|
|
42
|
-
}]);
|
|
43
|
-
categories = categories.concat(await Category.insert([{
|
|
44
|
-
name: 'cat_child',
|
|
45
|
-
parent: categories[0]._id
|
|
46
|
-
}]));
|
|
47
|
-
tags = await Tag.insert([{
|
|
48
|
-
name: 'tag1'
|
|
49
|
-
}, {
|
|
50
|
-
name: 'tag2'
|
|
51
|
-
}]);
|
|
52
|
-
await hexo.load();
|
|
53
|
-
register(hexo);
|
|
54
|
-
});
|
|
55
|
-
test('Export assets file from asset folder', async () => {
|
|
56
|
-
const locals = hexo.locals.toObject();
|
|
57
|
-
locals.config = hexo.config;
|
|
58
|
-
locals.posts = posts;
|
|
59
|
-
locals.pages = pages;
|
|
60
|
-
locals.categories = categories;
|
|
61
|
-
locals.tags = tags;
|
|
62
|
-
const generator = hexo.extend.generator.get('insight').bind(hexo);
|
|
63
|
-
const result = await generator(locals);
|
|
64
|
-
expect(result.path).toBe('/content.json');
|
|
65
|
-
expect(result.data).not.toBeUndefined();
|
|
66
|
-
const data = JSON.parse(result.data);
|
|
67
|
-
expect(data.posts.length).toBe(2);
|
|
68
|
-
expect(data.posts.find(post => post.title === 'post1' && post.link.includes('bar') && Object.prototype.hasOwnProperty.call(post, 'text'))).not.toBeUndefined();
|
|
69
|
-
expect(data.posts.find(post => post.title === 'post2 <input>' && post.link.includes('baz') && Object.prototype.hasOwnProperty.call(post, 'text'))).not.toBeUndefined();
|
|
70
|
-
expect(data.pages.length).toBe(2);
|
|
71
|
-
expect(data.pages.find(page => page.title === 'page1' && page.link.includes('bio') && Object.prototype.hasOwnProperty.call(page, 'text'))).not.toBeUndefined();
|
|
72
|
-
expect(data.pages.find(page => page.title === 'page2' && page.link.includes('about') && Object.prototype.hasOwnProperty.call(page, 'text'))).not.toBeUndefined();
|
|
73
|
-
expect(data.categories.length).toBe(2);
|
|
74
|
-
expect(data.categories.find(category => category.name === 'cat_parent' && category.slug === 'cat-parent' && category.link.includes('cat-parent'))).not.toBeUndefined();
|
|
75
|
-
expect(data.categories.find(category => category.name === 'cat_child' && category.slug === 'cat-parent/cat-child' && category.link.includes('cat-parent/cat-child'))).not.toBeUndefined();
|
|
76
|
-
expect(data.tags.length).toBe(2);
|
|
77
|
-
expect(data.tags.find(tag => tag.name === 'tag1' && tag.slug === 'tag1' && tag.link.includes('tag1'))).not.toBeUndefined();
|
|
78
|
-
expect(data.tags.find(tag => tag.name === 'tag2' && tag.slug === 'tag2' && tag.link.includes('tag2'))).not.toBeUndefined();
|
|
79
|
-
});
|
|
80
|
-
test('Exclude pages from index when `index_pages` is false', async () => {
|
|
81
|
-
const locals = hexo.locals.toObject();
|
|
82
|
-
locals.config = hexo.config;
|
|
83
|
-
locals.posts = posts;
|
|
84
|
-
locals.pages = pages;
|
|
85
|
-
locals.categories = categories;
|
|
86
|
-
locals.tags = tags;
|
|
87
|
-
hexo.theme.config.search = {
|
|
88
|
-
index_pages: false
|
|
89
|
-
};
|
|
90
|
-
const generator = hexo.extend.generator.get('insight').bind(hexo);
|
|
91
|
-
const result = await generator(locals);
|
|
92
|
-
const data = JSON.parse(result.data);
|
|
93
|
-
expect(data.posts.length).toBe(2);
|
|
94
|
-
expect(data.pages.length).toBe(0);
|
|
95
|
-
});
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
const {
|
|
2
|
-
join
|
|
3
|
-
} = require('path');
|
|
4
|
-
const Hexo = require('hexo');
|
|
5
|
-
const register = require('./manifest');
|
|
6
|
-
const rootDir = join(__dirname, '../../../fixture/site');
|
|
7
|
-
const hexo = new Hexo(rootDir, {
|
|
8
|
-
silent: true
|
|
9
|
-
});
|
|
10
|
-
beforeAll(async () => {
|
|
11
|
-
await hexo.init();
|
|
12
|
-
await hexo.load();
|
|
13
|
-
register(hexo);
|
|
14
|
-
});
|
|
15
|
-
test('Generate manifest.json according to theme configuration', async () => {
|
|
16
|
-
const manifest = {
|
|
17
|
-
name: 'name',
|
|
18
|
-
short_name: 'short_name',
|
|
19
|
-
start_url: 'start_url',
|
|
20
|
-
theme_color: '#000000',
|
|
21
|
-
background_color: '#111111',
|
|
22
|
-
display: 'standalone',
|
|
23
|
-
icons: [{
|
|
24
|
-
src: '1.png',
|
|
25
|
-
sizes: '128x128 256x256',
|
|
26
|
-
type: 'image/png'
|
|
27
|
-
}, {
|
|
28
|
-
src: '2.png',
|
|
29
|
-
sizes: '512x512',
|
|
30
|
-
type: 'image/png'
|
|
31
|
-
}]
|
|
32
|
-
};
|
|
33
|
-
hexo.theme.config.head = {
|
|
34
|
-
manifest
|
|
35
|
-
};
|
|
36
|
-
const locals = hexo.locals.toObject();
|
|
37
|
-
const generator = hexo.extend.generator.get('manifest').bind(hexo);
|
|
38
|
-
const result = await generator(locals);
|
|
39
|
-
expect(result.path).toEqual('/manifest.json');
|
|
40
|
-
expect(JSON.parse(result.data)).toEqual(manifest);
|
|
41
|
-
});
|
|
42
|
-
test('Generate manifest.json when theme configuration is empty', async () => {
|
|
43
|
-
hexo.theme.config.head = {};
|
|
44
|
-
const locals = hexo.locals.toObject();
|
|
45
|
-
const generator = hexo.extend.generator.get('manifest').bind(hexo);
|
|
46
|
-
const result = await generator(locals);
|
|
47
|
-
expect(result.path).toEqual('/manifest.json');
|
|
48
|
-
expect(JSON.parse(result.data)).toEqual({
|
|
49
|
-
name: 'site title',
|
|
50
|
-
start_url: '/index.html'
|
|
51
|
-
});
|
|
52
|
-
});
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const Hexo = require('hexo');
|
|
3
|
-
const register = require('./tags');
|
|
4
|
-
const rootDir = path.join(__dirname, '../../../fixture/site');
|
|
5
|
-
const hexo = new Hexo(rootDir, {
|
|
6
|
-
silent: true
|
|
7
|
-
});
|
|
8
|
-
const Page = hexo.model('Page');
|
|
9
|
-
const Post = hexo.model('Post');
|
|
10
|
-
let pages = [];
|
|
11
|
-
beforeAll(async () => {
|
|
12
|
-
await hexo.init();
|
|
13
|
-
pages = await Page.insert([{
|
|
14
|
-
source: 'bio/index.md',
|
|
15
|
-
path: 'bio/',
|
|
16
|
-
updated: 1e8 - 3
|
|
17
|
-
}, {
|
|
18
|
-
source: 'about/index.md',
|
|
19
|
-
path: 'about/',
|
|
20
|
-
updated: 1e8 - 4
|
|
21
|
-
}]);
|
|
22
|
-
pages.concat(await Post.insert([{
|
|
23
|
-
source: 'bar',
|
|
24
|
-
slug: 'bar',
|
|
25
|
-
updated: 1e8 + 1
|
|
26
|
-
}, {
|
|
27
|
-
source: 'baz',
|
|
28
|
-
slug: 'baz',
|
|
29
|
-
updated: 1e8 - 1
|
|
30
|
-
}]));
|
|
31
|
-
await hexo.load();
|
|
32
|
-
register(hexo);
|
|
33
|
-
});
|
|
34
|
-
test('Add /tags route and add a flag (__tags) to the locals', async () => {
|
|
35
|
-
const locals = hexo.locals.toObject();
|
|
36
|
-
const generator = hexo.extend.generator.get('tags').bind(hexo);
|
|
37
|
-
const result = await generator(locals);
|
|
38
|
-
expect(result.path).toBe('tags/');
|
|
39
|
-
expect(result.layout).toEqual(['tags']);
|
|
40
|
-
expect(result.data.__tags).toBe(true);
|
|
41
|
-
});
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const Hexo = require('hexo');
|
|
3
|
-
const register = require('./cdn');
|
|
4
|
-
const rootDir = path.join(__dirname, '../../../fixture/site');
|
|
5
|
-
const hexo = new Hexo(rootDir, {
|
|
6
|
-
silent: true
|
|
7
|
-
});
|
|
8
|
-
beforeAll(async () => {
|
|
9
|
-
await hexo.init();
|
|
10
|
-
await hexo.load();
|
|
11
|
-
register(hexo);
|
|
12
|
-
});
|
|
13
|
-
describe('Get JavaScript library URL', () => {
|
|
14
|
-
let cases;
|
|
15
|
-
beforeEach(async () => {
|
|
16
|
-
const cdn = hexo.extend.helper.get('cdn').bind(hexo);
|
|
17
|
-
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', '3.2.2', 'es5/tex-mml-chtml.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.3.0', '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', '2.6.3', 'dist/waline.js'), () => cdn('twikoo', '1.6.30', 'dist/twikoo.all.min.js'), () => cdn('example', '1.0.0', 'example.js')];
|
|
18
|
-
});
|
|
19
|
-
test('jsdelivr', () => {
|
|
20
|
-
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@3.2.2/es5/tex-mml-chtml.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.3.0/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@2.6.3/dist/waline.js', 'https://cdn.jsdelivr.net/npm/twikoo@1.6.30/dist/twikoo.all.min.js', 'https://cdn.jsdelivr.net/npm/example@1.0.0/example.js'];
|
|
21
|
-
cases.forEach((func, i) => expect(func()).toBe(expected[i]));
|
|
22
|
-
});
|
|
23
|
-
test('unpkg', () => {
|
|
24
|
-
hexo.config.providers = {
|
|
25
|
-
cdn: 'unpkg'
|
|
26
|
-
};
|
|
27
|
-
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@3.2.2/es5/tex-mml-chtml.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.3.0/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@2.6.3/dist/waline.js', 'https://unpkg.com/twikoo@1.6.30/dist/twikoo.all.min.js', 'https://unpkg.com/example@1.0.0/example.js'];
|
|
28
|
-
cases.forEach((func, i) => expect(func()).toBe(expected[i]));
|
|
29
|
-
});
|
|
30
|
-
test('cdnjs', () => {
|
|
31
|
-
hexo.config.providers = {
|
|
32
|
-
cdn: 'cdnjs'
|
|
33
|
-
};
|
|
34
|
-
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/3.2.2/es5/tex-mml-chtml.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://cdnjs.cloudflare.com/ajax/libs/disqusjs/1.3.0/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/2.6.3/waline.js', 'https://cdnjs.cloudflare.com/ajax/libs/twikoo/1.6.30/twikoo.all.min.js', 'https://cdnjs.cloudflare.com/ajax/libs/example/1.0.0/example.js'];
|
|
35
|
-
cases.forEach((func, i) => expect(func()).toBe(expected[i]));
|
|
36
|
-
});
|
|
37
|
-
test('loli', () => {
|
|
38
|
-
hexo.config.providers = {
|
|
39
|
-
cdn: 'loli'
|
|
40
|
-
};
|
|
41
|
-
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/3.2.2/es5/tex-mml-chtml.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://cdnjs.loli.net/ajax/libs/disqusjs/1.3.0/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/2.6.3/waline.js', 'https://cdnjs.loli.net/ajax/libs/twikoo/1.6.30/twikoo.all.min.js', 'https://cdnjs.loli.net/ajax/libs/example/1.0.0/example.js'];
|
|
42
|
-
cases.forEach((func, i) => expect(func()).toBe(expected[i]));
|
|
43
|
-
});
|
|
44
|
-
test('Custom CDN', () => {
|
|
45
|
-
hexo.config.providers = {
|
|
46
|
-
cdn: 'https://my.cdn/${ package }@${ version }/${ filename }'
|
|
47
|
-
};
|
|
48
|
-
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@3.2.2/es5/tex-mml-chtml.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.3.0/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@2.6.3/dist/waline.js', 'https://my.cdn/twikoo@1.6.30/dist/twikoo.all.min.js', 'https://my.cdn/example@1.0.0/example.js'];
|
|
49
|
-
cases.forEach((func, i) => expect(func()).toBe(expected[i]));
|
|
50
|
-
});
|
|
51
|
-
test('Custom CDN.js-style CDN', () => {
|
|
52
|
-
hexo.config.providers = {
|
|
53
|
-
cdn: '[cdnjs]https://my.cdn/ajax/libs/${ package }/${ version }/${ filename }'
|
|
54
|
-
};
|
|
55
|
-
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/3.2.2/es5/tex-mml-chtml.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://my.cdn/ajax/libs/disqusjs/1.3.0/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/2.6.3/waline.js', 'https://my.cdn/ajax/libs/twikoo/1.6.30/twikoo.all.min.js', 'https://my.cdn/ajax/libs/example/1.0.0/example.js'];
|
|
56
|
-
cases.forEach((func, i) => expect(func()).toBe(expected[i]));
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
describe('Get web font URL', () => {
|
|
60
|
-
let cases;
|
|
61
|
-
beforeEach(async () => {
|
|
62
|
-
const fontcdn = hexo.extend.helper.get('fontcdn').bind(hexo);
|
|
63
|
-
cases = [() => fontcdn('Ubuntu:400,600|Source+Code+Pro', 'css'), () => fontcdn('Roboto:wght@100;400&display=swap', 'css2')];
|
|
64
|
-
});
|
|
65
|
-
test('google', () => {
|
|
66
|
-
hexo.config.providers = {
|
|
67
|
-
fontcdn: 'google'
|
|
68
|
-
};
|
|
69
|
-
const expected = ['https://fonts.googleapis.com/css?family=Ubuntu:400,600|Source+Code+Pro', 'https://fonts.googleapis.com/css2?family=Roboto:wght@100;400&display=swap'];
|
|
70
|
-
cases.forEach((func, i) => expect(func()).toBe(expected[i]));
|
|
71
|
-
});
|
|
72
|
-
test('loli', () => {
|
|
73
|
-
hexo.config.providers = {
|
|
74
|
-
fontcdn: 'loli'
|
|
75
|
-
};
|
|
76
|
-
const expected = ['https://fonts.loli.net/css?family=Ubuntu:400,600|Source+Code+Pro', 'https://fonts.loli.net/css2?family=Roboto:wght@100;400&display=swap'];
|
|
77
|
-
cases.forEach((func, i) => expect(func()).toBe(expected[i]));
|
|
78
|
-
});
|
|
79
|
-
test('fontim', () => {
|
|
80
|
-
hexo.config.providers = {
|
|
81
|
-
fontcdn: 'fontim'
|
|
82
|
-
};
|
|
83
|
-
const expected = ['https://fonts.font.im/css?family=Ubuntu:400,600|Source+Code+Pro', 'https://fonts.font.im/css2?family=Roboto:wght@100;400&display=swap'];
|
|
84
|
-
cases.forEach((func, i) => expect(func()).toBe(expected[i]));
|
|
85
|
-
});
|
|
86
|
-
test('ustc', () => {
|
|
87
|
-
hexo.config.providers = {
|
|
88
|
-
fontcdn: 'ustc'
|
|
89
|
-
};
|
|
90
|
-
const expected = ['https://fonts.lug.ustc.edu.cn/css?family=Ubuntu:400,600|Source+Code+Pro', 'https://fonts.lug.ustc.edu.cn/css2?family=Roboto:wght@100;400&display=swap'];
|
|
91
|
-
cases.forEach((func, i) => expect(func()).toBe(expected[i]));
|
|
92
|
-
});
|
|
93
|
-
test('Custom web font CDN', () => {
|
|
94
|
-
hexo.config.providers = {
|
|
95
|
-
fontcdn: 'https://my.cdn/${ type }?family=${ fontname }'
|
|
96
|
-
};
|
|
97
|
-
const expected = ['https://my.cdn/css?family=Ubuntu:400,600|Source+Code+Pro', 'https://my.cdn/css2?family=Roboto:wght@100;400&display=swap'];
|
|
98
|
-
cases.forEach((func, i) => expect(func()).toBe(expected[i]));
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
describe('Get icon font URL', () => {
|
|
102
|
-
let cases;
|
|
103
|
-
beforeEach(async () => {
|
|
104
|
-
const iconcdn = hexo.extend.helper.get('iconcdn').bind(hexo);
|
|
105
|
-
cases = [() => iconcdn()];
|
|
106
|
-
});
|
|
107
|
-
test('fontawesome', () => {
|
|
108
|
-
hexo.config.providers = {
|
|
109
|
-
iconcdn: 'fontawesome'
|
|
110
|
-
};
|
|
111
|
-
const expected = ['https://use.fontawesome.com/releases/v6.0.0/css/all.css'];
|
|
112
|
-
cases.forEach((func, i) => expect(func()).toBe(expected[i]));
|
|
113
|
-
});
|
|
114
|
-
test('loli', () => {
|
|
115
|
-
hexo.config.providers = {
|
|
116
|
-
iconcdn: 'loli'
|
|
117
|
-
};
|
|
118
|
-
const expected = ['https://cdnjs.loli.net/ajax/libs/font-awesome/6.0.0/css/all.min.css'];
|
|
119
|
-
cases.forEach((func, i) => expect(func()).toBe(expected[i]));
|
|
120
|
-
});
|
|
121
|
-
test('Custom web font CDN', () => {
|
|
122
|
-
hexo.config.providers = {
|
|
123
|
-
iconcdn: 'https://my.cdn/icon'
|
|
124
|
-
};
|
|
125
|
-
const expected = ['https://my.cdn/icon'];
|
|
126
|
-
cases.forEach((func, i) => expect(func()).toBe(expected[i]));
|
|
127
|
-
});
|
|
128
|
-
});
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const Hexo = require('hexo');
|
|
3
|
-
const register = require('./page');
|
|
4
|
-
const rootDir = path.join(__dirname, '../../../fixture/site');
|
|
5
|
-
const hexo = new Hexo(rootDir, {
|
|
6
|
-
silent: true
|
|
7
|
-
});
|
|
8
|
-
const Page = hexo.model('Page');
|
|
9
|
-
const Post = hexo.model('Post');
|
|
10
|
-
let pages = [];
|
|
11
|
-
beforeAll(async () => {
|
|
12
|
-
await hexo.init();
|
|
13
|
-
await hexo.load();
|
|
14
|
-
register(hexo);
|
|
15
|
-
pages = await Page.insert([{
|
|
16
|
-
source: 'bio/index.md',
|
|
17
|
-
path: 'bio/',
|
|
18
|
-
updated: 1e8 - 3,
|
|
19
|
-
__categories: true
|
|
20
|
-
}, {
|
|
21
|
-
source: 'about/index.md',
|
|
22
|
-
path: 'about/',
|
|
23
|
-
updated: 1e8 - 4,
|
|
24
|
-
__tags: true
|
|
25
|
-
}, {
|
|
26
|
-
source: 'faq/index.md',
|
|
27
|
-
path: 'faq/',
|
|
28
|
-
updated: 1e8 - 5
|
|
29
|
-
}]);
|
|
30
|
-
pages.concat(await Post.insert([{
|
|
31
|
-
source: 'foo',
|
|
32
|
-
slug: 'foo',
|
|
33
|
-
updated: 1e8,
|
|
34
|
-
__tags: true
|
|
35
|
-
}, {
|
|
36
|
-
source: 'bar',
|
|
37
|
-
slug: 'bar',
|
|
38
|
-
updated: 1e8 + 1,
|
|
39
|
-
__categories: true
|
|
40
|
-
}, {
|
|
41
|
-
source: 'baz',
|
|
42
|
-
slug: 'baz',
|
|
43
|
-
updated: 1e8 - 1
|
|
44
|
-
}]));
|
|
45
|
-
});
|
|
46
|
-
beforeEach(() => {
|
|
47
|
-
hexo.page = null;
|
|
48
|
-
});
|
|
49
|
-
test('Correctly check if page is /categories page', () => {
|
|
50
|
-
const isCategories = hexo.extend.helper.get('is_categories').bind(hexo);
|
|
51
|
-
const expected = [true, false, false, false, true, false];
|
|
52
|
-
pages.forEach((page, i) => expect(isCategories(page)).toBe(expected[i]));
|
|
53
|
-
hexo.page = pages[0];
|
|
54
|
-
expect(isCategories()).toBe(expected[0]);
|
|
55
|
-
});
|
|
56
|
-
test('Correctly check if page is /tags page', () => {
|
|
57
|
-
const isTags = hexo.extend.helper.get('is_tags').bind(hexo);
|
|
58
|
-
const expected = [false, true, false, true, false, false];
|
|
59
|
-
pages.forEach((page, i) => expect(isTags(page)).toBe(expected[i]));
|
|
60
|
-
hexo.page = pages[0];
|
|
61
|
-
expect(isTags()).toBe(expected[0]);
|
|
62
|
-
});
|