hexo-component-inferno 4.1.0 → 4.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.
Files changed (72) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +159 -8
  3. package/asset/js/algolia.js +27 -10
  4. package/asset/js/insight.js +62 -44
  5. package/lib/core/migrate.js +23 -4
  6. package/lib/core/schema.js +31 -9
  7. package/lib/core/view.js +1 -1
  8. package/lib/hexo/filter/locals.js +5 -2
  9. package/lib/hexo/generator/category.js +8 -1
  10. package/lib/hexo/generator/insight.js +8 -15
  11. package/lib/hexo/generator/manifest.js +6 -0
  12. package/lib/hexo/helper/cdn.js +1 -1
  13. package/lib/hexo/tag/message.js +11 -1
  14. package/lib/hexo/tag/tabs.js +28 -5
  15. package/lib/schema/comment/giscus.json +5 -0
  16. package/lib/schema/comment/gitment.json +1 -1
  17. package/lib/schema/comment/valine.json +1 -1
  18. package/lib/schema/comment/waline.json +1 -1
  19. package/lib/schema/misc/open_graph.json +0 -1
  20. package/lib/schema/plugin/waline_pageview.json +1 -1
  21. package/lib/schema/share/addthis.json +1 -1
  22. package/lib/schema/widget/archives.json +23 -0
  23. package/lib/schema/widget/categories.json +27 -0
  24. package/lib/schema/widget/recent_posts.json +5 -0
  25. package/lib/schema/widget/subscribe_email.json +1 -1
  26. package/lib/util/classname.js +1 -1
  27. package/lib/util/deprecate.js +28 -0
  28. package/lib/util/html.js +51 -0
  29. package/lib/util/script.js +30 -7
  30. package/lib/view/comment/artalk.js +3 -2
  31. package/lib/view/comment/beaudar.js +3 -2
  32. package/lib/view/comment/changyan.js +2 -1
  33. package/lib/view/comment/cusdis.js +2 -1
  34. package/lib/view/comment/disqus.js +3 -1
  35. package/lib/view/comment/disqusjs.js +3 -2
  36. package/lib/view/comment/facebook.js +3 -1
  37. package/lib/view/comment/giscus.js +3 -2
  38. package/lib/view/comment/gitalk.js +4 -2
  39. package/lib/view/comment/gitment.js +7 -2
  40. package/lib/view/comment/isso.js +5 -1
  41. package/lib/view/comment/twikoo.js +5 -1
  42. package/lib/view/comment/utterances.js +3 -2
  43. package/lib/view/comment/valine.js +7 -1
  44. package/lib/view/comment/waline.js +25 -21
  45. package/lib/view/donate/afdian.js +1 -1
  46. package/lib/view/donate/alipay.js +1 -1
  47. package/lib/view/donate/buymeacoffee.js +1 -1
  48. package/lib/view/donate/patreon.js +1 -1
  49. package/lib/view/donate/wechat.js +1 -1
  50. package/lib/view/misc/meta.js +9 -3
  51. package/lib/view/misc/open_graph.js +12 -15
  52. package/lib/view/misc/structured_data.js +8 -9
  53. package/lib/view/misc/web_app.js +15 -6
  54. package/lib/view/plugin/baidu_analytics.js +3 -1
  55. package/lib/view/plugin/cookie_consent.js +3 -1
  56. package/lib/view/plugin/google_analytics.js +3 -1
  57. package/lib/view/plugin/hotjar.js +3 -1
  58. package/lib/view/plugin/matomo.js +3 -1
  59. package/lib/view/plugin/outdated_browser.js +1 -1
  60. package/lib/view/plugin/statcounter.js +3 -1
  61. package/lib/view/plugin/twitter_conversion_tracking.js +3 -1
  62. package/lib/view/plugin/waline_pageview.js +3 -1
  63. package/lib/view/search/algolia.js +3 -1
  64. package/lib/view/search/baidu.js +3 -1
  65. package/lib/view/search/google_cse.js +3 -1
  66. package/lib/view/search/insight.js +4 -2
  67. package/lib/view/share/addthis.js +4 -0
  68. package/lib/view/widget/archives.js +15 -2
  69. package/lib/view/widget/categories.js +20 -10
  70. package/lib/view/widget/links.js +1 -1
  71. package/lib/view/widget/subscribe_email.js +5 -0
  72. package/package.json +4 -2
@@ -38,6 +38,12 @@ module.exports = function (hexo) {
38
38
  if (!manifest.start_url) {
39
39
  manifest.start_url = url_for('/index.html');
40
40
  }
41
+ if (Array.isArray(manifest.icons)) {
42
+ // Resolve the icons against the root of the site, like start_url
43
+ manifest.icons = manifest.icons.map(icon => icon && icon.src ? Object.assign({}, icon, {
44
+ src: url_for(icon.src)
45
+ }) : icon);
46
+ }
41
47
  return {
42
48
  path: '/manifest.json',
43
49
  data: JSON.stringify(manifest)
@@ -70,7 +70,7 @@ const UNPKG_FIXTURES = {
70
70
  *
71
71
  * // Use the function below to insert FontAwesome icon font CSS URL.
72
72
  * iconcdn();
73
- * // -> https://use.fontawesome.com/releases/v5.15.2/css/all.css
73
+ * // -> https://use.fontawesome.com/releases/v6.0.0/css/all.css
74
74
  */
75
75
  module.exports = function (hexo) {
76
76
  function applyFixture(fixture, _package, version, filename) {
@@ -3,6 +3,16 @@
3
3
  * @module hexo/tag/message
4
4
  */
5
5
 
6
+ /**
7
+ * Split a tag option at its first colon, so that the value can contain colons, as in
8
+ * <code>'title:Step 1: Install'</code>.
9
+ * @private
10
+ */
11
+ function splitOption(option) {
12
+ const index = option.indexOf(':');
13
+ return index === -1 ? [option] : [option.slice(0, index), option.slice(index + 1)];
14
+ }
15
+
6
16
  /**
7
17
  * Register custom Hexo tag {% message %}.
8
18
  * <p>
@@ -53,7 +63,7 @@ module.exports = function (hexo) {
53
63
  let classes = '';
54
64
  let header = '';
55
65
  for (const option of options) {
56
- const [key, value] = option.split(':');
66
+ const [key, value] = splitOption(option);
57
67
  switch (key) {
58
68
  case 'size':
59
69
  classes += ` is-${value}`;
@@ -3,6 +3,16 @@
3
3
  * @module hexo/tag/tabs
4
4
  */
5
5
 
6
+ /**
7
+ * Split a tag option at its first colon, so that the value can contain colons, as in
8
+ * <code>'title:Step 1: Install'</code>.
9
+ * @private
10
+ */
11
+ function splitOption(option) {
12
+ const index = option.indexOf(':');
13
+ return index === -1 ? [option] : [option.slice(0, index), option.slice(index + 1)];
14
+ }
15
+
6
16
  /**
7
17
  * Register custom Hexo tag {% tabs %}.
8
18
  * <p>
@@ -151,10 +161,11 @@ module.exports = function (hexo) {
151
161
  }
152
162
  return options;
153
163
  }
164
+ let tabCount = 0;
154
165
  function processTag(options, content) {
155
166
  let classes = '';
156
167
  for (const option of options) {
157
- const [key, value] = option.split(':');
168
+ const [key, value] = splitOption(option);
158
169
  switch (key) {
159
170
  case 'align':
160
171
  classes += ` is-${value}`;
@@ -176,12 +187,14 @@ module.exports = function (hexo) {
176
187
  let contentElements = '';
177
188
  while ((match = pattern.exec(content)) !== null) {
178
189
  const [, tabOptions, tabContent] = match;
179
- let id = 'tab-' + Date.now() + (Math.random() * 1000 | 0);
190
+
191
+ // A counter, as random numbers in the same millisecond could be the same
192
+ let id = 'tab-' + Date.now() + '-' + tabCount++;
180
193
  let icon = '';
181
194
  let title = '';
182
195
  let active = false;
183
196
  for (const option of splitTabOptions(tabOptions)) {
184
- const [key, value] = option.split(':');
197
+ const [key, value] = splitOption(option);
185
198
  switch (key) {
186
199
  case 'id':
187
200
  id = value;
@@ -228,7 +241,12 @@ module.exports = function (hexo) {
228
241
  return;
229
242
  }
230
243
 
231
- const id = '#' + CSS.escape(location.hash.substring(1));
244
+ let hash = location.hash.substring(1);
245
+ try {
246
+ // Non-ASCII IDs are percent-encoded in the URL
247
+ hash = decodeURIComponent(hash);
248
+ } catch (e) {}
249
+ const id = '#' + CSS.escape(hash);
232
250
  const $tabMenu = document.querySelector(\`.tabs a[href="\${id}"]\`);
233
251
  if (!$tabMenu) {
234
252
  return;
@@ -248,7 +266,12 @@ module.exports = function (hexo) {
248
266
  $activeTab.classList.remove('is-hidden');
249
267
  }
250
268
  }
251
- switchTab();
269
+ // The script is in <head>, so wait for the tabs to switch to the tab in the URL
270
+ if (document.readyState === 'loading') {
271
+ document.addEventListener('DOMContentLoaded', switchTab);
272
+ } else {
273
+ switchTab();
274
+ }
252
275
  window.addEventListener('hashchange', switchTab, false);
253
276
  })();
254
277
  </script>`;
@@ -33,6 +33,11 @@
33
33
  "default": "pathname",
34
34
  "nullable": true
35
35
  },
36
+ "term": {
37
+ "type": ["string", "number"],
38
+ "description": "The search term of the discussion when mapping is specific, or the discussion number when mapping is number",
39
+ "nullable": true
40
+ },
36
41
  "strict": {
37
42
  "type": "boolean",
38
43
  "description": "Avoid mismatches due to GitHub's fuzzy searching method when there are multiple discussions with similar titles",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "http://json-schema.org/draft-07/schema#",
3
3
  "$id": "/comment/gitment.json",
4
- "description": "Gitment comment plugin configurations",
4
+ "description": "Gitment comment plugin configurations\nDEPRECATED: Gitment is no longer maintained, and the GitHub sign-in proxy it uses no longer works. Use Giscus, Utterances or Gitalk instead.",
5
5
  "type": "object",
6
6
  "properties": {
7
7
  "type": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "http://json-schema.org/draft-07/schema#",
3
3
  "$id": "/comment/valine.json",
4
- "description": "Valine comment plugin configurations\nWARNING: Valine saves comments, including the commenters' email addresses, in a LeanCloud class that anyone with your public app ID and key can read. Consider Waline or another comment system instead.",
4
+ "description": "Valine comment plugin configurations\nDEPRECATED: LeanCloud, where Valine stores the comments, shuts down on January 12, 2027. Use Waline, Twikoo or another comment system instead.\nWARNING: Valine saves comments, including the commenters' email addresses, in a LeanCloud class that anyone with your public app ID and key can read. Consider Waline or another comment system instead.",
5
5
  "type": "object",
6
6
  "properties": {
7
7
  "type": {
@@ -14,7 +14,7 @@
14
14
  },
15
15
  "path": {
16
16
  "type": "string",
17
- "description": "Article path id."
17
+ "description": "Article path id. A path, such as /posts/hello/, or a JavaScript expression, such as window.location.pathname, which is the default."
18
18
  },
19
19
  "lang": {
20
20
  "type": "string",
@@ -12,7 +12,6 @@
12
12
  "type": {
13
13
  "type": "string",
14
14
  "description": "Page type (og:type) (optional)\nYou should leave this blank for most of the time",
15
- "default": "blog",
16
15
  "nullable": true
17
16
  },
18
17
  "url": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "http://json-schema.org/draft-07/schema#",
3
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",
4
+ "description": "Waline page view counter, true to use the server of the Waline comments. 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
5
  "type": ["boolean", "object"],
6
6
  "properties": {
7
7
  "server_url": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "http://json-schema.org/draft-07/schema#",
3
3
  "$id": "/share/addthis.json",
4
- "description": "Enable AddThis share buttons\nhttps://www.addthis.com/",
4
+ "description": "Enable AddThis share buttons\nDEPRECATED: AddThis shut down on May 31, 2023. Use AddToAny or ShareThis instead.",
5
5
  "type": "object",
6
6
  "properties": {
7
7
  "type": {
@@ -12,6 +12,29 @@
12
12
  "type": "integer",
13
13
  "description": "Amount of archives to show, with a link to the archive page for the rest. Will show all if not set",
14
14
  "nullable": true
15
+ },
16
+ "group_by": {
17
+ "type": "string",
18
+ "enum": ["monthly", "yearly"],
19
+ "description": "Whether to group the archives by month or by year. Groups by month if not set",
20
+ "nullable": true
21
+ },
22
+ "order": {
23
+ "type": "integer",
24
+ "enum": [1, -1],
25
+ "description": "1 to show the oldest archives first, or -1 to show the newest first. Shows the newest first if not set",
26
+ "nullable": true
27
+ },
28
+ "format": {
29
+ "type": "string",
30
+ "description": "Moment.js format of the archive names, such as 'MMMM YYYY' (by month) or 'YYYY' (by year), which are used if not set",
31
+ "nullable": true
32
+ },
33
+ "show_count": {
34
+ "type": "boolean",
35
+ "default": true,
36
+ "description": "Whether to show the number of posts of each archive",
37
+ "nullable": true
15
38
  }
16
39
  },
17
40
  "required": ["type"]
@@ -12,6 +12,33 @@
12
12
  "type": "integer",
13
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
14
  "nullable": true
15
+ },
16
+ "order_by": {
17
+ "type": "string",
18
+ "description": "How to order the categories. For example 'name' to order by name, and 'length' to order by number of posts. Orders by name if not set",
19
+ "nullable": true
20
+ },
21
+ "order": {
22
+ "type": "integer",
23
+ "enum": [1, -1],
24
+ "description": "1 for ascending order, or -1 for descending order. Ascending if not set",
25
+ "nullable": true
26
+ },
27
+ "depth": {
28
+ "type": "integer",
29
+ "description": "Levels of categories to show, for example 1 for the top-level categories only. Shows all levels if not set or 0",
30
+ "nullable": true
31
+ },
32
+ "show_current": {
33
+ "type": "boolean",
34
+ "description": "Whether to highlight the categories of the current post",
35
+ "nullable": true
36
+ },
37
+ "show_count": {
38
+ "type": "boolean",
39
+ "default": true,
40
+ "description": "Whether to show the number of posts of each category",
41
+ "nullable": true
15
42
  }
16
43
  },
17
44
  "required": ["type"]
@@ -7,6 +7,11 @@
7
7
  "type": {
8
8
  "type": "string",
9
9
  "const": "recent_posts"
10
+ },
11
+ "limit": {
12
+ "type": "integer",
13
+ "description": "Number of recent posts to show. Shows 5 if not set",
14
+ "nullable": true
10
15
  }
11
16
  },
12
17
  "required": ["type"]
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "http://json-schema.org/draft-07/schema#",
3
3
  "$id": "/widget/subscribe_email.json",
4
- "description": "Google FeedBurner email subscription widget configurations",
4
+ "description": "Google FeedBurner email subscription widget configurations\nDEPRECATED: Google FeedBurner stopped email subscriptions in July 2021. Use the follow.it widget instead.",
5
5
  "type": "object",
6
6
  "properties": {
7
7
  "type": {
@@ -19,7 +19,7 @@ module.exports = function (classname) {
19
19
  if (Array.isArray(classname)) {
20
20
  return classname.join(' ');
21
21
  }
22
- if (typeof classname === 'object') {
22
+ if (classname !== null && typeof classname === 'object') {
23
23
  return Object.keys(classname).filter(key => !!classname[key]).join(' ');
24
24
  }
25
25
  throw new Error('Cannot process class name ' + JSON.stringify(classname));
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Utility functions for warning about deprecated components.
3
+ * @module util/deprecate
4
+ */
5
+
6
+ const warned = new Set();
7
+
8
+ /**
9
+ * Print a warning about a deprecated component, once per component.
10
+ * <p>
11
+ * Components are rendered for every page, so the warning is only printed the first time.
12
+ *
13
+ * @param {string} name Name of the component, such as <code>share.addthis</code>.
14
+ * @param {string} message Why the component is deprecated, and what to use instead.
15
+ * @example
16
+ * deprecate('share.addthis', 'AddThis shut down on May 31, 2023. Use AddToAny or ShareThis instead.');
17
+ */
18
+ function deprecate(name, message) {
19
+ if (warned.has(name)) {
20
+ return;
21
+ }
22
+ warned.add(name);
23
+ // eslint-disable-next-line no-console
24
+ console.warn(`hexo-component-inferno: ${name} is deprecated. ${message}`);
25
+ }
26
+ module.exports = {
27
+ deprecate
28
+ };
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Utility functions for HTML text.
3
+ * @module util/html
4
+ */
5
+ const {
6
+ stripHTML
7
+ } = require('hexo-util');
8
+ const ENTITIES = {
9
+ amp: '&',
10
+ lt: '<',
11
+ gt: '>',
12
+ quot: '"',
13
+ apos: "'",
14
+ nbsp: ' '
15
+ };
16
+
17
+ /**
18
+ * Decode the character references in HTML text, such as <code>&amp;amp;</code>,
19
+ * <code>&amp;#39;</code> and <code>&amp;#x1F600;</code>.
20
+ * <p>
21
+ * Numeric references and the named ones that Markdown renderers output are decoded. Other named
22
+ * references are kept as they are.
23
+ *
24
+ * @param {string} str HTML text.
25
+ * @returns {string} The text.
26
+ */
27
+ function decodeHTML(str) {
28
+ return str.replace(/&(#x[\da-f]+|#\d+|[a-z]+);/gi, (match, entity) => {
29
+ if (entity[0] === '#') {
30
+ const code = entity[1] === 'x' || entity[1] === 'X' ? parseInt(entity.slice(2), 16) : parseInt(entity.slice(1), 10);
31
+ return code <= 0x10ffff ? String.fromCodePoint(code) : match;
32
+ }
33
+ const char = ENTITIES[entity.toLowerCase()];
34
+ return char === undefined ? match : char;
35
+ });
36
+ }
37
+
38
+ /**
39
+ * Convert HTML to plain text on one line, for example to index or describe a page.
40
+ *
41
+ * @param {string} html HTML.
42
+ * @returns {string} The text, with the tags removed, the character references decoded, and the
43
+ * whitespace collapsed.
44
+ */
45
+ function toPlainText(html) {
46
+ return decodeHTML(stripHTML(html || '')).replace(/\s+/g, ' ').trim();
47
+ }
48
+ module.exports = {
49
+ decodeHTML,
50
+ toPlainText
51
+ };
@@ -3,6 +3,23 @@
3
3
  * @module util/script
4
4
  */
5
5
 
6
+ /**
7
+ * Convert a value to JavaScript code that can be put in an inline <code>&lt;script&gt;</code>.
8
+ * <p>
9
+ * Unlike <code>JSON.stringify</code> alone, it escapes <code>&lt;</code>, so that a value containing
10
+ * <code>&lt;/script&gt;</code>, such as a page title, cannot end the inline script, and the line
11
+ * separators U+2028 and U+2029, which older browsers do not allow in JavaScript strings.
12
+ *
13
+ * @param {any} value A value that can be converted to JSON.
14
+ * @returns {string} The JavaScript code.
15
+ *
16
+ * @example
17
+ * toJs('</script>'); // '"\\u003c/script>"'
18
+ */
19
+ function toJs(value) {
20
+ return JSON.stringify(value).replace(/</g, '\\u003c').replace(/\u2028/g, '\\u2028').replace(/\u2029/g, '\\u2029');
21
+ }
22
+
6
23
  /**
7
24
  * Build an inline script that loads external scripts asynchronously and in order, and then runs the
8
25
  * given code.
@@ -22,8 +39,8 @@
22
39
  */
23
40
  function loadScripts(urls, code, attrs = {}) {
24
41
  return `(function () {
25
- var urls = ${JSON.stringify([].concat(urls))};
26
- var attrs = ${JSON.stringify(attrs)};
42
+ var urls = ${toJs([].concat(urls))};
43
+ var attrs = ${toJs(attrs)};
27
44
  function run() {
28
45
  ${code}
29
46
  }
@@ -54,6 +71,11 @@ function loadScripts(urls, code, attrs = {}) {
54
71
  script.addEventListener('load', function () {
55
72
  this.setAttribute('data-loaded', 'true');
56
73
  });
74
+ // Remove a script that fails to load, so that the next run, e.g., after a PJAX page switch,
75
+ // adds it again instead of waiting for it
76
+ script.addEventListener('error', function () {
77
+ this.remove();
78
+ });
57
79
  document.head.appendChild(script);
58
80
  }
59
81
  script.addEventListener('load', function () {
@@ -87,19 +109,19 @@ function loadScripts(urls, code, attrs = {}) {
87
109
  * });
88
110
  */
89
111
  function appendScript(selector, url, attrs, dynamicAttrs = {}) {
90
- const dynamic = Object.keys(dynamicAttrs).map(name => `attrs[${JSON.stringify(name)}] = ${dynamicAttrs[name]};`).join('\n ');
112
+ const dynamic = Object.keys(dynamicAttrs).map(name => `attrs[${toJs(name)}] = ${dynamicAttrs[name]};`).join('\n ');
91
113
  return `(function () {
92
- var element = document.querySelector(${JSON.stringify(selector)});
114
+ var element = document.querySelector(${toJs(selector)});
93
115
  if (!element) {
94
116
  return;
95
117
  }
96
- var attrs = ${JSON.stringify(attrs)};
118
+ var attrs = ${toJs(attrs)};
97
119
  ${dynamic}
98
120
  var script = document.createElement('script');
99
121
  for (var name in attrs) {
100
122
  script.setAttribute(name, attrs[name]);
101
123
  }
102
- script.src = ${JSON.stringify(url)};
124
+ script.src = ${toJs(url)};
103
125
  script.async = true;
104
126
  setTimeout(function () {
105
127
  element.appendChild(script);
@@ -107,4 +129,5 @@ function appendScript(selector, url, attrs, dynamicAttrs = {}) {
107
129
  })();`;
108
130
  }
109
131
  module.exports = loadScripts;
110
- module.exports.appendScript = appendScript;
132
+ module.exports.appendScript = appendScript;
133
+ module.exports.toJs = toJs;
@@ -23,6 +23,7 @@ var _require = require('inferno'),
23
23
  var _require2 = require('../../util/cache'),
24
24
  cacheComponent = _require2.cacheComponent;
25
25
  var loadScripts = require('../../util/script');
26
+ var toJs = loadScripts.toJs;
26
27
  var _require3 = require('../../util/appearance'),
27
28
  getAppearance = _require3.getAppearance,
28
29
  isDark = _require3.isDark;
@@ -64,9 +65,9 @@ var Artalk = /*#__PURE__*/function (_Component) {
64
65
  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
  }
66
67
  // 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
+ var darkModeOption = darkMode === null || typeof darkMode === 'undefined' ? "".concat(getAppearance(), " === 'auto' ? 'auto' : ").concat(isDark()) : toJs(darkMode);
68
69
  // 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
+ var js = "if (window.__artalkInstance) {\n window.__artalkInstance.destroy();\n }\n window.__artalkInstance = Artalk.init({\n el: '#artalk-thread',\n server: ".concat(toJs(server), ",\n ").concat(site ? "site: ".concat(toJs(site), ",") : '', "\n ").concat(pageKey ? "pageKey: ".concat(toJs(pageKey), ",") : '', "\n ").concat(pageTitle ? "pageTitle: ".concat(toJs(pageTitle), ",") : '', "\n ").concat(locale ? "locale: ".concat(toJs(locale), ",") : '', "\n darkMode: ").concat(darkModeOption, ",\n });");
70
71
  return (0, _inferno.createFragment)([(0, _inferno.createVNode)(1, "div", null, null, 1, {
71
72
  "id": "artalk-thread"
72
73
  }), (0, _inferno.createVNode)(1, "link", null, null, 1, {
@@ -23,7 +23,8 @@ var _require = require('inferno'),
23
23
  var _require2 = require('../../util/cache'),
24
24
  cacheComponent = _require2.cacheComponent;
25
25
  var _require3 = require('../../util/script'),
26
- appendScript = _require3.appendScript;
26
+ appendScript = _require3.appendScript,
27
+ toJs = _require3.toJs;
27
28
  var _require4 = require('../../util/appearance'),
28
29
  isDark = _require4.isDark;
29
30
 
@@ -80,7 +81,7 @@ var Beaudar = /*#__PURE__*/function (_Component) {
80
81
  config.crossorigin = 'anonymous';
81
82
  // Use the dark theme when the page looks dark
82
83
  var js = appendScript('#beaudar-thread', 'https://beaudar.lipk.org/client.js', config, {
83
- theme: "".concat(isDark(), " ? ").concat(JSON.stringify(darkTheme || 'github-dark'), " : ").concat(JSON.stringify(theme || 'github-light'))
84
+ theme: "".concat(isDark(), " ? ").concat(toJs(darkTheme || 'github-dark'), " : ").concat(toJs(theme || 'github-light'))
84
85
  });
85
86
  return (0, _inferno.createFragment)([(0, _inferno.createVNode)(1, "div", null, null, 1, {
86
87
  "id": "beaudar-thread"
@@ -23,6 +23,7 @@ var _require = require('inferno'),
23
23
  var _require2 = require('../../util/cache'),
24
24
  cacheComponent = _require2.cacheComponent;
25
25
  var loadScripts = require('../../util/script');
26
+ var toJs = loadScripts.toJs;
26
27
 
27
28
  /**
28
29
  * ChangYan comment JSX component.
@@ -50,7 +51,7 @@ var ChangYan = /*#__PURE__*/function (_Component) {
50
51
  if (!appId || !conf) {
51
52
  return (0, _inferno.createVNode)(1, "div", "notification is-danger", [(0, _inferno.createTextVNode)("You forgot to set the "), (0, _inferno.createVNode)(1, "code", null, "app_id", 16), (0, _inferno.createTextVNode)(" or "), (0, _inferno.createVNode)(1, "code", null, "conf", 16), (0, _inferno.createTextVNode)(" for Changyan. Please set it in "), (0, _inferno.createVNode)(1, "code", null, "_config.yml", 16), (0, _inferno.createTextVNode)(".")], 4);
52
53
  }
53
- var js = "window.changyan.api.config({appid: '".concat(appId, "',conf: '").concat(conf, "'});");
54
+ var js = "window.changyan.api.config({appid: ".concat(toJs(appId), ",conf: ").concat(toJs(conf), "});");
54
55
  /* eslint-disable react/no-unknown-property */
55
56
  return (0, _inferno.createFragment)([(0, _inferno.createVNode)(1, "div", null, null, 1, {
56
57
  "id": "SOHUCS",
@@ -23,6 +23,7 @@ var _require = require('inferno'),
23
23
  var _require2 = require('../../util/cache'),
24
24
  cacheComponent = _require2.cacheComponent;
25
25
  var loadScripts = require('../../util/script');
26
+ var toJs = loadScripts.toJs;
26
27
  var _require3 = require('../../util/appearance'),
27
28
  getAppearance = _require3.getAppearance;
28
29
 
@@ -68,7 +69,7 @@ var Cusdis = /*#__PURE__*/function (_Component) {
68
69
  // Without the theme option, follow the appearance of the page (light, dark, or auto, the same values
69
70
  // as the themes of Cusdis). The Cusdis script renders #cusdis_thread when it loads, so render it
70
71
  // directly only when the script is already loaded, e.g., when PJAX runs this code again.
71
- var js = "(function () {\n var element = document.getElementById('cusdis_thread');\n if (!element) {\n return;\n }\n element.setAttribute('data-theme', ".concat(theme ? JSON.stringify(theme) : getAppearance(), ");\n if (window.renderCusdis) {\n window.renderCusdis(element);\n return;\n }\n ").concat(loadScripts(urls, ''), "\n })();");
72
+ var js = "(function () {\n var element = document.getElementById('cusdis_thread');\n if (!element) {\n return;\n }\n element.setAttribute('data-theme', ".concat(theme ? toJs(theme) : getAppearance(), ");\n if (window.renderCusdis) {\n window.renderCusdis(element);\n return;\n }\n ").concat(loadScripts(urls, ''), "\n })();");
72
73
  return (0, _inferno.createFragment)([(0, _inferno.createVNode)(1, "div", null, null, 1, {
73
74
  "id": "cusdis_thread",
74
75
  "data-host": host,
@@ -22,6 +22,8 @@ var _require = require('inferno'),
22
22
  Component = _require.Component;
23
23
  var _require2 = require('../../util/cache'),
24
24
  cacheComponent = _require2.cacheComponent;
25
+ var _require3 = require('../../util/script'),
26
+ toJs = _require3.toJs;
25
27
 
26
28
  /**
27
29
  * Disqus comment JSX component.
@@ -51,7 +53,7 @@ var Disqus = /*#__PURE__*/function (_Component) {
51
53
  if (!shortname) {
52
54
  return (0, _inferno.createVNode)(1, "div", "notification is-danger", [(0, _inferno.createTextVNode)("You forgot to set the "), (0, _inferno.createVNode)(1, "code", null, "shortname", 16), (0, _inferno.createTextVNode)(" for Disqus. Please set it in"), (0, _inferno.createTextVNode)(' '), (0, _inferno.createVNode)(1, "code", null, "_config.yml", 16), (0, _inferno.createTextVNode)(".")], 0);
53
55
  }
54
- var js = "var disqus_config = function () {\n this.page.url = '".concat(permalink, "';\n this.page.identifier = '").concat(disqusId || path, "';\n };\n (function() {\n var d = document, s = d.createElement('script'); \n s.src = '//' + '").concat(shortname, "' + '.disqus.com/embed.js';\n s.setAttribute('data-timestamp', +new Date());\n (d.head || d.body).appendChild(s);\n })();");
56
+ var js = "var disqus_config = function () {\n this.page.url = ".concat(toJs(permalink), ";\n this.page.identifier = ").concat(toJs(disqusId || path), ";\n };\n (function() {\n var d = document, s = d.createElement('script'); \n s.src = ").concat(toJs("//".concat(shortname, ".disqus.com/embed.js")), ";\n s.setAttribute('data-timestamp', +new Date());\n (d.head || d.body).appendChild(s);\n })();");
55
57
  return (0, _inferno.createFragment)([(0, _inferno.createVNode)(1, "div", null, (0, _inferno.createVNode)(1, "noscript", null, [(0, _inferno.createTextVNode)("Please enable JavaScript to view the"), (0, _inferno.createTextVNode)(' '), (0, _inferno.createVNode)(1, "a", null, "comments powered by Disqus.", 16, {
56
58
  "href": "//disqus.com/?ref_noscript"
57
59
  })], 0), 2, {
@@ -23,6 +23,7 @@ var _require = require('inferno'),
23
23
  var _require2 = require('../../util/cache'),
24
24
  cacheComponent = _require2.cacheComponent;
25
25
  var loadScripts = require('../../util/script');
26
+ var toJs = loadScripts.toJs;
26
27
 
27
28
  /**
28
29
  * DisqusJS comment JSX component.
@@ -67,12 +68,12 @@ var DisqusJs = /*#__PURE__*/function (_Component) {
67
68
  siteTitle = _this$props.siteTitle,
68
69
  jsUrl = _this$props.jsUrl,
69
70
  cssUrl = _this$props.cssUrl;
70
- if (!shortname) {
71
+ if (!shortname || !apiKey) {
71
72
  return (0, _inferno.createVNode)(1, "div", "notification is-danger", [(0, _inferno.createTextVNode)("You forgot to set the "), (0, _inferno.createVNode)(1, "code", null, "shortname", 16), (0, _inferno.createTextVNode)(" or "), (0, _inferno.createVNode)(1, "code", null, "api_key", 16), (0, _inferno.createTextVNode)(" for Disqus. Please set it in "), (0, _inferno.createVNode)(1, "code", null, "_config.yml", 16), (0, _inferno.createTextVNode)(".")], 4);
72
73
  }
73
74
  var url = permalink || path;
74
75
  var identifier = disqusId || path;
75
- var js = "new DisqusJS({\n shortname: '".concat(shortname, "',\n apikey: ").concat(JSON.stringify(apiKey), ",\n ").concat(siteTitle ? "siteName: ".concat(JSON.stringify(siteTitle), ",") : '', "\n ").concat(identifier ? "identifier: ".concat(JSON.stringify(identifier), ",") : '', "\n ").concat(url ? "url: ".concat(JSON.stringify(url), ",") : '', "\n ").concat(pageTitle ? "title: ".concat(JSON.stringify(pageTitle), ",") : '', "\n ").concat(api ? "api: ".concat(JSON.stringify(api), ",") : '', "\n ").concat(admin ? "admin: ".concat(JSON.stringify(admin), ",") : '', "\n ").concat(adminLabel ? "adminLabel: ".concat(JSON.stringify(adminLabel), ",") : '', "\n ").concat(nesting ? "nesting: ".concat(JSON.stringify(nesting), ",") : '', "\n });");
76
+ var js = "new DisqusJS({\n shortname: ".concat(toJs(shortname), ",\n apikey: ").concat(toJs(apiKey), ",\n ").concat(siteTitle ? "siteName: ".concat(toJs(siteTitle), ",") : '', "\n ").concat(identifier ? "identifier: ".concat(toJs(identifier), ",") : '', "\n ").concat(url ? "url: ".concat(toJs(url), ",") : '', "\n ").concat(pageTitle ? "title: ".concat(toJs(pageTitle), ",") : '', "\n ").concat(api ? "api: ".concat(toJs(api), ",") : '', "\n ").concat(admin ? "admin: ".concat(toJs(admin), ",") : '', "\n ").concat(adminLabel ? "adminLabel: ".concat(toJs(adminLabel), ",") : '', "\n ").concat(nesting ? "nesting: ".concat(toJs(nesting), ",") : '', "\n });");
76
77
  return (0, _inferno.createFragment)([(0, _inferno.createVNode)(1, "link", null, null, 1, {
77
78
  "rel": "stylesheet",
78
79
  "href": cssUrl,
@@ -22,6 +22,8 @@ var _require = require('inferno'),
22
22
  Component = _require.Component;
23
23
  var _require2 = require('../../util/cache'),
24
24
  cacheComponent = _require2.cacheComponent;
25
+ var _require3 = require('../../util/script'),
26
+ toJs = _require3.toJs;
25
27
 
26
28
  /**
27
29
  * Facebook comment JSX component.
@@ -45,7 +47,7 @@ var Facebook = /*#__PURE__*/function (_Component) {
45
47
  language = _this$props.language,
46
48
  permalink = _this$props.permalink;
47
49
  var fbLanguage = language.split('-').join('_');
48
- var js = "(function(d, s, id) {\n var js, fjs = d.getElementsByTagName(s)[0];\n if (d.getElementById(id)) return;\n js = d.createElement(s); js.id = id;\n js.src = \"//connect.facebook.net/".concat(fbLanguage, "/sdk.js#xfbml=1&version=v12.0\";\n fjs.parentNode.insertBefore(js, fjs);\n }(document, 'script', 'facebook-jssdk'));");
50
+ var js = "(function(d, s, id) {\n var js, fjs = d.getElementsByTagName(s)[0];\n // After a PJAX page switch, the SDK is loaded, so render the new comments box with it\n if (d.getElementById(id)) {\n if (window.FB) FB.XFBML.parse();\n return;\n }\n js = d.createElement(s); js.id = id;\n js.src = ".concat(toJs("//connect.facebook.net/".concat(fbLanguage, "/sdk.js#xfbml=1&version=v12.0")), ";\n fjs.parentNode.insertBefore(js, fjs);\n }(document, 'script', 'facebook-jssdk'));");
49
51
  return (0, _inferno.createFragment)([(0, _inferno.createVNode)(1, "div", "fb-comments", null, 1, {
50
52
  "data-width": "100%",
51
53
  "data-href": permalink,
@@ -23,7 +23,8 @@ var _require = require('inferno'),
23
23
  var _require2 = require('../../util/cache'),
24
24
  cacheComponent = _require2.cacheComponent;
25
25
  var _require3 = require('../../util/script'),
26
- appendScript = _require3.appendScript;
26
+ appendScript = _require3.appendScript,
27
+ toJs = _require3.toJs;
27
28
  var _require4 = require('../../util/appearance'),
28
29
  isDark = _require4.isDark;
29
30
 
@@ -124,7 +125,7 @@ var Giscus = /*#__PURE__*/function (_Component) {
124
125
  return (0, _inferno.createVNode)(1, "div", "notification is-danger", [(0, _inferno.createTextVNode)("You set "), (0, _inferno.createVNode)(1, "code", null, "theme", 16), (0, _inferno.createTextVNode)(" to "), (0, _inferno.createVNode)(1, "code", null, "custom", 16), (0, _inferno.createTextVNode)(", but did not apply a"), (0, _inferno.createTextVNode)(' '), (0, _inferno.createVNode)(1, "code", null, "customThemeCss", 16), (0, _inferno.createTextVNode)(" for Giscus. Please set it in "), (0, _inferno.createVNode)(1, "code", null, "_config.yml", 16), (0, _inferno.createTextVNode)(".")], 0);
125
126
  }
126
127
  } else {
127
- dynamicConfig['data-theme'] = "".concat(isDark(), " ? ").concat(JSON.stringify(darkTheme || 'noborder_dark'), " : ").concat(JSON.stringify(theme || 'noborder_light'));
128
+ dynamicConfig['data-theme'] = "".concat(isDark(), " ? ").concat(toJs(darkTheme || 'noborder_dark'), " : ").concat(toJs(theme || 'noborder_light'));
128
129
  }
129
130
  if (lang) {
130
131
  config['data-lang'] = lang;