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

Add wavedrom support. #655

merged 8 commits into from
May 23, 2023

Conversation

r12f
Copy link
Contributor

@r12f r12f commented May 19, 2023

PR Checklist

PR Type

  • Bugfix.
  • Feature.
  • Improvement.
  • Code style update (formatting, linting).
  • Refactoring (no functional changes).
  • Documentation.
  • Translation.
  • Other... Please describe:

What is the current behavior?

Currently next theme doesn't have wavedrom tag support, and we will have to use markdown image tag to send to wavedrom rendering server to generate the graph. However, this approach can be slow. And if the code is long, the request will fail. Hence, it is better to add wavedrom code block rendering support within the theme.

Issue resolved: Rendering wavedrom code block.

What is the new behavior?

After the change, we can directly add wavedrom code and render it as graph.

How to use?

In NexT _config.yml:

# Wavedrom tag
wavedrom:
  enable: true

Then write code like below:

{% wavedrom %}
{ signal : [
  { name: "clk",  wave: "p......" },
  { name: "bus",  wave: "x.34.5x",   data: "head body tail" },
  { name: "wire", wave: "0.1..0." },
]}
{% endwavedrom %}

@welcome
Copy link

welcome bot commented May 19, 2023

Thanks so much for opening your first PR here!

@CLAassistant
Copy link

CLAassistant commented May 19, 2023

CLA assistant check
All committers have signed the CLA.

@r12f
Copy link
Contributor Author

r12f commented May 19, 2023

More things for validation:

JS files are downloaded from cdnjs:
image

Final code that injected for rendering:

  <script class="next-config" data-name="wavedrom" type="application/json">{"enable":true,"js":{"url":"https://cdnjs.cloudflare.com/ajax/libs/wavedrom/3.2.0/wavedrom.min.js","integrity":"sha512-/ZL0uQxVV1wYyWlpO4klZ1a39eaBz4zESSamuBMaMsZ6le3YejJ07hmLlHoCTXrKz5eYtEuO5K1BcTo+lQpQJA=="}}</script>
  <script class="next-config" data-name="wavedrom_skin" type="application/json">{"enable":true,"js":{"url":"https://cdnjs.cloudflare.com/ajax/libs/wavedrom/3.2.0/skins/default.min.js","integrity":"sha512-SDH/iWIRSg0ujndO7Np7wyJF/zs8JHp4tHKU4VJuraJ3ASd2sVorT/3uA2xnHthywvei4/fJYz8Lsbr1SChYBQ=="}}</script>
  <script src="/js/third-party/tags/wavedrom.js"></script>

@github-actions github-actions bot added the CSS label May 19, 2023
@r12f
Copy link
Contributor Author

r12f commented May 21, 2023

Lint should be fixed now. But need approval for running the workflow again.

image

@coveralls
Copy link

coveralls commented May 21, 2023

Pull Request Test Coverage Report for Build 5054503871

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 97.614%

Totals Coverage Status
Change from base Build 4899068859: 0.0%
Covered Lines: 394
Relevant Lines: 399

💛 - Coveralls

_vendors.yml Outdated
@@ -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.

_vendors.yml Outdated
name: 'wavedrom'
version: 3.2.0
file: skins/default.min.js
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

_vendors.yml Outdated
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.

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/

@stevenjoezhang
Copy link
Member

Thanks for your contribution 🎉

@stevenjoezhang stevenjoezhang merged commit 01e518a into next-theme:master May 23, 2023
@welcome
Copy link

welcome bot commented May 23, 2023

Congrats on merging your first pull request here! 🎉 How awesome!

@stevenjoezhang stevenjoezhang linked an issue May 23, 2023 that may be closed by this pull request
@r12f
Copy link
Contributor Author

r12f commented May 23, 2023

Woot! Thank you so much for helping me and review!!! 🎉🎉🎉

@r12f r12f deleted the dev branch May 23, 2023 20:50
gtn1024 pushed a commit to gtn1024/hexo-theme-next that referenced this pull request Jul 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hope to integrate WaveDrom like mermaid
4 participants