hexo-component-inferno 4.0.0 → 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/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/waline.json +1 -1
- package/lib/schema/plugin/waline_pageview.json +14 -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 +48 -3
- package/lib/view/comment/artalk.js +118 -0
- package/lib/view/comment/beaudar.js +133 -0
- package/lib/view/comment/cusdis.js +119 -0
- package/lib/view/comment/giscus.js +31 -21
- package/lib/view/comment/utterances.js +25 -16
- package/lib/view/comment/waline.js +10 -4
- package/lib/view/plugin/waline_pageview.js +98 -0
- package/lib/view/widget/archives.js +22 -7
- package/lib/view/widget/categories.js +22 -6
- package/lib/view/widget/tags.js +18 -5
- package/package.json +1 -1
package/lib/hexo/helper/cdn.js
CHANGED
|
@@ -59,6 +59,11 @@ const UNPKG_FIXTURES = {
|
|
|
59
59
|
* cdn('jquery', '3.3.1', 'dist/jquery.min.js');
|
|
60
60
|
* // -> https://cdn.jsdelivr.net/npm/jquery@3.3.1/dist/jquery.min.js
|
|
61
61
|
*
|
|
62
|
+
* // Set providers.cdn_overrides, e.g., { jquery: 'unpkg' }, to use a different CDN provider or URL
|
|
63
|
+
* // template for some packages
|
|
64
|
+
* cdn('jquery', '3.3.1', 'dist/jquery.min.js');
|
|
65
|
+
* // -> https://unpkg.com/jquery@3.3.1/dist/jquery.min.js
|
|
66
|
+
*
|
|
62
67
|
* // Use the function below to resolve the CDN URL web font files
|
|
63
68
|
* fontcdn('Ubuntu:400,600|Source+Code+Pro', 'css');
|
|
64
69
|
* // -> https://fonts.googleapis.com/css?family=Ubuntu:400,600|Source+Code+Pro
|
|
@@ -80,9 +85,12 @@ module.exports = function (hexo) {
|
|
|
80
85
|
return [_package, version, filename];
|
|
81
86
|
}
|
|
82
87
|
hexo.extend.helper.register('cdn', function (_package, version, filename) {
|
|
88
|
+
const providers = typeof this.config.providers === 'object' ? this.config.providers : {};
|
|
83
89
|
const {
|
|
84
|
-
|
|
85
|
-
} =
|
|
90
|
+
cdn_overrides: overrides
|
|
91
|
+
} = providers;
|
|
92
|
+
// A package can use a different provider or URL than the rest in providers.cdn_overrides
|
|
93
|
+
const cdn = typeof overrides === 'object' && overrides !== null && overrides[_package] ? overrides[_package] : providers.cdn || 'jsdelivr';
|
|
86
94
|
let _cdn = cdn;
|
|
87
95
|
if (_cdn in PROVIDERS.LIBRARY) {
|
|
88
96
|
_cdn = PROVIDERS.LIBRARY[_cdn];
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"$id": "/comment/artalk.json",
|
|
4
|
+
"description": "Artalk comment plugin configurations\nhttps://artalk.js.org/guide/frontend/config.html",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"properties": {
|
|
7
|
+
"type": {
|
|
8
|
+
"type": "string",
|
|
9
|
+
"const": "artalk"
|
|
10
|
+
},
|
|
11
|
+
"server": {
|
|
12
|
+
"type": "string",
|
|
13
|
+
"description": "URL of your Artalk server"
|
|
14
|
+
},
|
|
15
|
+
"site": {
|
|
16
|
+
"type": "string",
|
|
17
|
+
"description": "Name of the site on the Artalk server",
|
|
18
|
+
"nullable": true
|
|
19
|
+
},
|
|
20
|
+
"page_key": {
|
|
21
|
+
"type": "string",
|
|
22
|
+
"description": "Unique identifier of the page. Uses the path of the page if not set",
|
|
23
|
+
"nullable": true
|
|
24
|
+
},
|
|
25
|
+
"locale": {
|
|
26
|
+
"type": "string",
|
|
27
|
+
"description": "Language of Artalk, e.g., en, zh-CN, or auto",
|
|
28
|
+
"nullable": true
|
|
29
|
+
},
|
|
30
|
+
"dark_mode": {
|
|
31
|
+
"type": ["boolean", "string"],
|
|
32
|
+
"description": "Dark mode: true, false, or 'auto' to follow the system color scheme. Follows the appearance of the theme (the data-appearance attribute of <html>) if not set",
|
|
33
|
+
"nullable": true
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"required": ["type", "server"]
|
|
37
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"$id": "/comment/beaudar.json",
|
|
4
|
+
"description": "Beaudar comment plugin configurations\nhttps://github.com/beaudar/beaudar",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"properties": {
|
|
7
|
+
"type": {
|
|
8
|
+
"type": "string",
|
|
9
|
+
"const": "beaudar"
|
|
10
|
+
},
|
|
11
|
+
"repo": {
|
|
12
|
+
"type": "string",
|
|
13
|
+
"description": "Name of the GitHub repository for the comments, e.g., user/repo"
|
|
14
|
+
},
|
|
15
|
+
"branch": {
|
|
16
|
+
"type": "string",
|
|
17
|
+
"description": "Branch of the repository that has beaudar.json",
|
|
18
|
+
"nullable": true
|
|
19
|
+
},
|
|
20
|
+
"label": {
|
|
21
|
+
"type": "string",
|
|
22
|
+
"description": "Label of the issues created by Beaudar",
|
|
23
|
+
"nullable": true
|
|
24
|
+
},
|
|
25
|
+
"theme": {
|
|
26
|
+
"type": "string",
|
|
27
|
+
"description": "Beaudar look and feel when the page looks light, e.g., github-light, github-dark, or preferred-color-scheme",
|
|
28
|
+
"default": "github-light",
|
|
29
|
+
"nullable": true
|
|
30
|
+
},
|
|
31
|
+
"dark_theme": {
|
|
32
|
+
"type": "string",
|
|
33
|
+
"description": "Beaudar look and feel when the page looks dark, e.g., with the dark or auto appearance of the theme. For example github-dark, github-dark-orange, classic-dark, dark-blue, icy-dark, or photon-dark",
|
|
34
|
+
"default": "github-dark",
|
|
35
|
+
"nullable": true
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"required": ["type", "repo"],
|
|
39
|
+
"oneOf": [
|
|
40
|
+
{
|
|
41
|
+
"type": "object",
|
|
42
|
+
"properties": {
|
|
43
|
+
"issue_term": {
|
|
44
|
+
"type": "string",
|
|
45
|
+
"description": "The mapping between blog posts and GitHub issues, e.g., pathname, url, or title",
|
|
46
|
+
"default": "pathname"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"required": ["issue_term"]
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"type": "object",
|
|
53
|
+
"properties": {
|
|
54
|
+
"issue_number": {
|
|
55
|
+
"type": "integer",
|
|
56
|
+
"description": "Configure Beaudar to load a specific issue by number"
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
"required": ["issue_number"]
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"$id": "/comment/cusdis.json",
|
|
4
|
+
"description": "Cusdis comment plugin configurations\nhttps://cusdis.com/doc",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"properties": {
|
|
7
|
+
"type": {
|
|
8
|
+
"type": "string",
|
|
9
|
+
"const": "cusdis"
|
|
10
|
+
},
|
|
11
|
+
"app_id": {
|
|
12
|
+
"type": "string",
|
|
13
|
+
"description": "App ID of the website in the embed code from the Cusdis dashboard"
|
|
14
|
+
},
|
|
15
|
+
"host": {
|
|
16
|
+
"type": "string",
|
|
17
|
+
"description": "URL of your Cusdis server if you host it yourself",
|
|
18
|
+
"default": "https://cusdis.com",
|
|
19
|
+
"nullable": true
|
|
20
|
+
},
|
|
21
|
+
"theme": {
|
|
22
|
+
"type": "string",
|
|
23
|
+
"description": "Theme of Cusdis: light, dark, or auto to follow the system color scheme. Follows the appearance of the theme (the data-appearance attribute of <html>) if not set",
|
|
24
|
+
"enum": ["light", "dark", "auto"],
|
|
25
|
+
"nullable": true
|
|
26
|
+
},
|
|
27
|
+
"lang": {
|
|
28
|
+
"type": "string",
|
|
29
|
+
"description": "Language of Cusdis, e.g., zh-cn, zh-tw, es, or fi. Uses English if not set",
|
|
30
|
+
"nullable": true
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"required": ["type", "app_id"]
|
|
34
|
+
}
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
},
|
|
61
61
|
"theme": {
|
|
62
62
|
"type": "string",
|
|
63
|
-
"description": "Giscus look and feel",
|
|
63
|
+
"description": "Giscus look and feel when the page looks light",
|
|
64
64
|
"enum": [
|
|
65
65
|
"light",
|
|
66
66
|
"light_high_contrast",
|
|
@@ -83,6 +83,12 @@
|
|
|
83
83
|
"default": "noborder_light",
|
|
84
84
|
"nullable": true
|
|
85
85
|
},
|
|
86
|
+
"darkTheme": {
|
|
87
|
+
"type": "string",
|
|
88
|
+
"description": "Giscus look and feel when the page looks dark, e.g., with the dark or auto appearance of the theme. Not used when theme is custom",
|
|
89
|
+
"default": "noborder_dark",
|
|
90
|
+
"nullable": true
|
|
91
|
+
},
|
|
86
92
|
"customThemeCss": {
|
|
87
93
|
"type": "string",
|
|
88
94
|
"description": "The url of custom Giscus theme css, only affect when theme is set to custom",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
},
|
|
20
20
|
"theme": {
|
|
21
21
|
"type": "string",
|
|
22
|
-
"description": "Utterances look and feel",
|
|
22
|
+
"description": "Utterances look and feel when the page looks light",
|
|
23
23
|
"enum": [
|
|
24
24
|
"github-light",
|
|
25
25
|
"github-dark",
|
|
@@ -30,6 +30,20 @@
|
|
|
30
30
|
],
|
|
31
31
|
"default": "github-light",
|
|
32
32
|
"nullable": true
|
|
33
|
+
},
|
|
34
|
+
"dark_theme": {
|
|
35
|
+
"type": "string",
|
|
36
|
+
"description": "Utterances look and feel when the page looks dark, e.g., with the dark or auto appearance of the theme",
|
|
37
|
+
"enum": [
|
|
38
|
+
"github-light",
|
|
39
|
+
"github-dark",
|
|
40
|
+
"github-dark-orange",
|
|
41
|
+
"icy-dark",
|
|
42
|
+
"dark-blue",
|
|
43
|
+
"photon-dark"
|
|
44
|
+
],
|
|
45
|
+
"default": "github-dark",
|
|
46
|
+
"nullable": true
|
|
33
47
|
}
|
|
34
48
|
},
|
|
35
49
|
"required": ["type", "repo"],
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
},
|
|
78
78
|
"dark": {
|
|
79
79
|
"type": ["string", "boolean"],
|
|
80
|
-
"description": "Darkmode support.",
|
|
80
|
+
"description": "Darkmode support. Can be true, false, 'auto' to follow the system color scheme, or a CSS selector that enables the dark mode when it matches an ancestor of Waline. Follows the appearance of the theme (the data-appearance attribute of <html>) if not set",
|
|
81
81
|
"nullable": true
|
|
82
82
|
},
|
|
83
83
|
"meta": {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"$id": "/plugin/waline_pageview.json",
|
|
4
|
+
"description": "Waline page view counter, true to use the server of the Waline comments, which can also store the views in LeanCloud. Do not also enable the pageview option of the Waline comments, which would count the views twice\nhttps://waline.js.org/en/guide/features/pageview.html",
|
|
5
|
+
"type": ["boolean", "object"],
|
|
6
|
+
"properties": {
|
|
7
|
+
"server_url": {
|
|
8
|
+
"type": "string",
|
|
9
|
+
"description": "URL of the Waline server. Uses the server of the Waline comments if not set",
|
|
10
|
+
"nullable": true
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"default": false
|
|
14
|
+
}
|
|
@@ -7,6 +7,11 @@
|
|
|
7
7
|
"type": {
|
|
8
8
|
"type": "string",
|
|
9
9
|
"const": "archives"
|
|
10
|
+
},
|
|
11
|
+
"amount": {
|
|
12
|
+
"type": "integer",
|
|
13
|
+
"description": "Amount of archives to show, with a link to the archive page for the rest. Will show all if not set",
|
|
14
|
+
"nullable": true
|
|
10
15
|
}
|
|
11
16
|
},
|
|
12
17
|
"required": ["type"]
|
|
@@ -7,6 +7,11 @@
|
|
|
7
7
|
"type": {
|
|
8
8
|
"type": "string",
|
|
9
9
|
"const": "categories"
|
|
10
|
+
},
|
|
11
|
+
"amount": {
|
|
12
|
+
"type": "integer",
|
|
13
|
+
"description": "Amount of top-level categories to show, with a link to the category page for the rest. Will show all if not set",
|
|
14
|
+
"nullable": true
|
|
10
15
|
}
|
|
11
16
|
},
|
|
12
17
|
"required": ["type"]
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
},
|
|
17
17
|
"amount": {
|
|
18
18
|
"type": "integer",
|
|
19
|
-
"description": "Amount of tags to show. Will show all if not set.",
|
|
19
|
+
"description": "Amount of tags to show, with a link to the tag page for the rest. Will show all if not set.",
|
|
20
20
|
"nullable": true
|
|
21
21
|
},
|
|
22
22
|
"show_count": {
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for inline scripts that follow the appearance of the page.
|
|
3
|
+
* @module util/appearance
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Get a JavaScript expression that is true when the page looks dark.
|
|
8
|
+
* <p>
|
|
9
|
+
* A theme can set the appearance of a page with the <code>data-appearance</code> attribute of
|
|
10
|
+
* <code><html></code>: <code>dark</code> always looks dark, <code>auto</code> looks dark when
|
|
11
|
+
* the system prefers a dark color scheme, and any other value, or no attribute, looks light.
|
|
12
|
+
*
|
|
13
|
+
* @returns {string} The JavaScript expression.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* const js = `var theme = ${isDark()} ? 'dark' : 'light';`;
|
|
17
|
+
*/
|
|
18
|
+
function isDark() {
|
|
19
|
+
return `(function (appearance) {
|
|
20
|
+
return appearance === 'dark' || (appearance === 'auto' && !!window.matchMedia &&
|
|
21
|
+
window.matchMedia('(prefers-color-scheme: dark)').matches);
|
|
22
|
+
})(document.documentElement.getAttribute('data-appearance'))`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Get a JavaScript expression for the appearance of the page: <code>'dark'</code>,
|
|
27
|
+
* <code>'auto'</code>, or <code>'light'</code>.
|
|
28
|
+
*
|
|
29
|
+
* @returns {string} The JavaScript expression.
|
|
30
|
+
* @see module:util/appearance.isDark
|
|
31
|
+
*/
|
|
32
|
+
function getAppearance() {
|
|
33
|
+
return `(function (appearance) {
|
|
34
|
+
return appearance === 'dark' || appearance === 'auto' ? appearance : 'light';
|
|
35
|
+
})(document.documentElement.getAttribute('data-appearance'))`;
|
|
36
|
+
}
|
|
37
|
+
module.exports = {
|
|
38
|
+
isDark,
|
|
39
|
+
getAppearance
|
|
40
|
+
};
|
package/lib/util/i18n.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for translations.
|
|
3
|
+
* @module util/i18n
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Translate a key with the <code>__</code> helper of Hexo, or use the fallback text when the theme has
|
|
8
|
+
* no translation for the key, in which case Hexo returns the key itself.
|
|
9
|
+
*
|
|
10
|
+
* @param {Function} __ The <code>__</code> helper function of Hexo.
|
|
11
|
+
* @param {string} key The translation key.
|
|
12
|
+
* @param {string} fallback The text to use without a translation.
|
|
13
|
+
* @returns {string} The translated text.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* translate(helper.__, 'widget.more', 'More');
|
|
17
|
+
*/
|
|
18
|
+
function translate(__, key, fallback) {
|
|
19
|
+
const text = typeof __ === 'function' ? __(key) : null;
|
|
20
|
+
return text && text !== key ? text : fallback;
|
|
21
|
+
}
|
|
22
|
+
module.exports = {
|
|
23
|
+
translate
|
|
24
|
+
};
|
package/lib/util/script.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Utility functions for building inline scripts that load external scripts without blocking the page.
|
|
3
3
|
* @module util/script
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
* @example
|
|
21
21
|
* <script dangerouslySetInnerHTML={{ __html: loadScripts('/path/to/lib.js', 'lib.init();') }} />
|
|
22
22
|
*/
|
|
23
|
-
|
|
23
|
+
function loadScripts(urls, code, attrs = {}) {
|
|
24
24
|
return `(function () {
|
|
25
25
|
var urls = ${JSON.stringify([].concat(urls))};
|
|
26
26
|
var attrs = ${JSON.stringify(attrs)};
|
|
@@ -62,4 +62,49 @@ module.exports = function (urls, code, attrs = {}) {
|
|
|
62
62
|
}
|
|
63
63
|
load(0);
|
|
64
64
|
})();`;
|
|
65
|
-
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Build an inline script that adds an external script to an element, for example the client script of
|
|
69
|
+
* a comment system that reads its options from the attributes of its own <code><script></code>
|
|
70
|
+
* tag.
|
|
71
|
+
* <p>
|
|
72
|
+
* The external script is added every time the inline script runs. Unlike a <code><script></code>
|
|
73
|
+
* tag in the page, which PJAX runs again without its attributes and outside of its element, it keeps
|
|
74
|
+
* its attributes and stays in the element. It is added after the inline script has finished, so that
|
|
75
|
+
* PJAX, which runs the scripts of the new page right after switching to it, does not run it again.
|
|
76
|
+
*
|
|
77
|
+
* @param {string} selector CSS selector of the element to add the external script to.
|
|
78
|
+
* @param {string} url URL of the external script.
|
|
79
|
+
* @param {Object} attrs Attributes to set on the external script element.
|
|
80
|
+
* @param {Object} [dynamicAttrs] More attributes, whose values are JavaScript expressions evaluated by
|
|
81
|
+
* the inline script, for example to choose a theme in the browser.
|
|
82
|
+
* @returns {string} The inline JavaScript code.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* appendScript('#comments-thread', 'https://comments.example.com/client.js', { repo: 'user/repo' }, {
|
|
86
|
+
* theme: "window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'",
|
|
87
|
+
* });
|
|
88
|
+
*/
|
|
89
|
+
function appendScript(selector, url, attrs, dynamicAttrs = {}) {
|
|
90
|
+
const dynamic = Object.keys(dynamicAttrs).map(name => `attrs[${JSON.stringify(name)}] = ${dynamicAttrs[name]};`).join('\n ');
|
|
91
|
+
return `(function () {
|
|
92
|
+
var element = document.querySelector(${JSON.stringify(selector)});
|
|
93
|
+
if (!element) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
var attrs = ${JSON.stringify(attrs)};
|
|
97
|
+
${dynamic}
|
|
98
|
+
var script = document.createElement('script');
|
|
99
|
+
for (var name in attrs) {
|
|
100
|
+
script.setAttribute(name, attrs[name]);
|
|
101
|
+
}
|
|
102
|
+
script.src = ${JSON.stringify(url)};
|
|
103
|
+
script.async = true;
|
|
104
|
+
setTimeout(function () {
|
|
105
|
+
element.appendChild(script);
|
|
106
|
+
});
|
|
107
|
+
})();`;
|
|
108
|
+
}
|
|
109
|
+
module.exports = loadScripts;
|
|
110
|
+
module.exports.appendScript = appendScript;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
var _inferno = require("inferno");
|
|
5
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
6
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
7
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
8
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
9
|
+
function _toPrimitive(t, e) { if ("object" != _typeof(t) || !t) return t; var r; if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) { var i = r.call(t, e || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === e ? String : Number)(t); }
|
|
10
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
11
|
+
function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
|
|
12
|
+
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
|
|
13
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
14
|
+
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
|
|
15
|
+
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
|
|
16
|
+
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
|
|
17
|
+
/**
|
|
18
|
+
* Artalk comment JSX component.
|
|
19
|
+
* @module view/comment/artalk
|
|
20
|
+
*/
|
|
21
|
+
var _require = require('inferno'),
|
|
22
|
+
Component = _require.Component;
|
|
23
|
+
var _require2 = require('../../util/cache'),
|
|
24
|
+
cacheComponent = _require2.cacheComponent;
|
|
25
|
+
var loadScripts = require('../../util/script');
|
|
26
|
+
var _require3 = require('../../util/appearance'),
|
|
27
|
+
getAppearance = _require3.getAppearance,
|
|
28
|
+
isDark = _require3.isDark;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Artalk comment JSX component.
|
|
32
|
+
*
|
|
33
|
+
* @see https://artalk.js.org/guide/frontend/config.html
|
|
34
|
+
* @example
|
|
35
|
+
* <Artalk
|
|
36
|
+
* server="https://artalk.example.com"
|
|
37
|
+
* site="******"
|
|
38
|
+
* pageKey="/path/to/page/"
|
|
39
|
+
* pageTitle="******"
|
|
40
|
+
* locale="en"
|
|
41
|
+
* darkMode={false}
|
|
42
|
+
* jsUrl="/path/to/Artalk.js"
|
|
43
|
+
* cssUrl="/path/to/Artalk.css" />
|
|
44
|
+
*/
|
|
45
|
+
var Artalk = /*#__PURE__*/function (_Component) {
|
|
46
|
+
function Artalk() {
|
|
47
|
+
_classCallCheck(this, Artalk);
|
|
48
|
+
return _callSuper(this, Artalk, arguments);
|
|
49
|
+
}
|
|
50
|
+
_inherits(Artalk, _Component);
|
|
51
|
+
return _createClass(Artalk, [{
|
|
52
|
+
key: "render",
|
|
53
|
+
value: function render() {
|
|
54
|
+
var _this$props = this.props,
|
|
55
|
+
server = _this$props.server,
|
|
56
|
+
site = _this$props.site,
|
|
57
|
+
pageKey = _this$props.pageKey,
|
|
58
|
+
pageTitle = _this$props.pageTitle,
|
|
59
|
+
locale = _this$props.locale,
|
|
60
|
+
darkMode = _this$props.darkMode,
|
|
61
|
+
jsUrl = _this$props.jsUrl,
|
|
62
|
+
cssUrl = _this$props.cssUrl;
|
|
63
|
+
if (!server) {
|
|
64
|
+
return (0, _inferno.createVNode)(1, "div", "notification is-danger", [(0, _inferno.createTextVNode)("You forgot to set the "), (0, _inferno.createVNode)(1, "code", null, "server", 16), (0, _inferno.createTextVNode)(" for Artalk. Please set it in"), (0, _inferno.createTextVNode)(' '), (0, _inferno.createVNode)(1, "code", null, "_config.yml", 16), (0, _inferno.createTextVNode)(".")], 0);
|
|
65
|
+
}
|
|
66
|
+
// Without the dark_mode option, follow the appearance of the page
|
|
67
|
+
var darkModeOption = darkMode === null || typeof darkMode === 'undefined' ? "".concat(getAppearance(), " === 'auto' ? 'auto' : ").concat(isDark()) : JSON.stringify(darkMode);
|
|
68
|
+
// PJAX replaces the element of the previous instance, so destroy it before initializing again
|
|
69
|
+
var js = "if (window.__artalkInstance) {\n window.__artalkInstance.destroy();\n }\n window.__artalkInstance = Artalk.init({\n el: '#artalk-thread',\n server: ".concat(JSON.stringify(server), ",\n ").concat(site ? "site: ".concat(JSON.stringify(site), ",") : '', "\n ").concat(pageKey ? "pageKey: ".concat(JSON.stringify(pageKey), ",") : '', "\n ").concat(pageTitle ? "pageTitle: ".concat(JSON.stringify(pageTitle), ",") : '', "\n ").concat(locale ? "locale: ".concat(JSON.stringify(locale), ",") : '', "\n darkMode: ").concat(darkModeOption, ",\n });");
|
|
70
|
+
return (0, _inferno.createFragment)([(0, _inferno.createVNode)(1, "div", null, null, 1, {
|
|
71
|
+
"id": "artalk-thread"
|
|
72
|
+
}), (0, _inferno.createVNode)(1, "link", null, null, 1, {
|
|
73
|
+
"rel": "stylesheet",
|
|
74
|
+
"href": cssUrl,
|
|
75
|
+
"media": "print",
|
|
76
|
+
"onload": "this.media='all'"
|
|
77
|
+
}), (0, _inferno.createVNode)(1, "script", null, null, 1, {
|
|
78
|
+
"dangerouslySetInnerHTML": {
|
|
79
|
+
__html: loadScripts(jsUrl, js)
|
|
80
|
+
}
|
|
81
|
+
})], 4);
|
|
82
|
+
}
|
|
83
|
+
}]);
|
|
84
|
+
}(Component);
|
|
85
|
+
/**
|
|
86
|
+
* Cacheable Artalk comment JSX component.
|
|
87
|
+
* <p>
|
|
88
|
+
* This class is supposed to be used in combination with the <code>locals</code> hexo filter
|
|
89
|
+
* ({@link module:hexo/filter/locals}).
|
|
90
|
+
*
|
|
91
|
+
* @see module:util/cache.cacheComponent
|
|
92
|
+
* @example
|
|
93
|
+
* <Artalk.Cacheable
|
|
94
|
+
* comment={{
|
|
95
|
+
* server: "https://artalk.example.com",
|
|
96
|
+
* site: "******",
|
|
97
|
+
* locale: "en",
|
|
98
|
+
* dark_mode: false
|
|
99
|
+
* }}
|
|
100
|
+
* page={{ title: "******" }}
|
|
101
|
+
* helper={{ cdn: function() {...} }} />
|
|
102
|
+
*/
|
|
103
|
+
Artalk.Cacheable = cacheComponent(Artalk, 'comment.artalk', function (props) {
|
|
104
|
+
var comment = props.comment,
|
|
105
|
+
helper = props.helper,
|
|
106
|
+
page = props.page;
|
|
107
|
+
return {
|
|
108
|
+
server: comment.server,
|
|
109
|
+
site: comment.site,
|
|
110
|
+
pageKey: comment.page_key,
|
|
111
|
+
pageTitle: page.title,
|
|
112
|
+
locale: comment.locale,
|
|
113
|
+
darkMode: comment.dark_mode,
|
|
114
|
+
jsUrl: helper.cdn('artalk', '2.9.1', 'dist/Artalk.js'),
|
|
115
|
+
cssUrl: helper.cdn('artalk', '2.9.1', 'dist/Artalk.css')
|
|
116
|
+
};
|
|
117
|
+
});
|
|
118
|
+
module.exports = Artalk;
|