Skip to content

Commit

Permalink
Add wavedrom support (#655)
Browse files Browse the repository at this point in the history
  • Loading branch information
r12f authored May 23, 2023
1 parent 2d64661 commit 01e518a
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 0 deletions.
3 changes: 3 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,9 @@ mermaid:
light: default
dark: dark

# WaveDrom tag
wavedrom:
enable: false

# ---------------------------------------------------------------
# Third Party Plugins & Services Settings
Expand Down
10 changes: 10 additions & 0 deletions _vendors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,13 @@ creative_commons:
version: 2020.11.3
dir: assets/license_badges
alias: creativecommons-vocabulary
wavedrom:
name: wavedrom
version: 3.2.0
file: wavedrom.min.js
integrity: sha512-/ZL0uQxVV1wYyWlpO4klZ1a39eaBz4zESSamuBMaMsZ6le3YejJ07hmLlHoCTXrKz5eYtEuO5K1BcTo+lQpQJA==
wavedrom_skin:
name: wavedrom
version: 3.2.0
file: skins/default.js
integrity: sha512-GV5gOBpCHd3M5Af9Ooz+I9dQdwcDKPR2F8ulzCpoF4W6uwmtLTh/pT8Q1XupPmQJO+Kt88/DrIiK7PzR1YLvwQ==
1 change: 1 addition & 0 deletions layout/_third-party/index.njk
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

{%- include 'tags/pdf.njk' -%}
{%- include 'tags/mermaid.njk' -%}
{%- include 'tags/wavedrom.njk' -%}

{%- include 'fancybox.njk' -%}
{%- include 'pace.njk' -%}
Expand Down
9 changes: 9 additions & 0 deletions layout/_third-party/tags/wavedrom.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{%- if theme.wavedrom.enable %}
{{ next_data('wavedrom', theme.wavedrom, {
js: theme.vendors.wavedrom
}) }}
{{ next_data('wavedrom_skin', theme.wavedrom, {
js: theme.vendors.wavedrom_skin
}) }}
{{ next_js('third-party/tags/wavedrom.js') }}
{%- endif %}
4 changes: 4 additions & 0 deletions scripts/filters/minify.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ hexo.extend.filter.register('after_generate', () => {
hexo.route.remove('js/third-party/tags/pdf.js');
}

if (!theme.wavedrom.enable) {
hexo.route.remove('js/third-party/tags/wavedrom.js');
}

// Others
if (!theme.fancybox) {
hexo.route.remove('js/third-party/fancybox.js');
Expand Down
4 changes: 4 additions & 0 deletions scripts/tags/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ const mermaid = require('./mermaid');

hexo.extend.tag.register('mermaid', mermaid, true);

const wavedrom = require('./wavedrom');

hexo.extend.tag.register('wavedrom', wavedrom, true);

const postNote = require('./note')(hexo);

hexo.extend.tag.register('note', postNote, true);
Expand Down
11 changes: 11 additions & 0 deletions scripts/tags/wavedrom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* wavedrom.js | https://theme-next.js.org/docs/tag-plugins/wavedrom
*/

'use strict';

module.exports = function(args, content) {
return `<div class="wavedrom"><script type="WaveDrom">
${content}
</script></div>`;
};
1 change: 1 addition & 0 deletions source/css/_common/scaffolding/tags/index.styl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@import 'label';
@import 'link-grid';
@import 'mermaid';
@import 'wavedrom';
@import 'note';
@import 'pdf';
@import 'tabs';
6 changes: 6 additions & 0 deletions source/css/_common/scaffolding/tags/wavedrom.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
if (hexo-config('wavedrom.enable')) {
.wavedrom {
margin-bottom: 20px;
text-align: center;
}
}
13 changes: 13 additions & 0 deletions source/js/third-party/tags/wavedrom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* global NexT, CONFIG, WaveDrom */

document.addEventListener('page:loaded', () => {
NexT.utils.getScript(CONFIG.wavedrom.js, {
condition: window.WaveDrom
}).then(() => {
NexT.utils.getScript(CONFIG.wavedrom_skin.js, {
condition: window.WaveSkin
}).then(() => {
WaveDrom.ProcessAll();
});
});
});

0 comments on commit 01e518a

Please sign in to comment.