feat: fixed mermaid diagrams
This commit is contained in:
parent
a6ce214130
commit
ffd33049d9
3 changed files with 20 additions and 0 deletions
|
|
@ -60,6 +60,13 @@
|
|||
{{ content | safe }}
|
||||
</main>
|
||||
|
||||
{% if mermaid %}
|
||||
<script type="module">
|
||||
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.esm.min.mjs';
|
||||
mermaid.initialize({ startOnLoad: true });
|
||||
</script>
|
||||
{% endif %}
|
||||
|
||||
<footer>
|
||||
<div>
|
||||
<!-- Social Things -->
|
||||
|
|
|
|||
|
|
@ -121,6 +121,7 @@ md.use(markdownItContainer, 'details', {
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
md.use(markdownItFootnote);
|
||||
md.use(markdownItHashtag);
|
||||
md.use(markdownItMermaid);
|
||||
|
|
|
|||
|
|
@ -33,6 +33,15 @@ const getGitModifiedTime = (filePath) => {
|
|||
return null;
|
||||
};
|
||||
|
||||
const hasMermaidContent = (filePath) => {
|
||||
try {
|
||||
const content = fs.readFileSync(filePath, 'utf-8');
|
||||
return /```mermaid/i.test(content);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const getTitleFromFilename = (filePath) => {
|
||||
const basename = path.basename(filePath, '.md');
|
||||
return basename
|
||||
|
|
@ -115,6 +124,9 @@ module.exports = {
|
|||
getGitModifiedTime(data.page.inputPath) ??
|
||||
getFileModifiedTime(data.page.inputPath);
|
||||
},
|
||||
mermaid: (data) => {
|
||||
return hasMermaidContent(data.page.inputPath);
|
||||
},
|
||||
permalink: (data) => {
|
||||
const title = data.title || getTitleFromFilename(data.page.inputPath);
|
||||
const slug = title.toLowerCase().replace(/\s+/g, '-').replace(/[^\w-]/g, '');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue