Skip to content

fix: make mermaid.js store locally & remove duplicated import#437

Merged
imbajin merged 2 commits intoapache:masterfrom
Swadeep006:bugfix-branch
Dec 10, 2025
Merged

fix: make mermaid.js store locally & remove duplicated import#437
imbajin merged 2 commits intoapache:masterfrom
Swadeep006:bugfix-branch

Conversation

@Swadeep006
Copy link
Contributor

Purpose of the PR

Replaced the external Mermaid CDN script with a locally hosted mermaid.min.js to make Mermaid rendering compliant with ASF CSP rules.

Summary

  • Added mermaid.min.js under static/js/
  • Updated head-end.html to load Mermaid from 'self' instead of an external CDN
  • Verified that Mermaid diagrams render correctly and no external scripts are loaded
Screenshot 2025-12-10 151228

@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. bug Something isn't working labels Dec 10, 2025
@imbajin imbajin requested a review from Copilot December 10, 2025 10:35
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request addresses issue #408 by replacing the external Mermaid CDN script with a locally hosted version to comply with ASF CSP (Content Security Policy) rules. The change ensures that all scripts are loaded from 'self' rather than external domains.

  • Replaced CDN-hosted mermaid library with local file at themes/docsy/static/js/mermaid.min.js
  • Added mermaid package dependency to package.json for version tracking
  • Updated script reference in head-end.html to use local path instead of jsdelivr CDN

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.

File Description
themes/docsy/layouts/partials/hooks/head-end.html Updated mermaid script source from jsdelivr CDN to local file path using relURL
package.json Added mermaid v10.9.5 as a dependency to track the library version being used

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


{{ if .Site.Params.mermaid.enable }}
<script src="https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.min.js"></script>
<script src="{{ "js/mermaid.min.js" | relURL }}"></script>
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

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

This change introduces duplicate loading of mermaid.min.js. The Mermaid library is already loaded in themes/docsy/layouts/partials/scripts.html at line 6. Loading the same library twice will cause unnecessary bandwidth usage and may lead to initialization conflicts.

Consider removing this script tag since Mermaid is already loaded in scripts.html, or remove the one in scripts.html if this location is preferred.

Suggested change
<script src="{{ "js/mermaid.min.js" | relURL }}"></script>

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

hi @imbajin ,
Updated head-end.html to only handle Mermaid initialization. The library itself is now loaded once from scripts.html via the local js/mermaid.min.js file to avoid duplicate script loading.

@imbajin imbajin changed the title fix #408 fix: make mermaid.js store locally & remove duplicated import Dec 10, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Dec 10, 2025
@imbajin imbajin merged commit 2e03daa into apache:master Dec 10, 2025
1 check passed
github-actions bot pushed a commit that referenced this pull request Dec 10, 2025
* fix #408

* Use single local Mermaid load and keep initialization in head-end 2e03daa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working lgtm This PR has been approved by a maintainer size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Add Mermaid diagram & image rendering support

3 participants