Add katex shortcode

pull/26/head
James Panther 2021-11-04 10:06:52 +11:00
parent 40899da9a8
commit 554ae35e6f
No known key found for this signature in database
GPG Key ID: D36F789E45745D17
2 changed files with 47 additions and 30 deletions

View File

@ -1,39 +1,55 @@
{{/* Mermaid */}} {{/* Mermaid */}}
{{ if .Page.HasShortcode "mermaid" }} {{ if .Page.HasShortcode "mermaid" }}
{{ $mermaidJS := resources.Get "vendor/mermaid/mermaid.min.js" }} {{ $mermaidJS := resources.Get "vendor/mermaid/mermaid.min.js" }}
{{ if $mermaidJS }} {{ $mermaidJS := $mermaidJS | resources.Fingerprint "sha512" }} <script defer src="{{ $mermaidJS.RelPermalink }}" integrity="{{ $mermaidJS.Data.Integrity }}"></script>
{{ $mermaidJS := $mermaidJS | resources.Fingerprint "sha512" }} <script defer src="{{ $mermaidJS.RelPermalink }}" integrity="{{ $mermaidJS.Data.Integrity }}"></script> <script>
<script> document.addEventListener('DOMContentLoaded', (event) => {
document.addEventListener('DOMContentLoaded', (event) => { function css(name) {
function css(name) { return getComputedStyle(document.documentElement).getPropertyValue(name);
return getComputedStyle(document.documentElement).getPropertyValue(name); }
} mermaid.initialize({ theme: "base", themeVariables: { background: css("--color-neutral"), primaryColor: css("--color-primary-200"), secondaryColor: css("--color-secondary-200"), tertiaryColor: css("--color-neutral-100"), primaryBorderColor: css("--color-primary-400"), secondaryBorderColor: css("--color-secondary-400"), tertiaryBorderColor: css("--color-neutral-400"), lineColor: css("--color-neutral-600"), fontFamily: "ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,segoe ui,Roboto,helvetica neue,Arial,noto sans,sans-serif", fontSize: "16px" }});
mermaid.initialize({ theme: "base", themeVariables: { background: css("--color-neutral"), primaryColor: css("--color-primary-200"), secondaryColor: css("--color-secondary-200"), tertiaryColor: css("--color-neutral-100"), primaryBorderColor: css("--color-primary-400"), secondaryBorderColor: css("--color-secondary-400"), tertiaryBorderColor: css("--color-neutral-400"), lineColor: css("--color-neutral-600"), fontFamily: "ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,segoe ui,Roboto,helvetica neue,Arial,noto sans,sans-serif", fontSize: "16px" }}); });
}); </script>
</script>
{{ end }}
{{ end }} {{ end }}
{{/* Chart */}} {{/* Chart */}}
{{ if .Page.HasShortcode "chart" }} {{ if .Page.HasShortcode "chart" }}
{{ $chartJS := resources.Get "vendor/chart/chart.min.js" }} {{ $chartJS := resources.Get "vendor/chart/chart.min.js" }}
{{ if $chartJS }} {{ $chartJS := $chartJS | resources.Fingerprint "sha512" }}
{{ $chartJS := $chartJS | resources.Fingerprint "sha512" }} <script defer src="{{ $chartJS.RelPermalink }}" integrity="{{ $chartJS.Data.Integrity }}"></script>
<script defer src="{{ $chartJS.RelPermalink }}" integrity="{{ $chartJS.Data.Integrity }}"></script> <script>
<script> document.addEventListener('DOMContentLoaded', (event) => {
document.addEventListener('DOMContentLoaded', (event) => { function css(name) {
function css(name) { return getComputedStyle(document.documentElement).getPropertyValue(name);
return getComputedStyle(document.documentElement).getPropertyValue(name); }
} Chart.defaults.font.size = 14;
Chart.defaults.font.size = 14; Chart.defaults.backgroundColor = css("--color-primary-300");
Chart.defaults.backgroundColor = css("--color-primary-300"); Chart.defaults.elements.point.borderColor = css("--color-primary-400");
Chart.defaults.elements.point.borderColor = css("--color-primary-400"); Chart.defaults.elements.bar.borderColor = css("--color-primary-500");
Chart.defaults.elements.bar.borderColor = css("--color-primary-500"); Chart.defaults.elements.bar.borderWidth = 1;
Chart.defaults.elements.bar.borderWidth = 1; Chart.defaults.elements.line.borderColor = css("--color-primary-400");
Chart.defaults.elements.line.borderColor = css("--color-primary-400"); Chart.defaults.elements.arc.backgroundColor = css("--color-primary-200");
Chart.defaults.elements.arc.backgroundColor = css("--color-primary-200"); Chart.defaults.elements.arc.borderColor = css("--color-primary-500");
Chart.defaults.elements.arc.borderColor = css("--color-primary-500"); Chart.defaults.elements.arc.borderWidth = 1;
Chart.defaults.elements.arc.borderWidth = 1; });
}); </script>
</script> {{ end }}
{{/* Katex */}}
{{ if .Page.HasShortcode "katex" }}
{{ $katexCSS := resources.Get "vendor/katex/katex.min.css" }}
{{ $katexCSS := $katexCSS | resources.Fingerprint "sha512" }}
<link
type="text/css" rel="stylesheet"
href="{{ $katexCSS.RelPermalink }}"
integrity="{{ $katexCSS.Data.Integrity }}"
/>
{{ $katexJS := resources.Get "vendor/katex/katex.min.js" }}
{{ $katexJS := $katexJS | resources.Fingerprint "sha512" }}
<script defer src="{{ $katexJS.RelPermalink }}" integrity="{{ $katexJS.Data.Integrity }}"></script>
{{ $katexRenderJS := resources.Get "vendor/katex/auto-render.min.js" }}
{{ $katexRenderJS := $katexRenderJS | resources.Fingerprint "sha512" }}
<script defer src="{{ $katexRenderJS.RelPermalink }}" integrity="{{ $katexRenderJS.Data.Integrity }}" onload="renderMathInElement(document.body);"></script>
{{ $katexFonts := resources.Match "vendor/katex/fonts/*" }}
{{ range $katexFonts }}
<!-- {{ .RelPermalink }} -->
{{ end }} {{ end }}
{{ end }} {{ end }}

View File

@ -0,0 +1 @@
{{/* Nothing to see here */}}