diff --git a/assets/js/clipboard.js b/assets/js/clipboard.js index d8a95ef..55eec7b 100644 --- a/assets/js/clipboard.js +++ b/assets/js/clipboard.js @@ -5,7 +5,11 @@ var pre = document.getElementsByTagName('pre'); for (var i = 0; i < pre.length; ++ i) { var element = pre[i]; - element.insertAdjacentHTML('afterbegin', ''); + var mermaid = element.getElementsByClassName('language-mermaid')[0]; + + if (mermaid == null) { + element.insertAdjacentHTML('afterbegin', ''); + } } var clipboard = new Clipboard('.btn-copy', { diff --git a/assets/js/highlight.js b/assets/js/highlight.js index 00a2a2d..c96b781 100644 --- a/assets/js/highlight.js +++ b/assets/js/highlight.js @@ -18,7 +18,7 @@ hljs.registerLanguage('yaml', yaml); hljs.registerLanguage('md', markdown); document.addEventListener('DOMContentLoaded', () => { - document.querySelectorAll('pre code').forEach((block) => { + document.querySelectorAll('pre code:not(.language-mermaid)').forEach((block) => { hljs.highlightElement(block); }); }); diff --git a/assets/js/mermaid.js b/assets/js/mermaid.js new file mode 100644 index 0000000..2ab0b9a --- /dev/null +++ b/assets/js/mermaid.js @@ -0,0 +1,11 @@ +import mermaid from 'mermaid/dist/mermaid'; + +var config = { + theme: 'default', + fontFamily: '"Jost", -apple-system, blinkmacsystemfont, "Segoe UI", roboto, "Helvetica Neue", arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";', +}; + +document.addEventListener('DOMContentLoaded', () => { + mermaid.initialize(config); + mermaid.init(undefined, '.language-mermaid'); +}); diff --git a/assets/scss/app.scss b/assets/scss/app.scss index 9086c5b..fc76d8e 100644 --- a/assets/scss/app.scss +++ b/assets/scss/app.scss @@ -24,6 +24,7 @@ @import "components/comments"; @import "components/forms"; @import "components/images"; +@import "components/mermaid"; @import "components/search"; @import "components/tables"; @import "layouts/footer"; diff --git a/assets/scss/common/_dark.scss b/assets/scss/common/_dark.scss index 44deb6c..479dfc1 100644 --- a/assets/scss/common/_dark.scss +++ b/assets/scss/common/_dark.scss @@ -232,11 +232,6 @@ body.dark pre code::-webkit-scrollbar-thumb { background: $gray-400; } -body.dark code:not(.hljs) { - background: $body-overlay-dark; - color: $body-color-dark; -} - body.dark pre code:hover { scrollbar-width: thin; scrollbar-color: $border-dark transparent; @@ -246,6 +241,16 @@ body.dark pre code::-webkit-scrollbar-thumb:hover { background: $gray-500; } +body.dark code:not(.hljs):not(.language-mermaid) { + background: $body-overlay-dark; + color: $body-color-dark; +} + +body.dark .mermaid, +body.dark pre code.language-mermaid { + background: $white; +} + body.dark blockquote { border-left: 3px solid $border-dark; } diff --git a/assets/scss/components/_code.scss b/assets/scss/components/_code.scss index c53e6f7..eb0c0a0 100644 --- a/assets/scss/components/_code.scss +++ b/assets/scss/components/_code.scss @@ -60,3 +60,7 @@ pre code:hover { pre code::-webkit-scrollbar-thumb:hover { background: $gray-500; } + +code.language-mermaid { + background: none; +} diff --git a/assets/scss/components/_mermaid.scss b/assets/scss/components/_mermaid.scss new file mode 100644 index 0000000..3ff2488 --- /dev/null +++ b/assets/scss/components/_mermaid.scss @@ -0,0 +1,8 @@ +.mermaid { + margin: 1.5rem 0; + padding: 1.5rem; +} + +.mermaid svg { + height: auto; +} diff --git a/config/_default/config.toml b/config/_default/config.toml index 3f8c8da..56fc5c8 100644 --- a/config/_default/config.toml +++ b/config/_default/config.toml @@ -93,3 +93,6 @@ rel = "sitemap" [[module.mounts]] source = "node_modules/katex" target = "assets/js/vendor/katex" + [[module.mounts]] + source = "node_modules/mermaid" + target = "assets/js/vendor/mermaid" diff --git a/config/postcss.config.js b/config/postcss.config.js index 0155a41..4b26fa1 100644 --- a/config/postcss.config.js +++ b/config/postcss.config.js @@ -22,6 +22,7 @@ module.exports = { ...whitelister([ './assets/scss/components/_buttons.scss', './assets/scss/components/_code.scss', + './assets/scss/components/_diagrams.scss', './assets/scss/components/_syntax.scss', './assets/scss/components/_search.scss', './assets/scss/common/_dark.scss', diff --git a/layouts/index.headers b/layouts/index.headers index 31746da..ce35f41 100644 --- a/layouts/index.headers +++ b/layouts/index.headers @@ -2,7 +2,7 @@ Strict-Transport-Security: max-age=31536000; includeSubDomains; preload X-Content-Type-Options: nosniff X-XSS-Protection: 1; mode=block - Content-Security-Policy: default-src 'self'; frame-ancestors https://jamstackthemes.dev; manifest-src 'self'; connect-src 'self'; font-src 'self'; img-src 'self' data:; script-src 'self'; style-src 'self' + Content-Security-Policy: default-src 'self'; frame-ancestors https://jamstackthemes.dev; manifest-src 'self'; connect-src 'self'; font-src 'self'; img-src 'self' data:; script-src 'self'; style-src 'self' 'unsafe-inline' X-Frame-Options: SAMEORIGIN Referrer-Policy: strict-origin Feature-Policy: geolocation 'self' diff --git a/layouts/partials/footer/script-footer.html b/layouts/partials/footer/script-footer.html index 76cf0d5..64ccf13 100644 --- a/layouts/partials/footer/script-footer.html +++ b/layouts/partials/footer/script-footer.html @@ -10,6 +10,8 @@ {{ $katex := resources.Get "js/vendor/katex/dist/katex.js" -}} {{ $katexAutoRender := resources.Get "js/vendor/katex/dist/contrib/auto-render.js" -}} +{{ $mermaid := resources.Get "js/mermaid.js" | js.Build -}} + {{ $app := resources.Get "js/app.js" -}} {{ $slice := slice $app -}} @@ -63,6 +65,9 @@ {{ end -}} + {{ with .Params.mermaid -}} + + {{ end -}} {{ if .Site.Params.options.flexSearch -}} {{ end -}} @@ -73,6 +78,7 @@ {{ $highlight := $highlight | minify | fingerprint "sha512" -}} {{ $katex := $katex | minify | fingerprint "sha512" -}} {{ $katexAutoRender := $katexAutoRender | minify | fingerprint "sha512" -}} + {{ $mermaid := $mermaid | minify | fingerprint "sha512" -}} {{ if .Site.Params.options.bootStrapJs -}} {{ end -}} @@ -84,6 +90,9 @@ {{ end -}} + {{ with .Params.mermaid -}} + + {{ end -}} {{ if .Site.Params.options.flexSearch -}} {{ end -}} diff --git a/layouts/shortcodes/mermaid.html b/layouts/shortcodes/mermaid.html new file mode 100644 index 0000000..aeecad5 --- /dev/null +++ b/layouts/shortcodes/mermaid.html @@ -0,0 +1,8 @@ +{{ if .Page.Params.mermaid -}} +