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 -%} + diff --git a/_layouts/page.html b/_layouts/page.html index 3c8050121a6..62019e9e198 100644 --- a/_layouts/page.html +++ b/_layouts/page.html @@ -7,8 +7,8 @@

{{ __return }}

{{ content }}
{%- if jekyll.environment != "development" and page.comment != false -%} -
{%- include utils/comment-disqus.html -%}
-
{%- include utils/comment-gitalk.html -%}
+
{%- include components/comment-disqus.html -%}
+
{%- include components/comment-gitalk.html -%}
{%- endif -%} diff --git a/_layouts/post.html b/_layouts/post.html index 00061b17540..a0676be3c54 100644 --- a/_layouts/post.html +++ b/_layouts/post.html @@ -52,8 +52,8 @@

{{ __return }}

{%- endif -%} {%- if jekyll.environment != "development" and page.comment != false -%} -
{%- include utils/comment-disqus.html -%}
-
{%- include utils/comment-gitalk.html -%}
+
{%- include components/comment-disqus.html -%}
+
{%- include components/comment-gitalk.html -%}
{%- endif -%} diff --git a/gulpfile.js b/gulpfile.js index 4373502830e..cd907e36b5c 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -8,64 +8,64 @@ var iconDestPath = './assets/images/logo'; var faviconDestPath = './'; function coverSvg(width, height) { - height || (height = width); - return gulp.src('./assets/images/logo/logo.svg') - .pipe(svg2png({ width: width, height: height })) - .pipe(rename({ - basename: iconBasename, - suffix: '-' + width + 'x' + height - })) - .pipe(gulp.dest(iconDestPath)); + height || (height = width); + return gulp.src('./assets/images/logo/logo.svg') + .pipe(svg2png({ width: width, height: height })) + .pipe(rename({ + basename: iconBasename, + suffix: '-' + width + 'x' + height + })) + .pipe(gulp.dest(iconDestPath)); } gulp.task('icon310', function() { - return coverSvg(310); + return coverSvg(310); }); gulp.task('icon310x150', function() { - return coverSvg(310, 150); + return coverSvg(310, 150); }); gulp.task('icon192', function() { - return coverSvg(192); + return coverSvg(192); }); gulp.task('icon180', function() { - return coverSvg(180); + return coverSvg(180); }); gulp.task('icon167', function() { - return coverSvg(167); + return coverSvg(167); }); gulp.task('icon152', function() { - return coverSvg(152); + return coverSvg(152); }); gulp.task('icon150', function() { - return coverSvg(150); + return coverSvg(150); }); gulp.task('icon128', function() { - return coverSvg(128); + return coverSvg(128); }); gulp.task('icon120', function() { - return coverSvg(120); + return coverSvg(120); }); gulp.task('icon70', function() { - return coverSvg(70); + return coverSvg(70); }); gulp.task('icon48', function() { - return coverSvg(48); + return coverSvg(48); }); gulp.task('icon16', function() { - return coverSvg(16); + return coverSvg(16); }); gulp.task('favicon', ['icon128', 'icon48', 'icon16'], function() { - return gulp.src([ - iconDestPath + '/icon-128x128.png', - iconDestPath + '/icon-48x48.png', - iconDestPath + '/icon-16x16.png']) - .pipe(ico({ path: 'favicon.ico'})) - .pipe(gulp.dest(faviconDestPath)); + return gulp.src([ + iconDestPath + '/icon-128x128.png', + iconDestPath + '/icon-48x48.png', + iconDestPath + '/icon-16x16.png']) + .pipe(ico({ path: 'favicon.ico'})) + .pipe(gulp.dest(faviconDestPath)); }); gulp.task('icons', [ - 'icon310', 'icon310x150', 'icon192', 'icon180', 'icon167', 'icon152', 'icon150', 'icon120', 'icon70' + 'icon310', 'icon310x150', 'icon192', 'icon180', 'icon167', 'icon152', 'icon150', 'icon120', 'icon70' ]); gulp.task('artwork', ['favicon', 'icons']); \ No newline at end of file diff --git a/package.json b/package.json index 7ab3f701e26..a0f6f485435 100644 --- a/package.json +++ b/package.json @@ -7,8 +7,9 @@ "serve": "bundle exec jekyll serve -H 0.0.0.0", "default": "bundle exec jekyll serve -H 0.0.0.0 -t", "dev": "bundle exec jekyll serve -H 0.0.0.0 -t --config ./_config.dev.yml", - "demo": "bundle exec jekyll serve -H 0.0.0.0 -t --config ./_config.demo.yml", - "production": "JEKYLL_ENV=production bundle exec jekyll serve -H 0.0.0.0 -t --config ./_config.demo.yml", + "demo-dev": "bundle exec jekyll serve -H 0.0.0.0 -t --config ./_config.demo.yml", + "demo-beta": "JEKYLL_ENV=beta bundle exec jekyll serve -H 0.0.0.0 -t --config ./_config.demo.yml", + "demo-production": "JEKYLL_ENV=production bundle exec jekyll serve -H 0.0.0.0 -t --config ./_config.demo.yml", "favicon": "gulp favicon", "icons": "gulp icons", "artwork": "gulp artwork",