-
Notifications
You must be signed in to change notification settings - Fork 14.5k
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
adding mermaidjs shortcode with example #20434
adding mermaidjs shortcode with example #20434
Conversation
Deploy preview for kubernetes-io-master-staging ready! Built with commit bea8e2b https://deploy-preview-20434--kubernetes-io-master-staging.netlify.app |
Related: #20293 |
a8b89ce
to
a40e521
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
(I've limited experience with Hugo, and I do like the idea of Mermaid, but would like to help make docs available to readers who don't or can't enable JavaScript).
Is there a way to use CSS to hide the Mermaid source when JavaScript isn't enabled?
At the moment it renders roughly as
Produces:
sequenceDiagram Alice ->> Bob: Hello Bob, how are you? Bob-->>John: How about you John? Bob--x Alice: I am good thanks! Bob-x John: I am good thanks! Note right of John: Bob thinks a long
long time, so long
that the text does
not fit on a row. Bob-->Alice: Checking with John... Alice->John: Yes... John, how are you?
and there's not a hint to readers that it'd look different with JavaScript enabled.
For me the ideal would be to have the website build invoke https://github.com/mermaid-js/mermaid.cli and then save the rendered output for the CDN to serve. That's likely to work with a very large audience of readers.
However if that's not feasible, is it at least possible to replace the output with a clear indication that there's a missing image? For example, a plain mid-grey rectangle might provide enough of a hint. A rectangle with “please enable JavaScript” is even more clear.
a40e521
to
bea8e2b
Compare
@sftim I've insourced the JS, commented where the origin is, and added a JavaScript error that looks like: I also moved the JS implementation where we have other JS (head.html). Let me know if you think that would resolve your concerns. Thanks! |
I completely agree that having the user compose an image would be better from a usability standpoint. I do think by having it as JavaScript enables community easy edits / updates without much effort. I started to look into Hugo web-hooks / markup approaches but couldn't find anything concrete to dive into. That would be one alternative, if Hugo could generate the image on build based on a hook. Once again, my goal is to enable a feature without needing much support / effort to maintain. |
@jimangel this looks like a good approach for now, with room to make things even better at some future point |
Hello @jimangel . I quickly looked at the mermaid docs and the content here. |
@kbhawkey before I address your questions, let me preface this by saying my primary goal was to introduce a gantt diagram for a releases page much like: https://en.wikipedia.org/wiki/Kubernetes#Release_Versions the general consensus was that it was a good idea. Given the velocity of the releases (every quarter) my goal was to implement something similar to Wikipedia that could be changed every 12 weeks. With that, I wanted this feature to be easily modified and low effort to maintain. More info about the releases page here: #20293 To be clear, we don't need to merge this PR and could still create an effective
I believe the velocity is the concern here. Dynamic generation really lowers the bar. The information should be additional not essential.
Looking at the source code https://github.com/mermaid-js/mermaid it appears it is actively maintained by ~140 contributors. The code frequency appears to be healthy with the last commit ~3 days ago and the following chart indicates code velocity is also increasing: Additionally, hackmd.io supports it too: https://hackmd.io/s/features#Mermaid
For my use case it seems very strait forward. I think the examples are a great reference.
I'm not aware of security concerns, but that would definitely be worth addressing before merging this PR. Can you provide some additional context / links?
The content can be modified via CSS and there's a few issues open regarding starting points for this. If you think this is a show stopper, I would be happy to include a custom style sheet with this PR.
I've seen this and would be 100% down to change this approach to render on build if it can be easily done. I haven't found a good example how we could trigger image builds via mermaid (or other charting software). Going back to my original comment, I want this to be easily changed and implementable without a high bar to contribute. |
@jimangel This is so plush. 🤩 Does it make sense to add a link to mermaid syntax to ...but the responsible chair in me thinks it would be an even better |
+1 on the |
Hi. I am in favor of including well thought out and visually appealing diagrams in the docs 💹 . |
{{ if eq .Params.mermaid true }} | ||
<!-- Copied from https://unpkg.com/mermaid@8.5.0/dist/mermaid.min.js --> | ||
<script async src="{{ "js/mermaid.min.js" | relURL }}"></script> | ||
{{ end }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jimangel , Question:
Do you know how the field .Params.js
is used?
# config.toml
js = [
"custom-jekyll/tags",
"script"
]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no clue. It looks like it does the same thing twice (explicitly first then in shortcode after:
<script src="{{ "js/script.js" | relURL }}"></script>
<script src="{{ "js/custom-jekyll/tags.js" | relURL }}"></script>
{{ with .Params.js }}{{ range (split . ",") }}<script src="{{ (trim . " ") | relURL }}"></script><!-- custom js added -->
/lgtm |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: sftim The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
trying to follow along, so this is still dynamically rendered right? |
Yep! However, there's a strong desire to eventually switch to generation on build; if possible. |
Enabling visuals for https://mermaid-js.github.io/mermaid/ via shortcode. This was discussed at the weekly docs meeting on 4/14/2020.
I've included an example markdown doc too.