Skip to content

Commit

Permalink
Add new tag caniuse (#984)
Browse files Browse the repository at this point in the history
  • Loading branch information
1v9 authored Jul 20, 2019
1 parent d0e5216 commit bc05293
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,11 @@ mermaid:
cdn: //cdn.jsdelivr.net/npm/mermaid@8/dist/mermaid.min.js
#cdn: //cdnjs.cloudflare.com/ajax/libs/mermaid/8.0.0/mermaid.min.js

# Caniuse tag
caniuse:
enable: false
cdn: //cdn.jsdelivr.net/gh/ireade/caniuse-embed@1/caniuse-embed.min.js


# ---------------------------------------------------------------
# Animation Settings
Expand Down
1 change: 1 addition & 0 deletions layout/_layout.swig
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
{% include '_third-party/math/index.swig' %}
{% include '_third-party/pdf.swig' %}
{% include '_third-party/mermaid.swig' %}
{% include '_third-party/caniuse.swig' %}
{% include '_third-party/baidu-push.swig' %}
{% include '_third-party/schedule.swig' %}
{% include '_third-party/needsharebutton.swig' %}
Expand Down
3 changes: 3 additions & 0 deletions layout/_third-party/caniuse.swig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% if theme.caniuse.enable %}
<script async src="{{ theme.caniuse.cdn }}"></script>
{% endif %}
22 changes: 22 additions & 0 deletions scripts/tags/caniuse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* caniuse.js | https://theme-next.org/docs/tag-plugins/caniuse
*/

/* global hexo */

'use strict';

const caniUse = (args) => {
args = args.join('').split('@');
let feature = args[0];
let periods = args[1] || 'current';

if (!feature) {
hexo.log.w('Caniuse feature can NOT be empty');
return '';
}

return `<p class="ciu_embed" data-feature="${feature}" data-periods="${periods}"><a href="http://caniuse.com/#feat=${feature}">Can I Use ${feature}?</a>Data on support for the ${feature} feature across the major browsers from caniuse.com.</p>`;
};

hexo.extend.tag.register('caniuse', caniUse, {async: true});

0 comments on commit bc05293

Please sign in to comment.