diff --git a/.prettierignore b/.prettierignore index c2fa97ea6..90cac5ecd 100644 --- a/.prettierignore +++ b/.prettierignore @@ -3,3 +3,4 @@ assets/lib *.md **/public main.css +*.json diff --git a/assets/js/lib/mathjax.js b/assets/js/lib/mathjax.js deleted file mode 100644 index 6c1257397..000000000 --- a/assets/js/lib/mathjax.js +++ /dev/null @@ -1,16 +0,0 @@ -const delimiters = window.config?.math?.delimiters; -if (!delimiters) { - return; -} -const displayMath = delimiters - .filter((d) => d.display) - .map((d) => [d.left, d.right]); -const inlineMath = delimiters - .filter((d) => !d.display) - .map((d) => [d.left, d.right]); -window.MathJax = { - tex: { - displayMath, - inlineMath, - }, -}; diff --git a/assets/js/lib/mathjax.ts b/assets/js/lib/mathjax.ts new file mode 100644 index 000000000..6a5a483f5 --- /dev/null +++ b/assets/js/lib/mathjax.ts @@ -0,0 +1,15 @@ +const delimiters = window.config?.math?.delimiters; +if (delimiters) { + const displayMath = delimiters + .filter((d) => d.display) + .map((d) => [d.left, d.right]); + const inlineMath = delimiters + .filter((d) => !d.display) + .map((d) => [d.left, d.right]); + window.MathJax = { + tex: { + displayMath, + inlineMath, + }, + }; +} diff --git a/assets/js/lib/twemoji.js b/assets/js/lib/twemoji.js deleted file mode 100644 index 9b5befec3..000000000 --- a/assets/js/lib/twemoji.js +++ /dev/null @@ -1,3 +0,0 @@ -import twemoji from "twemoji"; - -if (window.config?.twemoji) twemoji.parse(document.body); diff --git a/assets/js/lib/twemoji.ts b/assets/js/lib/twemoji.ts new file mode 100644 index 000000000..984e0fa2b --- /dev/null +++ b/assets/js/lib/twemoji.ts @@ -0,0 +1,2 @@ +import twemoji from "twemoji"; +twemoji.parse(document.body); diff --git a/layouts/partials/assets.html b/layouts/partials/assets.html index e63509ff1..539bb1edd 100644 --- a/layouts/partials/assets.html +++ b/layouts/partials/assets.html @@ -26,117 +26,6 @@ {{- end -}} {{- end -}} -{{- /* tablesort */ -}} -{{- if $params.table | and $params.table.sort | and (.Scratch.Get "this").tablesort -}} - {{- $source := $cdn.tablesort | default "lib/tablesort/tablesort.min.js" -}} - {{- dict "Source" $source "Fingerprint" $fingerprint | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}} - {{- $config = dict "sort" true | dict "table" | merge $config -}} -{{- end -}} - -{{- /* twemoji */ -}} -{{- if $params.twemoji -}} - {{- $config = dict "twemoji" true | merge $config -}} - {{- $options := dict -}} - - {{- $source := $cdn.twemojiJS | default "lib/twemoji/twemoji.min.js" -}} - {{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}} - {{- $shims := dict "twemoji" "js/shims/twemoji.js" -}} - {{- $options = dict "shims" $shims | merge $options -}} - - {{- $options = dict "targetPath" "js/twemoji.min.js" | merge $options -}} - {{- $options = dict "minify" true | merge $options -}} - {{- $js := resources.Get "js/lib/twemoji.js" | js.Build $options -}} - {{- $_ := $js.RelPermalink -}} - {{- dict "Link" $js.RelPermalink "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}} -{{- end -}} - -{{- /* lightgallery.js */ -}} -{{- if $params.lightgallery -}} - {{- $source := $cdn.lightgalleryCSS | default "lib/lightgallery/lightgallery.min.css" -}} - {{- dict "Source" $source "Fingerprint" $fingerprint | dict "Scratch" .Scratch "Data" | partial "scratch/style.html" -}} - {{- $source := $cdn.lightgalleryJS | default "lib/lightgallery/lightgallery.min.js" -}} - {{- dict "Source" $source "Fingerprint" $fingerprint | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}} - {{- $source := $cdn.lightgalleryThumbnailJS | default "lib/lightgallery/lg-thumbnail.min.js" -}} - {{- dict "Source" $source "Fingerprint" $fingerprint | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}} - {{- $source := $cdn.lightgalleryZoomJS | default "lib/lightgallery/lg-zoom.min.js" -}} - {{- dict "Source" $source "Fingerprint" $fingerprint | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}} - {{- $config = dict "selector" ".lightgallery" "speed" 400 "hideBarsDelay" 2000 "thumbnail" true "exThumbImage" "data-thumbnail" "thumbWidth" 80 "thumbContHeight" 80 "actualSize" false | dict "lightGallery" | merge $config -}} -{{- end -}} - -{{- /* Sharer.js */ -}} -{{- if $params.share.enable | and (.Scratch.Get "this").sharer -}} - {{- $source := $cdn.sharerJS | default "lib/sharer/sharer.min.js" -}} - {{- dict "Source" $source "Fingerprint" $fingerprint | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}} - {{- $config = dict "sharerjs" true | merge $config -}} -{{- end -}} - -{{- /* TypeIt */ -}} -{{- with (.Scratch.Get "this").typeitMap -}} - {{- $typeit := $.Site.Params.typeit -}} - {{- $source := $cdn.typeitJS | default "lib/typeit/typeit.min.js" -}} - {{- dict "Source" $source "Fingerprint" $fingerprint | dict "Scratch" $.Scratch "Data" | partial "scratch/script.html" -}} - {{- $config = dict "speed" $typeit.speed "cursorSpeed" $typeit.cursorSpeed "cursorChar" $typeit.cursorChar "duration" $typeit.duration "data" . | dict "typeit" | merge $config -}} -{{- end -}} - -{{- /* KaTeX */ -}} -{{- $math := $params.math -}} -{{- if eq $math true -}} - {{- $math = .Site.Params.page.math | default dict -}} -{{- else if eq $math false -}} - {{- $math = dict "enable" false -}} -{{- end -}} -{{- if $math.enable -}} - {{- if $math.mathjax -}} - {{- $source := "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js" -}} - {{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}} - {{- $options := dict -}} - {{- $options = dict "targetPath" "js/mathjax.min.js" | merge $options -}} - {{- $options = dict "minify" true | merge $options -}} - {{- $js := resources.Get "js/lib/mathjax.js" | js.Build $options -}} - {{- $_ := $js.RelPermalink -}} - {{- dict "Link" $js.RelPermalink "Fingerprint" $fingerprint | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}} - - {{- else -}} - - {{- $source := $cdn.katexCSS | default "lib/katex/katex.min.css" -}} - {{- dict "Source" $source "Fingerprint" $fingerprint | dict "Scratch" .Scratch "Data" | partial "scratch/style.html" -}} - {{- $source := $cdn.katexJS | default "lib/katex/katex.min.js" -}} - {{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}} - {{- $source := $cdn.katexAutoRenderJS | default "lib/katex/auto-render.min.js" -}} - {{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}} - {{- if $math.copyTex -}} - {{- $source := $cdn.katexCopyTexCSS | default "lib/katex/copy-tex.min.css" -}} - {{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/style.html" -}} - {{- $source := $cdn.katexCopyTexJS | default "lib/katex/copy-tex.min.js" -}} - {{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}} - {{- end -}} - {{- if $math.mhchem -}} - {{- $source := $cdn.katexMhchemJS | default "lib/katex/mhchem.min.js" -}} - {{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}} - {{- end -}} - {{- $shims := dict "katex/dist/contrib/auto-render" "js/shims/katex.js" -}} - {{- $options := dict -}} - {{- $options = dict "targetPath" "js/katex.min.js" | merge $options -}} - {{- $options = dict "minify" true | merge $options -}} - {{- $options = dict "shims" $shims | merge $options -}} - {{- $js := resources.Get "js/lib/katex.js" | js.Build $options -}} - {{- $_ := $js.RelPermalink -}} - {{- dict "Link" $js.RelPermalink "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}} - - {{- end -}} - - {{- $blockDelimiters := slice (dict "left" "$$" "right" "$$" "display" true) (dict "left" "\\[" "right" "\\]" "display" true) -}} - {{- if and $math.blockLeftDelimiter $math.blockRightDelimiter -}} - {{- $blockDelimiters = slice (dict "left" $math.blockLeftDelimiter "right" $math.blockRightDelimiter "display" true) -}} - {{- end -}} - {{- $inlineDelimiters := slice (dict "left" "$" "right" "$" "display" false) (dict "left" "\\(" "right" "\\)" "display" false) -}} - {{- if and $math.inlineLeftDelimiter $math.inlineRightDelimiter -}} - {{- $inlineDelimiters = slice (dict "left" $math.inlineLeftDelimiter "right" $math.inlineRightDelimiter "display" false) -}} - {{- end -}} - {{- $delimiters := $blockDelimiters | append $inlineDelimiters -}} - {{- $config = dict "strict" false "delimiters" $delimiters | dict "math" | merge $config -}} -{{- end -}} - {{- /* mermaid */ -}} {{- if (.Scratch.Get "this").mermaid -}} +{{- end -}} + +{{- /* lightgallery.js */ -}} +{{/* Run only when lightgallary is enabled */}} +{{- if $params.lightgallery -}} + {{- dict "cdn" $cdn.lightgalleryCSS "default" "lib/lightgallery/lightgallery.min.css" | partial "partials/assets/deferStyle.html" -}} + {{- dict "cdn" $cdn.lightgalleryJS "default" "lib/lightgallery/lightgallery.min.js" | partial "partials/assets/deferScript.html" -}} + {{- dict "cdn" $cdn.lightgalleryThumbnailJS "default" "lib/lightgallery/lg-thumbnail.min.js" | partial "partials/assets/deferScript.html" -}} + {{- dict "cdn" $cdn.lightgalleryZoomJS "default" "lib/lightgallery/lg-zoom.min.js" | partial "partials/assets/deferScript.html" -}} + + {{- $config = dict "selector" ".lightgallery" "speed" 400 "hideBarsDelay" 2000 "thumbnail" true "exThumbImage" "data-thumbnail" "thumbWidth" 80 "thumbContHeight" 80 "actualSize" false | dict "lightGallery" | merge $config -}} +{{- end -}} + +{{- /* Sharer.js */ -}} +{{/* Run only when enabled and on page that's sharable */}} +{{- if $params.share.enable | and (.Scratch.Get "this").sharer -}} + {{- $src := dict "cdn" $cdn.sharerJS "default" "lib/sharer/sharer.min.js" | partial "partials/assets/deferScript.html" -}} + + {{- $config = dict "sharerjs" true | merge $config -}} +{{- end -}} + +{{- /* TypeIt */ -}} +{{- with (.Scratch.Get "this").typeitMap -}} + {{- $typeit := $.Site.Params.typeit -}} + {{- dict "cdn" $cdn.typeitJS "default" "lib/typeit/typeit.min.js" | partial "partials/assets/deferScript.html" -}} + + {{- $config = dict "speed" $typeit.speed "cursorSpeed" $typeit.cursorSpeed "cursorChar" $typeit.cursorChar "duration" $typeit.duration "data" . | dict "typeit" | merge $config -}} +{{- end -}} + +{{- /* Math (KaTeX or mathjax) */ -}} +{{- $math := $params.math -}} +{{- if eq $math true -}} + {{- $math = .Site.Params.page.math | default dict -}} +{{- else if eq $math false -}} + {{- $math = dict "enable" false -}} +{{- end -}} +{{- if $math.enable -}} + {{- if $math.mathjax -}} + + + {{- $options := dict "targetPath" "js/mathjax.min.js" "minify" true -}} + {{- $js := resources.Get "js/lib/mathjax.ts" | js.Build $options -}} + + {{- else -}} + {{- dict "cdn" $cdn.katexCSS "default" "lib/katex/katex.min.css" | partial "partials/assets/deferStyle.html" -}} + {{- dict "cdn" $cdn.katexJS "default" "lib/katex/katex.min.js" | partial "partials/assets/deferScript.html" -}} + + {{- dict "cdn" $cdn.katexAutoRenderJS "default" "lib/katex/auto-render.min.js" | partial "partials/assets/deferScript.html" -}} + + {{- if $math.copyTex -}} + {{- dict "cdn" $cdn.katexCopyTexCSS "default" "lib/katex/copy-tex.min.css" | partial "partials/assets/deferStyle.html" -}} + {{- dict "cdn" $cdn.katexCopyTexJS "default" "lib/katex/copy-tex.min.js" | partial "partials/assets/deferScript.html" -}} + {{- end -}} + + {{- if $math.mhchem -}} + {{- dict "cdn" $cdn.katexMhchemJS "default" "lib/katex/mhchem.min.js" | partial "partials/assets/deferScript.html" -}} + {{- end -}} + + {{- $options := dict "targetPath" "js/katex.min.js" "minify" true "shims" (dict "katex/dist/contrib/auto-render" "js/shims/katex.js") -}} + {{- $js := resources.Get "js/lib/katex.js" | js.Build $options -}} + + {{- end -}} + + {{- $blockDelimiters := slice (dict "left" "$$" "right" "$$" "display" true) (dict "left" "\\[" "right" "\\]" "display" true) -}} + {{- if and $math.blockLeftDelimiter $math.blockRightDelimiter -}} + {{- $blockDelimiters = slice (dict "left" $math.blockLeftDelimiter "right" $math.blockRightDelimiter "display" true) -}} + {{- end -}} + {{- $inlineDelimiters := slice (dict "left" "$" "right" "$" "display" false) (dict "left" "\\(" "right" "\\)" "display" false) -}} + {{- if and $math.inlineLeftDelimiter $math.inlineRightDelimiter -}} + {{- $inlineDelimiters = slice (dict "left" $math.inlineLeftDelimiter "right" $math.inlineRightDelimiter "display" false) -}} + {{- end -}} + {{- $delimiters := $blockDelimiters | append $inlineDelimiters -}} + {{- $config = dict "strict" false "delimiters" $delimiters | dict "math" | merge $config -}} +{{- end -}} + {{/* Instant page */}} {{- if $params.instantpage.enable -}} -{{- $js := resources.Get "/lib/instant.page/instantpage.min.js" -}} + {{- $js := resources.Get "/lib/instant.page/instantpage.min.js" -}} {{- end -}} -{{- range (.Scratch.Get "this").style -}} - {{- partial "plugin/style.html" . -}} -{{- end -}} - {{/* Config script */}} +{{- end -}} + +{{- define "partials/assets/deferStyle.html" -}} + {{- $src := .cdn | default .default -}} + {{- $value := resources.Get $src -}} + +{{- end -}} diff --git a/layouts/partials/function/src.html b/layouts/partials/function/src.html new file mode 100644 index 000000000..e69de29bb