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 }}
|
{{ content | safe }}
|
||||||
</main>
|
</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>
|
<footer>
|
||||||
<div>
|
<div>
|
||||||
<!-- Social Things -->
|
<!-- Social Things -->
|
||||||
|
|
|
||||||
|
|
@ -121,6 +121,7 @@ md.use(markdownItContainer, 'details', {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
md.use(markdownItFootnote);
|
md.use(markdownItFootnote);
|
||||||
md.use(markdownItHashtag);
|
md.use(markdownItHashtag);
|
||||||
md.use(markdownItMermaid);
|
md.use(markdownItMermaid);
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,15 @@ const getGitModifiedTime = (filePath) => {
|
||||||
return null;
|
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 getTitleFromFilename = (filePath) => {
|
||||||
const basename = path.basename(filePath, '.md');
|
const basename = path.basename(filePath, '.md');
|
||||||
return basename
|
return basename
|
||||||
|
|
@ -115,6 +124,9 @@ module.exports = {
|
||||||
getGitModifiedTime(data.page.inputPath) ??
|
getGitModifiedTime(data.page.inputPath) ??
|
||||||
getFileModifiedTime(data.page.inputPath);
|
getFileModifiedTime(data.page.inputPath);
|
||||||
},
|
},
|
||||||
|
mermaid: (data) => {
|
||||||
|
return hasMermaidContent(data.page.inputPath);
|
||||||
|
},
|
||||||
permalink: (data) => {
|
permalink: (data) => {
|
||||||
const title = data.title || getTitleFromFilename(data.page.inputPath);
|
const title = data.title || getTitleFromFilename(data.page.inputPath);
|
||||||
const slug = title.toLowerCase().replace(/\s+/g, '-').replace(/[^\w-]/g, '');
|
const slug = title.toLowerCase().replace(/\s+/g, '-').replace(/[^\w-]/g, '');
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue