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 wavedrom support. #655

Merged
merged 8 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
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'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove single quotes in this line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it. removed.

version: 3.2.0
file: wavedrom.min.js
integrity: sha512-/ZL0uQxVV1wYyWlpO4klZ1a39eaBz4zESSamuBMaMsZ6le3YejJ07hmLlHoCTXrKz5eYtEuO5K1BcTo+lQpQJA==
wavedrom_skin:
name: 'wavedrom'
version: 3.2.0
file: skins/default.min.js
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

skins/default.min.js does not exist in its npm version. You need to change it to skins/default.js and re-calculate its integrity value

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it. moved to default.js now.

integrity: sha512-SDH/iWIRSg0ujndO7Np7wyJF/zs8JHp4tHKU4VJuraJ3ASd2sVorT/3uA2xnHthywvei4/fJYz8Lsbr1SChYBQ==
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Integrity incorrect for jsdelivr

截屏2023-05-22 20 51 57

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed by moving to default.js.

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cdnjs still works:

image

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;
}
}
11 changes: 11 additions & 0 deletions source/js/third-party/tags/wavedrom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* 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).then(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Condition for CONFIG.wavedrom_skin.js is window.WaveSkin

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Didn't add it since it is in the then block. It is fixed now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

demo page is also updated now: https://r12f.com/posts/use-wavedrom-in-hexo/

WaveDrom.ProcessAll();
});
});
});