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

feat(mermaid): Add Mermaid.js diagrams plugin #1547

Merged
merged 1 commit into from
Jan 24, 2024

Conversation

cloudjumpercat
Copy link
Contributor

@cloudjumpercat cloudjumpercat commented Dec 5, 2023

The docs team recently added Mermaid.js to our own docs repo (see PR here) to make it easy to create diagrams. We also added some custom styles to match our branding colors. I thought it would make a nice addition to the Kuma repo, and I have a doc that I'm writing that would benefit from this diagram tool.

It can be used with the following syntax:

{% mermaid %}
{% endmermaid %}

With mermaid we can describe graphs and diagrams in a markdown file and have them render as what we want.
So

{% mermaid %}
gantt
   title Git Issues - days since last update
   dateFormat  X
   axisFormat %s

   section Issue19062
   71   : 0, 71
   section Issue19401
   36   : 0, 36
   section Issue193
   34   : 0, 34
   section Issue7441
   9    : 0, 9
   section Issue1300
   5    : 0, 5
{% endmermaid %}

would render as:
image

We've been using https://mermaid.live/edit to easily generate diagrams and see the rendered output before adding it to docs.

Did you sign your commit? Instructions Yes

Have you read Contributing guidelines? Yes

Copy link

netlify bot commented Dec 5, 2023

Deploy Preview for kuma ready!

Name Link
🔨 Latest commit e7ddd55
🔍 Latest deploy log https://app.netlify.com/sites/kuma/deploys/65afd0368d0e070008745b6b
😎 Deploy Preview https://deploy-preview-1547--kuma.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@cloudjumpercat
Copy link
Contributor Author

The docs team added this to our stylesheet: https://github.com/Kong/docs.konghq.com/blob/e2f6df6b7f639891c59aad47b54ffe83c752c94b/app/_assets/stylesheets/page.less#L346

But I wasn't sure where to put that in the kuma-website style sheet.

@cloudjumpercat
Copy link
Contributor Author

I need to delete this edit before this PR is merged, but here's an example of how a flowchart would currently render in the Kuma docs: https://deploy-preview-1547--kuma.netlify.app/docs/2.5.x/introduction/about-service-meshes/

@lena-larionova
Copy link
Contributor

I think you should be able to set it here, to fix the styling:
https://github.com/cloudjumpercat/kuma-website/blob/feat/mermaid-js/app/_assets/styles/custom/base/_type-and-content.scss#L89-L98C6

This should work:

  pre,
  pre[class*='language-'],
  div[class*='language-'] {
    background-color: $codeBgColor;

    &.mermaid {
      background-color: unset;
    }

    code {
      font-size: 0.9rem;
      line-height: 1.5;
      color: #333;
    }
  }

If that doesn't work, then you can do it like this:

  pre,
  pre[class*='language-'],
  div[class*='language-'] {
    background-color: $codeBgColor;

    code {
      font-size: 0.9rem;
      line-height: 1.5;
      color: #333;
    }
  }

 pre.mermaid {
      background-color: unset;
  }

@cloudjumpercat
Copy link
Contributor Author

@lena-larionova Thanks for the feedback! You're first suggestion fixed it!

@cloudjumpercat
Copy link
Contributor Author

I removed the test example so I can mark this PR as ready, but here's an image of what it looked like when rendered:
Screenshot 2023-12-07 at 8 59 33 AM

@cloudjumpercat cloudjumpercat marked this pull request as ready for review December 7, 2023 15:01
@cloudjumpercat cloudjumpercat requested a review from a team as a code owner December 7, 2023 15:01
@cloudjumpercat cloudjumpercat requested review from slonka and Automaat and removed request for a team December 7, 2023 15:01
Copy link
Contributor

@slonka slonka left a comment

Choose a reason for hiding this comment

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

Hi! :) We already have some diagrams like this one
image
and a policy to make the diagrams

The team is moving diagrams to [Google slides](https://docs.google.com/presentation/d/1qvIKeYfcuowrHW1hV9fk9mCptt3ywroPBUYFjMj9gkk/edit#slide=id.g13d0c1ffb72_0_67).
( https://docs.google.com/presentation/d/1qvIKeYfcuowrHW1hV9fk9mCptt3ywroPBUYFjMj9gkk/edit#slide=id.g13d0c1ffb72_0_67 ). I don't think we should have two ways of making diagrams and I don't think it's worth going through all of them and converting them to mermaid.

Added @lahabana to reviewers so he can take a look at this.

@slonka slonka requested a review from lahabana December 8, 2023 07:16
@lahabana
Copy link
Contributor

lahabana commented Dec 11, 2023

I think this is very welcome! Lowering the bar of adding graph and charts is a great idea!
However, should plugins like this be extracted away to be consumable as a dependency? this duplication seems to be the open door to future maintainance issues.

Can we start using it somewhere? I think it'd make it easier to review :)

Also is it ok to rely on a CDN for the mermaid lib?

@fabianrbz WDYT?

@fabianrbz
Copy link
Contributor

I think this is very welcome! Lowering the bar of adding graph and charts is a great idea! However, should plugins like this be extracted away to be consumable as a dependency? this duplication seems to be the open door to future maintainance issues.

We can, however, we wouldn't be gaining much tbh.

Can we start using it somewhere? I think it'd make it easier to review :)

We have a few examples in docs.konghq

Also is it ok to rely on a CDN for the mermaid lib?

It should be ok, it's what they use in their docs.

@fabianrbz WDYT?

It's the same implementation we have in docs.konghq, I'm trying to improve it so that the script doesn't get included with every diagram (we could have several diagrams on one page). I also don't want to include the mermaid js on every page.
I'll get back to you on this

@lahabana
Copy link
Contributor

@cloudjumpercat can you rebase you first commit so it's Signed-Off too? (or just squash all your commits).

@cloudjumpercat
Copy link
Contributor Author

@bartsmykla I squashed and signed the commit, but I'm not sure if it worked correctly since it seems to have brought in changes to the master branch. I used the following to squash it:

git reset --soft master
git commit -m "Add Mermaid diagrams" --signoff
git push origin feat/mermaid-js --force

@bartsmykla
Copy link
Contributor

@cloudjumpercat all looks good now, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants