diff --git a/.github/workflows/jekyll-gh-pages.yml b/.github/workflows/jekyll-gh-pages.yml index e31d81c..fb6253c 100644 --- a/.github/workflows/jekyll-gh-pages.yml +++ b/.github/workflows/jekyll-gh-pages.yml @@ -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 diff --git a/scripts/mermaid.py b/scripts/mermaid.py new file mode 100644 index 0000000..3da852f --- /dev/null +++ b/scripts/mermaid.py @@ -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))