Skip to content

Commit

Permalink
mermaid
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelmattig committed Dec 9, 2024
1 parent 2378d40 commit 489cd7b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/jekyll-gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ jobs:
with:
source: ./
destination: ./_site
- name: Install Mermaid
run: |
cd ./_site
python3 ../scripts/mermaid.py
cd -
- name: Upload artifact
uses: actions/upload-pages-artifact@v3

Expand Down
22 changes: 22 additions & 0 deletions scripts/mermaid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from bs4 import BeautifulSoup

# Load the HTML content
with open('index.html', 'r') as file:
soup = BeautifulSoup(file, 'html.parser')

# Create the new script tag
new_script = soup.new_tag('script', type='module')
new_script.string = '''
import mermaid from "https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.esm.min.mjs";
for (const element of document.getElementsByClassName("language-mermaid")) {
element.classList.add("mermaid");
}
mermaid.initialize({ startOnLoad: true });
'''

# Append the script tag to the end of the body
soup.body.append(new_script)

# Save the modified HTML back to the file
with open('index.html', 'w') as file:
file.write(str(soup))

0 comments on commit 489cd7b

Please sign in to comment.