Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new tag caniuse #984

Merged
merged 1 commit into from
Jul 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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});