|
1 | | -{{- $jsTheme := resources.Get "js/theme.js" | resources.ExecuteAsTemplate "theme.js" . -}} |
2 | | -{{- $jsMenu := resources.Get "js/menu.js" -}} |
3 | | -{{- $jsTabs := resources.Get "js/tabs.js" -}} |
4 | | -{{- $jsLang := resources.Get "js/lang.js" -}} |
5 | | -{{- $jsCodeCopy := resources.Get "js/code-copy.js" -}} |
6 | | -{{- $jsFileTree := resources.Get "js/filetree.js" -}} |
7 | | -{{- $jsSidebar := resources.Get "js/sidebar.js" -}} |
8 | | -{{- $jsBackToTop := resources.Get "js/back-to-top.js" -}} |
9 | | - |
10 | | -{{- $scripts := slice $jsTheme $jsMenu $jsCodeCopy $jsTabs $jsLang $jsFileTree $jsSidebar $jsBackToTop | resources.Concat "js/main.js" -}} |
11 | | -{{- if hugo.IsProduction -}} |
12 | | - {{- $scripts = $scripts | minify | fingerprint -}} |
13 | | -{{- end -}} |
14 | | -<script defer src="{{ $scripts.RelPermalink }}" integrity="{{ $scripts.Data.Integrity }}"></script> |
15 | | - |
| 1 | +{{/* Core scripts (theme, menu, tabs, etc.) */}} |
| 2 | +{{- partial "scripts/core.html" . -}} |
16 | 3 |
|
17 | 4 | {{/* Search */}} |
18 | | -{{- if (site.Params.search.enable | default true) -}} |
19 | | - {{- $searchType := site.Params.search.type | default "flexsearch" -}} |
20 | | - {{- if eq $searchType "flexsearch" -}} |
21 | | - {{- $jsSearchScript := printf "%s.search.js" .Language.Lang -}} |
22 | | - {{- $jsSearch := resources.Get "js/flexsearch.js" | resources.ExecuteAsTemplate $jsSearchScript . -}} |
23 | | - {{- if hugo.IsProduction -}} |
24 | | - {{- $jsSearch = $jsSearch | minify | fingerprint -}} |
25 | | - {{- end -}} |
26 | | - {{- $flexSearchJS := resources.Get "lib/flexsearch/flexsearch.bundle.min.js" | fingerprint -}} |
27 | | - <script defer src="{{ $flexSearchJS.RelPermalink }}" integrity="{{ $flexSearchJS.Data.Integrity }}"></script> |
28 | | - <script defer src="{{ $jsSearch.RelPermalink }}" integrity="{{ $jsSearch.Data.Integrity }}"></script> |
29 | | - {{- else -}} |
30 | | - {{- warnf `search type "%s" is not supported` $searchType -}} |
31 | | - {{- end -}} |
32 | | -{{- end -}} |
| 5 | +{{- partial "scripts/search.html" . -}} |
33 | 6 |
|
34 | 7 | {{/* Mermaid */}} |
35 | 8 | {{/* FIXME: need to investigate .Page.Store hasMermaid is set for homepage */}} |
36 | 9 | {{- if and (.Page.Store.Get "hasMermaid") (not .Page.IsHome) -}} |
37 | | - {{- $mermaidJS := resources.Get "lib/mermaid/mermaid.min.js" | fingerprint -}} |
38 | | - <script defer src="{{ $mermaidJS.RelPermalink }}" integrity="{{ $mermaidJS.Data.Integrity }}"></script> |
39 | | - <script> |
40 | | - document.addEventListener("DOMContentLoaded", () => { |
41 | | - // Store original mermaid code for each diagram |
42 | | - document.querySelectorAll(".mermaid").forEach(el => { |
43 | | - el.dataset.original = el.innerHTML; |
44 | | - }); |
45 | | - |
46 | | - const theme = document.documentElement.classList.contains("dark") ? "dark" : "default"; |
47 | | - mermaid.initialize({ startOnLoad: true, theme: theme }); |
48 | | - |
49 | | - let timeout; |
50 | | - new MutationObserver(() => { |
51 | | - clearTimeout(timeout); |
52 | | - timeout = setTimeout(() => { |
53 | | - const theme = document.documentElement.classList.contains("dark") ? "dark" : "default"; |
54 | | - document.querySelectorAll(".mermaid").forEach(el => { |
55 | | - // Reset to original content, preserving HTML |
56 | | - el.innerHTML = el.dataset.original; |
57 | | - el.removeAttribute("data-processed"); |
58 | | - }); |
59 | | - mermaid.initialize({ startOnLoad: true, theme: theme }); |
60 | | - mermaid.init(); |
61 | | - }, 150); |
62 | | - }).observe(document.documentElement, { |
63 | | - attributes: true, |
64 | | - attributeFilter: ["class"] |
65 | | - }); |
66 | | - }); |
67 | | - </script> |
| 10 | + {{- partial "scripts/mermaid.html" . -}} |
68 | 11 | {{- end -}} |
69 | 12 |
|
70 | 13 | {{/* KaTex */}} |
71 | 14 | {{- if .Page.Params.math -}} |
72 | | - {{- $katexCSS := resources.Get "lib/katex/katex.min.css" | fingerprint -}} |
73 | | - {{- $katexJS := resources.Get "lib/katex/katex.min.js" | fingerprint -}} |
74 | | - {{- $mhchemJS := resources.Get "lib/katex/mhchem.min.js" | fingerprint -}} |
75 | | - {{- $katexAutoRenderJS := resources.Get "lib/katex/auto-render.min.js" | fingerprint -}} |
76 | | - <link type="text/css" rel="stylesheet" href="{{ $katexCSS.RelPermalink }}" integrity="{{ $katexCSS.Data.Integrity }}" /> |
77 | | - <script defer src="{{ $katexJS.RelPermalink }}" integrity="{{ $katexJS.Data.Integrity }}"></script> |
78 | | - <script defer src="{{ $katexAutoRenderJS.RelPermalink }}" integrity="{{ $katexAutoRenderJS.Data.Integrity }}"></script> |
79 | | - <script defer src="{{ $mhchemJS.RelPermalink }}" integrity="{{ $mhchemJS.Data.Integrity }}"></script> |
80 | | - {{ $katexFonts := resources.Match "lib/katex/fonts/*" }} |
81 | | - {{- range $katexFonts -}} |
82 | | - {{ .Publish }} |
83 | | - {{- end -}} |
84 | | - <script> |
85 | | - // TODO: make render options configurable |
86 | | - // Reference: https://katex.org/docs/autorender#api |
87 | | - document.addEventListener("DOMContentLoaded", function () { |
88 | | - renderMathInElement(document.body, { |
89 | | - delimiters: [ |
90 | | - { left: "$$", right: "$$", display: true }, |
91 | | - { left: "$", right: "$", display: false }, |
92 | | - { left: "\\(", right: "\\)", display: false }, |
93 | | - { left: "\\begin{equation}", right: "\\end{equation}", display: true }, |
94 | | - {left: "\\begin{align}", right: "\\end{align}", display: true}, |
95 | | - {left: "\\begin{alignat}", right: "\\end{alignat}", display: true}, |
96 | | - {left: "\\begin{gather}", right: "\\end{gather}", display: true}, |
97 | | - {left: "\\begin{CD}", right: "\\end{CD}", display: true}, |
98 | | - { left: "\\[", right: "\\]", display: true }, |
99 | | - ], |
100 | | - throwOnError: false, |
101 | | - }); |
102 | | - }); |
103 | | - </script> |
104 | | -{{ end }} |
| 15 | + {{- partial "scripts/katex.html" . -}} |
| 16 | +{{- end -}} |
0 commit comments