hexo-theme-fluid 1.9.1 → 1.9.2

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/_config.yml CHANGED
@@ -291,7 +291,7 @@ web_analytics: # 网页访问统计
291
291
  # Get the attribute of the page path during statistics
292
292
  path: window.location.pathname
293
293
  # 开启后不统计本地路径( localhost 与 127.0.0.1 )
294
- # If ture, ignore localhost & 127.0.0.1
294
+ # If true, ignore localhost & 127.0.0.1
295
295
  ignore_local: false
296
296
 
297
297
  # 对页面中的图片和评论插件进行懒加载处理,可见范围外的元素不会提前加载
@@ -1080,7 +1080,7 @@ static_prefix:
1080
1080
 
1081
1081
  mermaid: https://lib.baomitu.com/mermaid/8.14.0/
1082
1082
 
1083
- valine: https://lib.baomitu.com/valine/1.4.18/
1083
+ valine: https://lib.baomitu.com/valine/1.4.17/
1084
1084
 
1085
1085
  waline: https://lib.baomitu.com/waline/2.5.1/
1086
1086
 
@@ -43,6 +43,7 @@ var ogConfig = Object.assign({ image: ogImage && url_for(ogImage) }, theme.open_
43
43
  <%- export_config() %>
44
44
  <%- js_ex(theme.static_prefix.internal_js, 'utils.js') %>
45
45
  <%- js_ex(theme.static_prefix.internal_js, 'color-schema.js') %>
46
+ <%- partial('_partials/plugins/analytics.ejs') %>
46
47
 
47
48
  <%- inject_point('head') %>
48
49
  </head>
@@ -0,0 +1,24 @@
1
+ <% import_css(theme.static_prefix.github_markdown, 'github-markdown.min.css') %>
2
+ <% import_css(theme.static_prefix.hint, 'hint.min.css') %>
3
+
4
+ <% if (theme.code.highlight.enable) { %>
5
+ <%- partial('_partials/plugins/highlight.ejs') %>
6
+ <% } %>
7
+ <% if ((theme.code.language.enable && theme.code.language.default) || theme.code.copy_btn) { %>
8
+ <%- partial('_partials/plugins/code-widget.ejs') %>
9
+ <% } %>
10
+ <% if (theme.fun_features.anchorjs.enable && page.anchorjs !== false) { %>
11
+ <%- partial('_partials/plugins/anchorjs.ejs') %>
12
+ <% } %>
13
+ <% if (theme.post.image_zoom.enable && page.image_zoom !== false) { %>
14
+ <%- partial('_partials/plugins/fancybox.ejs') %>
15
+ <% } %>
16
+ <% if (theme.post.image_caption.enable) { %>
17
+ <% import_script('<script>Fluid.plugins.imageCaption();</script>') %>
18
+ <% } %>
19
+ <% if (theme.post.math.enable && (!theme.post.math.specific || (theme.post.math.specific && page.math))) { %>
20
+ <%- partial('_partials/plugins/math.ejs') %>
21
+ <% } %>
22
+ <% if (theme.post.mermaid.enable && (!theme.post.mermaid.specific || (theme.post.mermaid.specific && page.mermaid))) { %>
23
+ <%- partial('_partials/plugins/mermaid.ejs') %>
24
+ <% } %>
@@ -2,7 +2,7 @@
2
2
 
3
3
  <% if(theme.web_analytics.baidu) { %>
4
4
  <!-- Baidu Analytics -->
5
- <script defer>
5
+ <script async>
6
6
  if (!Fluid.ctx.dnt) {
7
7
  var _hmt = _hmt || [];
8
8
  (function() {
@@ -17,7 +17,7 @@
17
17
 
18
18
  <% if (theme.web_analytics.google){ %>
19
19
  <!-- Google Analytics -->
20
- <script defer>
20
+ <script async>
21
21
  if (!Fluid.ctx.dnt) {
22
22
  Fluid.utils.createScript('https://www.google-analytics.com/analytics.js', function() {
23
23
  window.ga = window.ga || function() { (ga.q = ga.q || []).push(arguments) };
@@ -31,7 +31,7 @@
31
31
 
32
32
  <% if (theme.web_analytics.gtag){ %>
33
33
  <!-- Google gtag.js -->
34
- <script defer>
34
+ <script async>
35
35
  if (!Fluid.ctx.dnt) {
36
36
  Fluid.utils.createScript('https://www.googletagmanager.com/gtag/js?id=<%= theme.web_analytics.gtag %>', function() {
37
37
  window.dataLayer = window.dataLayer || [];
@@ -45,7 +45,7 @@
45
45
 
46
46
  <% if(theme.web_analytics.tencent && theme.web_analytics.tencent.sid && theme.web_analytics.tencent.cid) { %>
47
47
  <!-- Tencent Analytics -->
48
- <script defer>
48
+ <script async>
49
49
  if (!Fluid.ctx.dnt) {
50
50
  var _mtac = {};
51
51
  (function() {
@@ -65,7 +65,7 @@
65
65
 
66
66
  <% if(theme.web_analytics.woyaola) { %>
67
67
  <!-- 51.la Analytics -->
68
- <script defer>
68
+ <script async>
69
69
  if (!Fluid.ctx.dnt) {
70
70
  Fluid.utils.createScript('//js.users.51.la/<%= theme.web_analytics.woyaola %>.js');
71
71
  }
@@ -74,7 +74,7 @@
74
74
 
75
75
  <% if(theme.web_analytics.cnzz) { %>
76
76
  <!-- cnzz Analytics -->
77
- <script defer>
77
+ <script async>
78
78
  if (!Fluid.ctx.dnt) {
79
79
  Fluid.utils.createScript('//s4.cnzz.com/z_stat.php?id=<%= theme.web_analytics.cnzz %>&show=pic');
80
80
  }
@@ -1,71 +1,7 @@
1
1
  <%
2
- import_script(`<script>
3
- (function() {
4
- var enableLang = CONFIG.code_language.enable && CONFIG.code_language.default;
5
- var enableCopy = CONFIG.copy_btn;
6
- if (!enableLang && !enableCopy) {
7
- return;
8
- }
9
-
10
- function getBgClass(ele) {
11
- return Fluid.utils.getBackgroundLightness(ele) >= 0 ? 'code-widget-light' : 'code-widget-dark';
12
- }
13
-
14
- var copyTmpl = '';
15
- copyTmpl += '<div class="code-widget">';
16
- copyTmpl += 'LANG';
17
- copyTmpl += '</div>';
18
- jQuery('.markdown-body pre').each(function() {
19
- var $pre = jQuery(this);
20
- if ($pre.find('code.mermaid').length > 0) {
21
- return;
22
- }
23
- if ($pre.find('span.line').length > 0) {
24
- return;
25
- }
26
-
27
- var lang = '';
28
-
29
- if (enableLang) {
30
- lang = CONFIG.code_language.default;
31
- if ($pre[0].children.length > 0 && $pre[0].children[0].classList.length >= 2 && $pre.children().hasClass('hljs')) {
32
- lang = $pre[0].children[0].classList[1];
33
- } else if ($pre[0].getAttribute('data-language')) {
34
- lang = $pre[0].getAttribute('data-language');
35
- } else if ($pre.parent().hasClass('sourceCode') && $pre[0].children.length > 0 && $pre[0].children[0].classList.length >= 2) {
36
- lang = $pre[0].children[0].classList[1];
37
- $pre.parent().addClass('code-wrapper');
38
- } else if ($pre.parent().hasClass('markdown-body') && $pre[0].classList.length === 0) {
39
- $pre.wrap('<div class="code-wrapper"></div>');
40
- }
41
- lang = lang.toUpperCase().replace('NONE', CONFIG.code_language.default);
42
- }
43
- $pre.append(copyTmpl.replace('LANG', lang).replace('code-widget">',
44
- getBgClass($pre[0]) + (enableCopy ? ' code-widget copy-btn" data-clipboard-snippet><i class="iconfont icon-copy"></i>' : ' code-widget">')));
45
-
46
- if (enableCopy) {
47
- Fluid.utils.createScript('${url_join(theme.static_prefix.clipboard, 'clipboard.min.js')}', function() {
48
- var clipboard = new window.ClipboardJS('.copy-btn', {
49
- target: function(trigger) {
50
- var nodes = trigger.parentNode.childNodes;
51
- for (var i = 0; i < nodes.length; i++) {
52
- if (nodes[i].tagName === 'CODE') {
53
- return nodes[i];
54
- }
55
- }
56
- }
57
- });
58
- clipboard.on('success', function(e) {
59
- e.clearSelection();
60
- e.trigger.innerHTML = e.trigger.innerHTML.replace('icon-copy', 'icon-success');
61
- setTimeout(function() {
62
- e.trigger.innerHTML = e.trigger.innerHTML.replace('icon-success', 'icon-copy');
63
- }, 2000);
64
- });
65
- });
66
- }
67
- });
68
- })();
69
- </script>
2
+ if (theme.code.copy_btn) {
3
+ import_script(`<script src=${url_join(theme.static_prefix.clipboard, 'clipboard.min.js')}></script>`)
4
+ }
5
+ import_script(`<script>Fluid.plugins.codeWidget();</script>
70
6
  `)
71
7
  %>
@@ -0,0 +1,18 @@
1
+ <%
2
+ import_script(`
3
+ <script defer>
4
+ if (document.getElementById('hbePass')) {
5
+ Fluid.utils.waitElementLoaded('hbe-prefix', function() {
6
+ var hbePrefix = document.querySelector('hbe-prefix');
7
+ hbePrefix.parentElement.classList.add('markdown-body');
8
+ Fluid.utils.retry(function() {
9
+ if (Fluid.boot && Fluid.boot.refreshPlugins) {
10
+ Fluid.boot.refreshPlugins();
11
+ return true;
12
+ }
13
+ }, 100, 10);
14
+ })
15
+ }
16
+ </script>
17
+ `)
18
+ %>
@@ -4,37 +4,33 @@
4
4
 
5
5
  import_script(`
6
6
  <script>
7
- MathJax = {
8
- tex : {
9
- inlineMath: { '[+]': [['$', '$']] }
10
- },
11
- loader : {
12
- ${ lazy ? 'load: \[\'ui/lazy\'\]' : '' }
13
- },
14
- options: {
15
- renderActions: {
16
- findScript : [10, doc => {
17
- document.querySelectorAll('script[type^="math/tex"]').forEach(node => {
18
- const display = !!node.type.match(/; *mode=display/);
19
- const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display);
20
- const text = document.createTextNode('');
21
- node.parentNode.replaceChild(text, node);
22
- math.start = { node: text, delim: '', n: 0 };
23
- math.end = { node: text, delim: '', n: 0 };
24
- doc.math.push(math);
25
- });
26
- }, '', false],
27
- insertedScript: [200, () => {
28
- document.querySelectorAll('mjx-container').forEach(node => {
29
- let target = node.parentNode;
30
- if (target.nodeName.toLowerCase() === 'li') {
31
- target.parentNode.classList.add('has-jax');
32
- }
33
- });
34
- }, '', false]
7
+ if (!window.MathJax) {
8
+ window.MathJax = {
9
+ tex : {
10
+ inlineMath: { '[+]': [['$', '$']] }
11
+ },
12
+ loader : {
13
+ ${ lazy ? 'load: \[\'ui/lazy\'\]' : '' }
14
+ },
15
+ options: {
16
+ renderActions: {
17
+ insertedScript: [200, () => {
18
+ document.querySelectorAll('mjx-container').forEach(node => {
19
+ let target = node.parentNode;
20
+ if (target.nodeName.toLowerCase() === 'li') {
21
+ target.parentNode.classList.add('has-jax');
22
+ }
23
+ });
24
+ }, '', false]
25
+ }
35
26
  }
36
- }
37
- };
27
+ };
28
+ } else {
29
+ MathJax.startup.document.state(0);
30
+ MathJax.texReset();
31
+ MathJax.typeset();
32
+ MathJax.typesetPromise();
33
+ }
38
34
  </script>
39
35
  `)
40
36
 
@@ -5,7 +5,6 @@
5
5
  <%- js_ex(theme.static_prefix.internal_js, 'plugins.js') %>
6
6
 
7
7
  <%- partial('_partials/plugins/typed.ejs') %>
8
- <%- partial('_partials/plugins/analytics.ejs') %>
9
8
 
10
9
  <% if (theme.lazyload.enable){ %>
11
10
  <% if (theme.lazyload.onlypost) { %>
package/layout/about.ejs CHANGED
@@ -50,4 +50,4 @@ page.banner_mask_alpha = page.banner_mask_alpha || theme.about.banner_mask_alpha
50
50
  <% } %>
51
51
  </article>
52
52
 
53
- <% import_css(theme.static_prefix.hint, 'hint.min.css') %>
53
+ <%- partial('_partials/markdown-plugins') %>
package/layout/links.ejs CHANGED
@@ -5,6 +5,7 @@ page.subtitle = theme.links.subtitle || __('links.subtitle')
5
5
  page.banner_img = theme.links.banner_img
6
6
  page.banner_img_height = theme.links.banner_img_height
7
7
  page.banner_mask_alpha = theme.links.banner_mask_alpha
8
+ page.comment = theme.links.comments.type
8
9
  %>
9
10
 
10
11
  <div class="row links">
package/layout/page.ejs CHANGED
@@ -14,28 +14,5 @@ page.banner_mask_alpha = page.banner_mask_alpha || theme.page.banner_mask_alpha
14
14
  </article>
15
15
 
16
16
  <% if (/<[^>]+? class="[^"]*?markdown-body[^"]*?"/gims.test(page.content)) { %>
17
- <% import_css(theme.static_prefix.github_markdown, 'github-markdown.min.css') %>
18
- <% import_css(theme.static_prefix.hint, 'hint.min.css') %>
19
-
20
- <% if (theme.code.highlight.enable) { %>
21
- <%- partial('_partials/plugins/highlight.ejs') %>
22
- <% } %>
23
- <% if ((theme.code.language.enable && theme.code.language.default) || theme.code.copy_btn) { %>
24
- <%- partial('_partials/plugins/code-widget.ejs') %>
25
- <% } %>
26
- <% if (theme.fun_features.anchorjs.enable && page.anchorjs !== false) { %>
27
- <%- partial('_partials/plugins/anchorjs.ejs') %>
28
- <% } %>
29
- <% if (theme.post.image_zoom.enable && page.image_zoom !== false) { %>
30
- <%- partial('_partials/plugins/fancybox.ejs') %>
31
- <% } %>
32
- <% if (theme.post.image_caption.enable) { %>
33
- <% import_script('<script>Fluid.plugins.imageCaption();</script>') %>
34
- <% } %>
35
- <% if (theme.post.math.enable && (!theme.post.math.specific || (theme.post.math.specific && page.math))) { %>
36
- <%- partial('_partials/plugins/math.ejs') %>
37
- <% } %>
38
- <% if (theme.post.mermaid.enable && (!theme.post.mermaid.specific || (theme.post.mermaid.specific && page.mermaid))) { %>
39
- <%- partial('_partials/plugins/mermaid.ejs') %>
40
- <% } %>
17
+ <%- partial('_partials/markdown-plugins') %>
41
18
  <% } %>
package/layout/post.ejs CHANGED
@@ -35,18 +35,25 @@ page.banner_mask_alpha = page.banner_mask_alpha || theme.post.banner_mask_alpha
35
35
  <% } %>
36
36
  </p>
37
37
  <% } %>
38
- <div class="markdown-body">
38
+ <% if (page.encrypt === true) { %>
39
39
  <%- inject_point('postMarkdownBegin') %>
40
40
  <%- page.content %>
41
+ <%- partial('_partials/plugins/encrypt') %>
41
42
  <%- inject_point('postMarkdownEnd') %>
42
- </div>
43
+ <% } else { %>
44
+ <div class="markdown-body">
45
+ <%- inject_point('postMarkdownBegin') %>
46
+ <%- page.content %>
47
+ <%- inject_point('postMarkdownEnd') %>
48
+ </div>
49
+ <% } %>
43
50
  <hr/>
44
51
  <div>
45
52
  <%- inject_point('postMetaBottom') %>
46
53
 
47
54
  <%- inject_point('postCopyright') %>
48
55
 
49
- <% if(theme.post.prev_next.enable && !page.hide) { %>
56
+ <% if (theme.post.prev_next.enable && !page.hide) { %>
50
57
  <div class="post-prevnext my-3">
51
58
  <article class="post-prev col-6">
52
59
  <% const prev = prev_post(page) %>
@@ -84,30 +91,7 @@ page.banner_mask_alpha = page.banner_mask_alpha || theme.post.banner_mask_alpha
84
91
  </div>
85
92
  </div>
86
93
 
87
- <% import_css(theme.static_prefix.github_markdown, 'github-markdown.min.css') %>
88
- <% import_css(theme.static_prefix.hint, 'hint.min.css') %>
89
-
90
- <% if (theme.code.highlight.enable) { %>
91
- <%- partial('_partials/plugins/highlight.ejs') %>
92
- <% } %>
93
- <% if ((theme.code.language.enable && theme.code.language.default) || theme.code.copy_btn) { %>
94
- <%- partial('_partials/plugins/code-widget.ejs') %>
95
- <% } %>
96
- <% if (theme.fun_features.anchorjs.enable && page.anchorjs !== false) { %>
97
- <%- partial('_partials/plugins/anchorjs.ejs') %>
98
- <% } %>
99
- <% if (theme.post.image_zoom.enable && page.image_zoom !== false) { %>
100
- <%- partial('_partials/plugins/fancybox.ejs') %>
101
- <% } %>
102
- <% if (theme.post.image_caption.enable) { %>
103
- <% import_script('<script>Fluid.plugins.imageCaption();</script>') %>
104
- <% } %>
105
- <% if (theme.post.math.enable && (!theme.post.math.specific || (theme.post.math.specific && page.math))) { %>
106
- <%- partial('_partials/plugins/math.ejs') %>
107
- <% } %>
108
- <% if (theme.post.mermaid.enable && (!theme.post.mermaid.specific || (theme.post.mermaid.specific && page.mermaid))) { %>
109
- <%- partial('_partials/plugins/mermaid.ejs') %>
110
- <% } %>
94
+ <%- partial('_partials/markdown-plugins') %>
111
95
 
112
96
  <% if(theme.post.custom && theme.post.custom.enable && theme.post.custom.content && page.custom !== false) { %>
113
97
  <!-- Custom -->
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hexo-theme-fluid",
3
- "version": "1.9.1",
3
+ "version": "1.9.2",
4
4
  "description": "An elegant Material-Design theme for Hexo.",
5
5
  "main": "package.json",
6
6
  "files": [
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
2
 
3
+ const { stripHTML } = require('hexo-util');
4
+
3
5
  // Register footnotes filter
4
6
  module.exports = (hexo) => {
5
7
  const config = hexo.theme.config;
@@ -29,7 +31,7 @@ module.exports = (hexo) => {
29
31
  text = text.replace(reInlineFootnote, function(match, index, content) {
30
32
  footnotes.push({
31
33
  index : index,
32
- content: content
34
+ content: content ? content.trim() : ''
33
35
  });
34
36
  // remove content of inline footnote
35
37
  return '[^' + index + ']';
@@ -39,7 +41,7 @@ module.exports = (hexo) => {
39
41
  text = text.replace(reFootnoteContent, function(match, index, content) {
40
42
  footnotes.push({
41
43
  index : index,
42
- content: content
44
+ content: content ? content.trim() : ''
43
45
  });
44
46
  // remove footnote content
45
47
  return '';
@@ -63,13 +65,11 @@ module.exports = (hexo) => {
63
65
  if (!indexMap[index]) {
64
66
  return match;
65
67
  }
66
- let tooltip = indexMap[index].content;
67
- tooltip = hexo.render.renderSync({ text: tooltip, engine: 'markdown' });
68
- tooltip = tooltip.replace(/(<.+?>)/g, '');
68
+ const tooltip = indexMap[index].content;
69
69
  return '<sup id="fnref:' + index + '" class="footnote-ref">'
70
70
  + '<a href="#fn:' + index + '" rel="footnote">'
71
71
  + '<span class="hint--top hint--rounded" aria-label="'
72
- + tooltip
72
+ + stripHTML(tooltip)
73
73
  + '">[' + index + ']</span></a></sup>';
74
74
  });
75
75
 
@@ -79,12 +79,12 @@ module.exports = (hexo) => {
79
79
  });
80
80
 
81
81
  // render footnotes (HTML)
82
- footnotes.forEach(function(footNote) {
83
- html += '<li><span id="fn:' + footNote.index + '" class="footnote-text">';
82
+ footnotes.forEach(function(item) {
83
+ html += '<li><span id="fn:' + item.index + '" class="footnote-text">';
84
84
  html += '<span>';
85
- const fn = hexo.render.renderSync({ text: footNote.content.trim(), engine: 'markdown' });
85
+ const fn = hexo.render.renderSync({ text: item.content, engine: 'markdown' });
86
86
  html += fn.replace(/(<p>)|(<\/p>)/g, '');
87
- html += '<a href="#fnref:' + footNote.index + '" rev="footnote" class="footnote-backref"> ↩</a></span></span></li>';
87
+ html += '<a href="#fnref:' + item.index + '" rev="footnote" class="footnote-backref"> ↩</a></span></span></li>';
88
88
  });
89
89
 
90
90
  // add footnotes at the end of the content
@@ -1,15 +1,12 @@
1
1
  'use strict';
2
2
 
3
3
  const fs = require('fs');
4
+ const css = require('css');
4
5
  const objUtil = require('../../utils/object');
5
6
  const resolveModule = require('../../utils/resolve');
6
7
 
7
8
  module.exports = (hexo) => {
8
9
 
9
- function parseStyleValue(line, attr) {
10
- return line.split(attr)[1].replace(';', '').trim();
11
- }
12
-
13
10
  function resolveHighlight(name) {
14
11
  if (!name) {
15
12
  name = 'github-gist';
@@ -21,23 +18,22 @@ module.exports = (hexo) => {
21
18
  }
22
19
  let backgroundColor;
23
20
  if (fs.existsSync(file)) {
24
- const css = fs.readFileSync(file).toString();
25
- let rule = '';
26
- css.replace(/\.hljs(\s+|,[^{]+){(.*?)}/sg, (match, $1, content) => {
27
- rule += content;
28
- return match;
29
- });
30
- rule.split('\n').forEach(line => {
31
- if (line.includes('background:')) {
32
- backgroundColor = parseStyleValue(line, 'background:');
33
- } else if (line.includes('background-color:')) {
34
- backgroundColor = parseStyleValue(line, 'background-color:');
35
- }
36
- });
21
+ const content = fs.readFileSync(file, 'utf8');
22
+ css.parse(content).stylesheet.rules
23
+ .filter(rule => rule.type === 'rule' && rule.selectors.some(selector => selector.endsWith('.hljs')))
24
+ .flatMap(rule => rule.declarations)
25
+ .forEach(declaration => {
26
+ if (declaration.property === 'background' || declaration.property === 'background-color') {
27
+ backgroundColor = declaration.value;
28
+ }
29
+ });
37
30
  } else {
38
31
  hexo.log.error(`[Fluid] highlightjs style '${name}' not found`);
39
32
  return {};
40
33
  }
34
+ if (backgroundColor === 'white' || backgroundColor === '#ffffff') {
35
+ backgroundColor = '#fff';
36
+ }
41
37
  return { file, backgroundColor };
42
38
  }
43
39
 
@@ -6,10 +6,11 @@
6
6
  margin-bottom 2rem
7
7
  color var(--post-text-color)
8
8
 
9
- h1, h2
9
+ & > h1, h2
10
10
  border-bottom-color var(--line-color)
11
11
 
12
- h1, h2, h3, h4, h5, h6
12
+ & > h1, h2, h3, h4, h5, h6
13
+ anchor-offset()
13
14
  color var(--post-heading-color)
14
15
  transition color .2s ease-in-out, border-bottom-color 0.2s ease-in-out
15
16
  font-weight bold
@@ -16,10 +16,6 @@
16
16
  .anchorjs-link-left
17
17
  opacity 0 !important
18
18
 
19
- .post-content
20
- h1, h2, h3, h4, h5, h6
21
- anchor-offset()
22
-
23
19
  .page-content, .post-content
24
20
  strong
25
21
  font-weight bold
@@ -62,8 +62,8 @@ $scrollbar-hover-color = theme-config("color.scrollbar_hover_color", "#a6a6a6")
62
62
  $scrollbar-hover-color-dark = theme-config("color.scrollbar_hover_color_dark", "#9da8b3")
63
63
 
64
64
  // code
65
- $highlight-bg-color = hexo-config("code.highlight.highlightjs.light.backgroundColor") && hexo-config("code.highlight.highlightjs.light.backgroundColor") != "white" ? unquote(hexo-config("code.highlight.highlightjs.light.backgroundColor")):#f6f8fa
66
- $highlight-bg-color-dark = hexo-config("code.highlight.highlightjs.dark.backgroundColor") && hexo-config("code.highlight.highlightjs.dark.backgroundColor") != "white" ? unquote(hexo-config("code.highlight.highlightjs.dark.backgroundColor")):#2d333b
65
+ $highlight-bg-color = hexo-config("code.highlight.highlightjs.light.backgroundColor") && hexo-config("code.highlight.highlightjs.light.backgroundColor") != "#fff" ? unquote(hexo-config("code.highlight.highlightjs.light.backgroundColor")):#f6f8fa
66
+ $highlight-bg-color-dark = hexo-config("code.highlight.highlightjs.dark.backgroundColor") && hexo-config("code.highlight.highlightjs.dark.backgroundColor") != "#fff" ? unquote(hexo-config("code.highlight.highlightjs.dark.backgroundColor")):#2d333b
67
67
  $inlinecode-bg-color = rgba(175, 184, 193, .2)
68
68
  $inlinecode-bg-color-dark = rgba(99, 110, 123, .4)
69
69
 
package/source/js/boot.js CHANGED
@@ -11,6 +11,44 @@ Fluid.boot.registerEvents = function() {
11
11
  Fluid.events.registerImageLoadedEvent();
12
12
  };
13
13
 
14
+ Fluid.boot.refreshPlugins = function() {
15
+ Fluid.plugins.fancyBox();
16
+ Fluid.plugins.codeWidget();
17
+
18
+ if ('tocbot' in window) {
19
+ tocbot.refresh();
20
+ var toc = jQuery('#toc');
21
+ if (toc.length === 0 || !tocbot) { return; }
22
+ if (toc.find('.toc-list-item').length > 0) {
23
+ toc.css('visibility', 'visible');
24
+ }
25
+ }
26
+
27
+ if ('anchors' in window) {
28
+ anchors.removeAll();
29
+ var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
30
+ var res = [];
31
+ for (var item of el) {
32
+ res.push('.markdown-body > ' + item.trim());
33
+ }
34
+ if (CONFIG.anchorjs.placement === 'left') {
35
+ anchors.options.class = 'anchorjs-link-left';
36
+ }
37
+ anchors.add(res.join(', '));
38
+ }
39
+
40
+ if ('MathJax' in window && MathJax.startup.document && typeof MathJax.startup.document.state === 'function') {
41
+ MathJax.startup.document.state(0);
42
+ MathJax.texReset();
43
+ MathJax.typeset();
44
+ MathJax.typesetPromise();
45
+ }
46
+
47
+ if ('mermaid' in window) {
48
+ mermaid.init();
49
+ }
50
+ }
51
+
14
52
  document.addEventListener('DOMContentLoaded', function() {
15
53
  Fluid.boot.registerEvents();
16
54
  });
@@ -1,4 +1,5 @@
1
1
  /* global CONFIG */
2
+ // eslint-disable-next-line no-console
2
3
 
3
4
  (function(window, document) {
4
5
  // 查询存储的记录
@@ -22,14 +23,12 @@
22
23
  }
23
24
  resolve(record);
24
25
  }).catch(error => {
25
- // eslint-disable-next-line no-console
26
- console.error('Failed to create', error);
26
+ console.error('Failed to create: ', error);
27
27
  reject(error);
28
28
  });
29
29
  }
30
30
  }).catch((error) => {
31
- // eslint-disable-next-line no-console
32
- console.error('LeanCloud Counter Error:', error);
31
+ console.error('LeanCloud Counter Error: ', error);
33
32
  reject(error);
34
33
  });
35
34
  });
@@ -47,8 +46,7 @@
47
46
  }
48
47
  resolve(res);
49
48
  }).catch((error) => {
50
- // eslint-disable-next-line no-console
51
- console.error('Failed to save visitor count', error);
49
+ console.error('Failed to save visitor count: ', error);
52
50
  reject(error);
53
51
  });
54
52
  });
@@ -95,5 +95,70 @@ Fluid.plugins = {
95
95
  }
96
96
  }
97
97
  });
98
+ },
99
+
100
+ codeWidget() {
101
+ var enableLang = CONFIG.code_language.enable && CONFIG.code_language.default;
102
+ var enableCopy = CONFIG.copy_btn && 'ClipboardJS' in window;
103
+ if (!enableLang && !enableCopy) {
104
+ return;
105
+ }
106
+
107
+ function getBgClass(ele) {
108
+ return Fluid.utils.getBackgroundLightness(ele) >= 0 ? 'code-widget-light' : 'code-widget-dark';
109
+ }
110
+
111
+ var copyTmpl = '';
112
+ copyTmpl += '<div class="code-widget">';
113
+ copyTmpl += 'LANG';
114
+ copyTmpl += '</div>';
115
+ jQuery('.markdown-body pre').each(function() {
116
+ var $pre = jQuery(this);
117
+ if ($pre.find('code.mermaid').length > 0) {
118
+ return;
119
+ }
120
+ if ($pre.find('span.line').length > 0) {
121
+ return;
122
+ }
123
+
124
+ var lang = '';
125
+
126
+ if (enableLang) {
127
+ lang = CONFIG.code_language.default;
128
+ if ($pre[0].children.length > 0 && $pre[0].children[0].classList.length >= 2 && $pre.children().hasClass('hljs')) {
129
+ lang = $pre[0].children[0].classList[1];
130
+ } else if ($pre[0].getAttribute('data-language')) {
131
+ lang = $pre[0].getAttribute('data-language');
132
+ } else if ($pre.parent().hasClass('sourceCode') && $pre[0].children.length > 0 && $pre[0].children[0].classList.length >= 2) {
133
+ lang = $pre[0].children[0].classList[1];
134
+ $pre.parent().addClass('code-wrapper');
135
+ } else if ($pre.parent().hasClass('markdown-body') && $pre[0].classList.length === 0) {
136
+ $pre.wrap('<div class="code-wrapper"></div>');
137
+ }
138
+ lang = lang.toUpperCase().replace('NONE', CONFIG.code_language.default);
139
+ }
140
+ $pre.append(copyTmpl.replace('LANG', lang).replace('code-widget">',
141
+ getBgClass($pre[0]) + (enableCopy ? ' code-widget copy-btn" data-clipboard-snippet><i class="iconfont icon-copy"></i>' : ' code-widget">')));
142
+
143
+ if (enableCopy) {
144
+ var clipboard = new ClipboardJS('.copy-btn', {
145
+ target: function(trigger) {
146
+ var nodes = trigger.parentNode.childNodes;
147
+ for (var i = 0; i < nodes.length; i++) {
148
+ if (nodes[i].tagName === 'CODE') {
149
+ return nodes[i];
150
+ }
151
+ }
152
+ }
153
+ });
154
+ clipboard.on('success', function(e) {
155
+ e.clearSelection();
156
+ e.trigger.innerHTML = e.trigger.innerHTML.replace('icon-copy', 'icon-success');
157
+ setTimeout(function() {
158
+ e.trigger.innerHTML = e.trigger.innerHTML.replace('icon-success', 'icon-copy');
159
+ }, 2000);
160
+ });
161
+ }
162
+ });
98
163
  }
99
164
  };
@@ -174,7 +174,19 @@ Fluid.utils = {
174
174
  }
175
175
  var colorCast = (0.213 * rgbArr[0]) + (0.715 * rgbArr[1]) + (0.072 * rgbArr[2]);
176
176
  return colorCast === 0 || colorCast > 255 / 2 ? 1 : -1;
177
- }
177
+ },
178
+
179
+ retry(handler, interval, times) {
180
+ if (times <= 0) {
181
+ return;
182
+ }
183
+ var next = function() {
184
+ if (--times >= 0 && !handler()) {
185
+ setTimeout(next, interval);
186
+ }
187
+ };
188
+ setTimeout(next, interval);
189
+ },
178
190
 
179
191
  };
180
192