diff --git a/.eslintrc b/.eslintrc index 436591a298d..7c423721e7b 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,11 +1,11 @@ { "env": { "browser": true, - "jquery": true - + "jquery": true, + "node": true }, "rules": { - "no-console": "off", + "no-console": "error", "semi": ["error", "always"], "quotes": ["error", "single"], "comma-dangle": ["error", "never"], diff --git a/_includes/components/comment-disqus.html b/_includes/components/comment-disqus.html new file mode 100644 index 00000000000..92ad2c6d44b --- /dev/null +++ b/_includes/components/comment-disqus.html @@ -0,0 +1,19 @@ +{%- if site.disqus.shortname and page.key -%} +
+ + +{%- endif -%} \ No newline at end of file diff --git a/_includes/utils/comment-gitalk.html b/_includes/components/comment-gitalk.html similarity index 100% rename from _includes/utils/comment-gitalk.html rename to _includes/components/comment-gitalk.html diff --git a/_includes/scripts/lib/affix.js b/_includes/scripts/components/affix.js similarity index 100% rename from _includes/scripts/lib/affix.js rename to _includes/scripts/components/affix.js diff --git a/_includes/scripts/components/chart.js b/_includes/scripts/components/chart.js new file mode 100644 index 00000000000..8bbc000cf88 --- /dev/null +++ b/_includes/scripts/components/chart.js @@ -0,0 +1,18 @@ +/* global Chart */ +(function () { + var SOURCES = window.TEXT_VARIABLES.sources; + var PAGE = window.TEXT_VARIABLES.page; + if (PAGE.chart) { + window.Lazyload.js([SOURCES.jquery, SOURCES.chart], function() { + var $canvas = null, $this = null, _ctx = null, _text = ''; + $('.language-chart').each(function(){ + $this = $(this); + $canvas = $(''); + _text = $this.text(); + $this.text('').append($canvas); + _ctx = $canvas.get(0).getContext('2d'); + (_ctx && _text) && (new Chart(_ctx, JSON.parse(_text)) && $this.attr('data-processed', true)); + }); + }); + } +})(); \ No newline at end of file diff --git a/_includes/scripts/components/google-analytics.js b/_includes/scripts/components/google-analytics.js new file mode 100644 index 00000000000..4d9056f14be --- /dev/null +++ b/_includes/scripts/components/google-analytics.js @@ -0,0 +1,15 @@ +/* global ga */ +(function() { + var ENVIRONMENT = window.TEXT_VARIABLES.jekyll.environment; + var GA_TRACKING_ID = window.TEXT_VARIABLES.site.ga_tracking_id; + if(GA_TRACKING_ID && ENVIRONMENT !== 'development') { + /* eslint-disable */ + (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ + (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), + m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) + })(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); + /* eslint-enable */ + ga('create', GA_TRACKING_ID, 'auto'); + ga('send', 'pageview'); + } +})(); \ No newline at end of file diff --git a/_includes/scripts/components/mathjax.js b/_includes/scripts/components/mathjax.js new file mode 100644 index 00000000000..5dbef124469 --- /dev/null +++ b/_includes/scripts/components/mathjax.js @@ -0,0 +1,14 @@ +(function () { + var SOURCES = window.TEXT_VARIABLES.sources; + var PAGE = window.TEXT_VARIABLES.page; + if (PAGE.mathjax) { + var _config = { tex2jax: { + inlineMath: [['$','$'], ['\\(','\\)']] + }}; + if (PAGE.mathjax_autoNumber == true) { + _config.TeX = { equationNumbers: { autoNumber: 'all' } }; + } + window.MathJax = _config; + window.Lazyload.js(SOURCES.mathjax); + } +})(); \ No newline at end of file diff --git a/_includes/scripts/components/mermaid.js b/_includes/scripts/components/mermaid.js new file mode 100644 index 00000000000..3733d5ebc11 --- /dev/null +++ b/_includes/scripts/components/mermaid.js @@ -0,0 +1,11 @@ +/* global mermaid */ +(function () { + var SOURCES = window.TEXT_VARIABLES.sources; + var PAGE = window.TEXT_VARIABLES.page; + if (PAGE.mermaid) { + window.Lazyload.js(SOURCES.mermaid, function() { + mermaid.init(undefined, '.language-mermaid'); + mermaid.initialize({ startOnLoad: true }); + }); + } +})(); \ No newline at end of file diff --git a/_includes/scripts/lib/pageview.js b/_includes/scripts/components/pageview.js similarity index 100% rename from _includes/scripts/lib/pageview.js rename to _includes/scripts/components/pageview.js diff --git a/_includes/scripts/lib/toc.js b/_includes/scripts/components/toc.js similarity index 98% rename from _includes/scripts/lib/toc.js rename to _includes/scripts/components/toc.js index 846adcff5af..e6cf054cb67 100644 --- a/_includes/scripts/lib/toc.js +++ b/_includes/scripts/components/toc.js @@ -63,7 +63,6 @@ }) ); $window.on('resize', window.throttle(function() { - console.log('toc', disabled); if (!disabled) { rendered || render(); calc(); diff --git a/_includes/scripts/page.js b/_includes/scripts/page-post.js similarity index 100% rename from _includes/scripts/page.js rename to _includes/scripts/page-post.js diff --git a/_includes/scripts/post.js b/_includes/scripts/post.js index d8b1d2943ea..c6f9d7754c8 100644 --- a/_includes/scripts/post.js +++ b/_includes/scripts/post.js @@ -21,7 +21,6 @@ $window.on('resize', window.throttle(function() { tocDisabled = disabled(); - console.log(tocDisabled); toc && toc.setOptions({ disabled: tocDisabled }); @@ -49,17 +48,19 @@ LEANCLOUD.app_id && LEANCLOUD.app_key && LEANCLOUD.app_class && - ENVIRONMENT !== 'development') { + '{{ page.key }}' && + ENVIRONMENT !== 'development' && + ENVIRONMENT !== 'beta' + ) { window.Lazyload.js([SOURCES.jquery, SOURCES.leancloud_js_sdk], function() { - var AV = window.AV; - + /* global AV */ var pageview = window.pageview(AV, { appId: LEANCLOUD.app_id, appKey: LEANCLOUD.app_key, appClass: LEANCLOUD.app_class }); var key = '{{ page.key }}'; - var title = window.decodeUrl('{{ page.title | url_encode }}'); + var title = '{{ page.title }}'; pageview.increase(key, title, function(view) { $('#post-key-{{ page.key }}').text(view); diff --git a/_includes/scripts/variables.html b/_includes/scripts/variables.html index fc3f5c1122f..40bdc0dd820 100644 --- a/_includes/scripts/variables.html +++ b/_includes/scripts/variables.html @@ -3,7 +3,7 @@ \ No newline at end of file diff --git a/_includes/snippets/to-boolean.html b/_includes/snippets/to-boolean.html new file mode 100644 index 00000000000..735d75486aa --- /dev/null +++ b/_includes/snippets/to-boolean.html @@ -0,0 +1,7 @@ +{%- if __value == false -%} +{%- assign __value = false -%} +{%- elsif __value == true -%} +{%- assign __value = true -%} +{%- else -%} +{%- assign __value = '' -%} +{%- endif -%} \ No newline at end of file diff --git a/_includes/utils/chart.html b/_includes/utils/chart.html deleted file mode 100644 index 93a63d1bc36..00000000000 --- a/_includes/utils/chart.html +++ /dev/null @@ -1,17 +0,0 @@ -{%- if site.chart == true or page.chart == true -%} -{%- include snippets/get-sources.html -%} -{%- assign _sources = __return -%} - -{%- endif -%} \ No newline at end of file diff --git a/_includes/utils/comment-disqus.html b/_includes/utils/comment-disqus.html deleted file mode 100644 index ab5cf752df2..00000000000 --- a/_includes/utils/comment-disqus.html +++ /dev/null @@ -1,19 +0,0 @@ -{%- if site.disqus.shortname and page.key -%} - - - -{%- endif -%} \ No newline at end of file diff --git a/_includes/utils/google-analytics.html b/_includes/utils/google-analytics.html deleted file mode 100644 index 27416350467..00000000000 --- a/_includes/utils/google-analytics.html +++ /dev/null @@ -1,11 +0,0 @@ -{%- if site.ga_tracking_id -%} - -{%- endif -%} diff --git a/_includes/utils/mathjax.html b/_includes/utils/mathjax.html deleted file mode 100644 index b35f21366c3..00000000000 --- a/_includes/utils/mathjax.html +++ /dev/null @@ -1,14 +0,0 @@ -{%- if site.mathjax == true or page.mathjax == true -%} -{%- include snippets/get-sources.html -%} -{%- assign _sources = __return -%} - - -{%- endif -%} \ No newline at end of file diff --git a/_includes/utils/mermaid.html b/_includes/utils/mermaid.html deleted file mode 100644 index 2c652729e42..00000000000 --- a/_includes/utils/mermaid.html +++ /dev/null @@ -1,10 +0,0 @@ -{%- if site.mermaid == true or page.mermaid == true -%} -{%- include snippets/get-sources.html -%} -{%- assign _sources = __return -%} - -{%- endif -%} \ No newline at end of file diff --git a/_layouts/base.html b/_layouts/base.html index 0d1663910a0..7f109a043ab 100644 --- a/_layouts/base.html +++ b/_layouts/base.html @@ -25,19 +25,19 @@ {%- include scripts/variables.html -%} {%- if page.layout == "home" -%} {%- elsif page.layout == "page" -%} {%- elsif page.layout == "post" -%} {%- elsif page.layout == "all" -%} @@ -45,11 +45,11 @@ {%- include scripts/all.js -%} {%- endif -%} - {%- include utils/mathjax.html -%} - {%- include utils/mermaid.html -%} - {%- include utils/chart.html -%} - {%- if jekyll.environment != "development" -%} - {%- include utils/google-analytics.html -%} - {%- endif -%} +