Skip to content

Commit

Permalink
added marmaid.js in learning-center and blog
Browse files Browse the repository at this point in the history
  • Loading branch information
tfsojon committed Aug 2, 2023
1 parent 87d07ac commit 48ea80e
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 125 deletions.
12 changes: 4 additions & 8 deletions themes/delta/layouts/_default/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,11 @@ <h1 class="h2 mb-3">{{.Title | markdownify}}</h1>
</span>
</div>

<div class="content">
{{ if .Page.Store.Get "hasMermaid" }}<p class="content-loader text-center">loading..</p>{{end}}
<div class="content {{ if .Page.Store.Get `hasMermaid` }}content-hidden{{end}}">
{{.Content}}
</div>

{{ if .Page.Store.Get "hasMermaid" }}
<script type="module">
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.esm.min.mjs';
mermaid.initialize({ startOnLoad: true });
</script>
{{ end }}

{{ with site.GetPage (string .Params.Author | urlize | lower) }}
{{if .Title}}
<div class="post-author d-flex border rounded-lg mt-5">
Expand Down Expand Up @@ -115,6 +109,8 @@ <h3 class="h5 title mb-1"><a href="{{.RelPermalink}}" class="text-dark">{{ .Titl
</div>
</section>

{{ partial "mermaid-script" . }}

{{ if site.Params.blog_popup.enable }}
{{ partial "popup-form" (dict "Class" "blog-popup" "Src" site.Params.blog_popup.clickup_iframe_url) }}
{{ end }}
Expand Down
4 changes: 2 additions & 2 deletions themes/delta/layouts/mindmaps/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ <h2 class="h4 text-center mb-4 text-muted">{{ .Key }}</h2>

{{ else }}

<p class="content-loader text-center">loading..</p>
{{ if .Page.Store.Get "hasMermaid" }}<p class="content-loader text-center">loading..</p>{{end}}

<div class="content content-hidden">
<div class="content {{ if .Page.Store.Get `hasMermaid` }}content-hidden{{end}}">
{{ with site.GetPage "mindmaps" }}
{{ with .Params.all_mindmaps_button }}
<a href="{{.link | relLangURL}}" class="border rounded py-1 pe-2 ps-1 d-inline-flex align-item-center line-height-0">
Expand Down
14 changes: 6 additions & 8 deletions themes/delta/layouts/partials/learning-center.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,9 @@ <h2 class="mb-4 font-weight-medium">{{ .Title }}</h2>
<span class="text-muted small d-inline-block mb-4" style="opacity:.75">Last Update : {{ .Lastmod.Format "02 January, 2006" }} <span class="mx-1 text-dark-50">|</span> Published : {{ .PublishDate.Format "02 January, 2006" }} <span class="mx-1 text-dark-50">|</span> {{.ReadingTime}} {{i18n `min_read`}}</span>

{{ if .Content }}
<div class="content" data-spy="scroll" data-target="#TableOfContents" data-offset="20">{{.Content}}</div>

{{ if .Page.Store.Get "hasMermaid" }}
<script type="module">
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.esm.min.mjs';
mermaid.initialize({ startOnLoad: true });
</script>
{{ end }}

{{ if .Page.Store.Get "hasMermaid" }}<p class="content-loader text-center">loading..</p>{{end}}
<div class="content {{ if .Page.Store.Get `hasMermaid` }}content-hidden{{end}}" data-spy="scroll" data-target="#TableOfContents" data-offset="20">{{.Content}}</div>

{{ else }}
<ul class="list-styled text-left mb-4">
Expand All @@ -57,6 +52,7 @@ <h2 class="mb-4 font-weight-medium">{{ .Title }}</h2>
{{end}}
</ul>
{{ end }}

<nav class="pagination">
<!-- Next prev page -->
{{ $currentNode := . }}
Expand Down Expand Up @@ -104,6 +100,8 @@ <h2 class="mb-4 font-weight-medium">{{ .Title }}</h2>

</div>

{{ partial "mermaid-script" . }}

{{ if site.Params.learning_center_popup.enable }}
{{ partial "popup-form" (dict "Class" "learning-center-popup" "Src" site.Params.learning_center_popup.clickup_iframe_url) }}
{{ end }}
Expand Down
236 changes: 129 additions & 107 deletions themes/delta/layouts/partials/mermaid-script.html
Original file line number Diff line number Diff line change
@@ -1,125 +1,147 @@
{{ range .Data.Pages }}
<div
class="offcanvas offcanvas-end fade"
data-bs-scroll="true"
tabindex="-1"
id="{{.Title | urlize}}"
aria-labelledby="{{.Title | urlize}}"
style="width:500px; transform:none"
>
<div class="offcanvas-header">
<h4 class="offcanvas-title" id="offcanvasExampleLabel">{{.Title}}</h4>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
{{ if .Page.Store.Get "hasMermaid" }}

{{ range where site.Pages "Section" .Section }}
<div
class="offcanvas offcanvas-end fade"
tabindex="-1"
id="{{.Title | urlize}}"
aria-labelledby="{{.Title | urlize}}"
style="width:500px; transform:none"
>
<div class="offcanvas-header">
<h4 class="offcanvas-title" id="offcanvasExampleLabel">{{.Title}}</h4>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
<div class="content">
{{.Content}}
</div>
<div class="offcanvas-body">
<div class="content">
{{.Content}}
</div>
</div>
</div>
{{ end }}

{{ range .Data.Pages }}
<div
class="offcanvas offcanvas-end fade"
tabindex="-1"
id="{{.Title | urlize}}"
aria-labelledby="{{.Title | urlize}}"
style="width:500px; transform:none"
>
<div class="offcanvas-header">
<h4 class="offcanvas-title" id="offcanvasExampleLabel">{{.Title}}</h4>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
<div class="content">
{{.Content}}
</div>
</div>
{{ end }}
</div>
{{ end }}

{{ if .Page.Store.Get "hasMermaid" }}
<script type="module">
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.esm.min.mjs';
mermaid.initialize({
startOnLoad: true,
securityLevel: 'loose',
theme: 'forest',
});
<script type="module">
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.esm.min.mjs';
mermaid.initialize({
startOnLoad: true,
securityLevel: 'loose',
theme: 'forest',
});

import zenuml from 'https://cdn.jsdelivr.net/npm/@mermaid-js/mermaid-zenuml@0.1.0/dist/mermaid-zenuml.esm.min.mjs';
await mermaid.registerExternalDiagrams([zenuml]);
import zenuml from 'https://cdn.jsdelivr.net/npm/@mermaid-js/mermaid-zenuml/dist/mermaid-zenuml.esm.min.mjs';
await mermaid.registerExternalDiagrams([zenuml]);

function urlize(str) {
str = str.trim();
str = str.replace(/\s+/g, '-');
str = str.replace(/[^\w-]/g, '');
str = str.replace(/-{2,}/g, '-');
str = str.toLowerCase();
return str;
}
function urlize(str) {
str = str.trim();
str = str.replace(/\s+/g, '-');
str = str.replace(/[^\w-]/g, '');
str = str.replace(/-{2,}/g, '-');
str = str.toLowerCase();
return str;
}

window.addEventListener('load', (event) => {
const body = document.querySelector('body');
const contentLoader = document.querySelector('.content-loader');
const content = document.querySelector('.content');
contentLoader.remove();
content.classList.remove('content-hidden');
window.addEventListener('load', (event) => {
const body = document.querySelector('body');
const contentLoader = document.querySelector('.content-loader');
const content = document.querySelectorAll('.content');
contentLoader.remove();
content.forEach(function(el) {
el.classList.remove('content-hidden');
});

let addDataAttribute = (el, textID) => {
el.setAttribute('type', 'button');
el.setAttribute('data-mindmap', '');
el.setAttribute('data-bs-toggle', 'offcanvas');
el.setAttribute('data-bs-target', '#'+urlize(textID));
el.setAttribute('aria-controls', urlize(textID));
}
let addDataAttribute = (el, textID) => {
el.setAttribute('type', 'button');
el.setAttribute('data-mindmap', '');
el.setAttribute('data-bs-toggle', 'offcanvas');
el.setAttribute('data-bs-target', '#'+urlize(textID));
el.setAttribute('aria-controls', urlize(textID));
}

setTimeout(function() {
// maindmap
let mindmapNode = document.querySelectorAll('.mindmap-node:not(.section-root):not(.node)');
mindmapNode.forEach(function(el) {
let innerText = el.querySelectorAll('.text-inner-tspan');
const textArray = [];
innerText.forEach((text) => {
textArray.push(text.textContent);
});
const textID = textArray.join(' ');
let id = document.getElementById(urlize(textID));
if (id) { addDataAttribute(el, textID) }
setTimeout(function() {
// maindmap
let mindmapNode = document.querySelectorAll('.mindmap-node:not(.section-root):not(.node)');
mindmapNode.forEach(function(el) {
let innerText = el.querySelectorAll('.text-inner-tspan');
const textArray = [];
innerText.forEach((text) => {
textArray.push(text.textContent);
});
const textID = textArray.join(' ');
let id = document.getElementById(urlize(textID));
if (id) { addDataAttribute(el, textID) }
});

// flowchart
let flowchartLabel = document.querySelectorAll('.flowchart-label');
let flowchartEdgeLabel = document.querySelectorAll('g.edgeLabel');
let flowchartLabels = [...flowchartLabel, ...flowchartEdgeLabel];
flowchartLabels.forEach(function(el) {
let nodeLabel = el.querySelectorAll('.nodeLabel');
let edgeLabel = el.querySelectorAll('.edgeLabel');
let allLabel = [...nodeLabel, ...edgeLabel];
const textArray = [];
allLabel.forEach((text) => {
textArray.push(text.textContent);
});
const textID = textArray.join(' ');
let id = document.getElementById(urlize(textID));
if (id) { addDataAttribute(el, textID) }
// flowchart
let flowchartLabel = document.querySelectorAll('.flowchart-label');
let flowchartEdgeLabel = document.querySelectorAll('g.edgeLabel');
let flowchartLabels = [...flowchartLabel, ...flowchartEdgeLabel];
flowchartLabels.forEach(function(el) {
let nodeLabel = el.querySelectorAll('.nodeLabel');
let edgeLabel = el.querySelectorAll('.edgeLabel');
let allLabel = [...nodeLabel, ...edgeLabel];
const textArray = [];
allLabel.forEach((text) => {
textArray.push(text.textContent);
});
const textID = textArray.join(' ');
let id = document.getElementById(urlize(textID));
if (id) { addDataAttribute(el, textID) }
});

// C4Context
let personMan = document.querySelectorAll('.person-man');
let personManLabel = document.querySelectorAll('g.edgeLabel');

personMan.forEach(function(el) {
const textArray = [];
let allLabel = el.querySelectorAll('text');
allLabel.forEach((text) => {
let fontSize = window.getComputedStyle(text).fontSize;
if (fontSize == '16px') {
textArray.push(text.textContent);
}
});

const textID = textArray.join(' ');
let id = document.querySelector(`[aria-labelledby="${urlize(textID)}"]`);
if (id) { addDataAttribute(el, textID) }
// C4Context
let personMan = document.querySelectorAll('.person-man');
let personManLabel = document.querySelectorAll('g.edgeLabel');

personMan.forEach(function(el) {
const textArray = [];
let allLabel = el.querySelectorAll('text');
allLabel.forEach((text) => {
let fontSize = window.getComputedStyle(text).fontSize;
if (fontSize == '16px') {
textArray.push(text.textContent);
}
});

// zenuml
let zenumlParticipant = document.querySelectorAll('.zenuml .participant');
let zenumlMessageName = document.querySelectorAll('.message .name');
let allZenuml = [...zenumlParticipant, ...zenumlMessageName];

allZenuml.forEach(function(el) {
let label = el.querySelector('.name');
const textID = el.textContent;
let id = document.getElementById(urlize(el.innerText));
if (id) { addDataAttribute(el, textID) }
});
const textID = textArray.join(' ');
let id = document.querySelector(`[aria-labelledby="${urlize(textID)}"]`);
if (id) { addDataAttribute(el, textID) }
});

// zenuml
let zenumlParticipant = document.querySelectorAll('.zenuml .participant');
let zenumlMessageName = document.querySelectorAll('.message .name');
let allZenuml = [...zenumlParticipant, ...zenumlMessageName];

allZenuml.forEach(function(el) {
let label = el.querySelector('.name');
const textID = el.textContent;
let id = document.getElementById(urlize(el.innerText));
if (id) { addDataAttribute(el, textID) }
});

}, 1000);
});

</script>
{{ end }}
}, 1000);
});

</script>
{{ end }}

0 comments on commit 48ea80e

Please sign in to comment.