Skip to content

feat: Conditionally load Mermaid.js#2

Merged
donglua merged 1 commit into
mainfrom
feature-conditional-mermaid-load-3116489472377016004
Jan 15, 2026
Merged

feat: Conditionally load Mermaid.js#2
donglua merged 1 commit into
mainfrom
feature-conditional-mermaid-load-3116489472377016004

Conversation

@donglua
Copy link
Copy Markdown
Owner

@donglua donglua commented Jan 15, 2026

This change modifies the post layout to only include the Mermaid.js script if the post content contains a Mermaid diagram. This is achieved by checking for the presence of the "language-mermaid" string in the post's content. This change improves page load performance by avoiding the unnecessary loading of the Mermaid.js library on pages that do not contain any diagrams.

This change modifies the post layout to only include the Mermaid.js script if the post content contains a Mermaid diagram. This is achieved by checking for the presence of the "language-mermaid" string in the post's content. This change improves page load performance by avoiding the unnecessary loading of the Mermaid.js library on pages that do not contain any diagrams.
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @donglua, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request implements a performance optimization by introducing conditional loading for the Mermaid.js library. Instead of including the script on every post page, it will now only be loaded when a post is detected to contain a Mermaid diagram. This targeted approach ensures that resources are only consumed when necessary, leading to faster page rendering for content without diagrams.

Highlights

  • Conditional Script Loading: The Mermaid.js script is now conditionally loaded in _layouts/post.html. It will only be included if the post's content contains the string 'language-mermaid', indicating the presence of a Mermaid diagram.
  • Performance Improvement: This change optimizes page load performance by preventing the unnecessary loading of the Mermaid.js library on pages that do not contain any diagrams, reducing bandwidth and processing overhead.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@donglua donglua merged commit 2d2c76b into main Jan 15, 2026
1 check failed
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a good performance optimization by loading Mermaid.js conditionally, only when a diagram is present in the post content. The approach of checking for the 'language-mermaid' string is a sensible and pragmatic way to achieve this. My review includes one suggestion to improve code formatting for better readability and consistency.

Comment thread _layouts/post.html

{% include mermaid.html %} No newline at end of file
{% if content contains 'language-mermaid' %}
{% include mermaid.html %}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

For better readability and to maintain a consistent coding style with the rest of the file, please consider indenting the include tag within the if block.

  {% include mermaid.html %}

@donglua donglua deleted the feature-conditional-mermaid-load-3116489472377016004 branch January 15, 2026 06:23
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.

1 participant