mirror of
https://github.com/hugo-fixit/FixIt.git
synced 2026-09-02 19:52:40 +00:00
303 lines
17 KiB
HTML
303 lines
17 KiB
HTML
{{- $params := .Scratch.Get "params" -}}
|
|
{{- $cdn := .Scratch.Get "cdn" | default dict -}}
|
|
{{- $fingerprint := .Scratch.Get "fingerprint" -}}
|
|
{{- $config := (.Scratch.Get "this").config -}}
|
|
|
|
{{- /* Search */ -}}
|
|
{{- if .Site.Params.search | and .Site.Params.search.enable -}}
|
|
{{- $search := .Site.Params.search -}}
|
|
{{- $source := $cdn.autocompleteJS | default "lib/autocomplete/autocomplete.min.js" -}}
|
|
{{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
|
|
{{- $config = dict "maxResultLength" $search.maxResultLength "snippetLength" $search.snippetLength "highlightTag" $search.highlightTag "noResultsFound" (T "noResultsFound") | dict "search" | merge $config -}}
|
|
{{- if eq $search.type "lunr" -}}
|
|
{{- with .Site.Home.OutputFormats.Get "json" -}}
|
|
{{- $config = dict "type" "lunr" "lunrIndexURL" .RelPermalink | dict "search" | merge $config -}}
|
|
{{- end -}}
|
|
{{- $source := $cdn.lunrJS | default "lib/lunr/lunr.min.js" -}}
|
|
{{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
|
|
{{- if T "lunrLanguageLib" -}}
|
|
{{- $config = T "lunrLanguageCode" | dict "lunrLanguageCode" | dict "search" | merge $config -}}
|
|
{{- with T "lunrSegmentitLib" -}}
|
|
{{- $config = dict "lunrSegmentitURL" (resources.Get .).RelPermalink | dict "search" | merge $config -}}
|
|
{{- end -}}
|
|
{{- dict "Source" "lib/lunr/lunr.stemmer.support.js" "Minify" true "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
|
|
{{- dict "Source" (T "lunrLanguageLib") "Minify" true "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
|
|
{{- end -}}
|
|
{{- else if eq $search.type "algolia" -}}
|
|
{{- $source := $cdn.algoliasearchJS | default "lib/algoliasearch/algoliasearch-lite.umd.min.js" -}}
|
|
{{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
|
|
{{- $config = dict "type" "algolia" "algoliaIndex" $search.algolia.index "algoliaAppID" $search.algolia.appID "algoliaSearchKey" $search.algolia.searchKey | dict "search" | merge $config -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
|
|
{{- /* lazysizes */ -}}
|
|
{{- $source := $cdn.lazysizesJS | default "lib/lazysizes/lazysizes.min.js" -}}
|
|
{{- dict "Source" $source "Fingerprint" $fingerprint "Async" true "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
|
|
|
|
{{- /* twemoji */ -}}
|
|
{{- if $params.twemoji -}}
|
|
{{- $source := $cdn.twemojiJS | default "lib/twemoji/twemoji.min.js" -}}
|
|
{{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
|
|
{{- $config = dict "twemoji" true | merge $config -}}
|
|
{{- 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 "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
|
|
{{- $source := $cdn.lightgalleryThumbnailJS | default "lib/lightgallery/lg-thumbnail.min.js" -}}
|
|
{{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
|
|
{{- $source := $cdn.lightgalleryZoomJS | default "lib/lightgallery/lg-zoom.min.js" -}}
|
|
{{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | 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 -}}
|
|
|
|
{{- $code := $params.code | default dict -}}
|
|
{{- $config = cond (ne $code.maxShownLines nil) $code.maxShownLines 10 | dict "maxShownLines" | dict "code" | merge $config -}}
|
|
|
|
{{- /* clipboard.js */ -}}
|
|
{{- if ne $code.copy false -}}
|
|
{{- $source := $cdn.clipboardJS | default "lib/clipboard/clipboard.min.js" -}}
|
|
{{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
|
|
{{- $config = T "copyToClipboard" | dict "copyTitle" | dict "code" | merge $config -}}
|
|
{{- end -}}
|
|
|
|
{{- /* Sharer.js */ -}}
|
|
{{- if $params.share.enable -}}
|
|
{{- $source := $cdn.sharerJS | default "lib/sharer/sharer.min.js" -}}
|
|
{{- dict "Source" $source "Fingerprint" $fingerprint "Async" true "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
|
|
{{- 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 "Defer" true | 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 -}}
|
|
{{- $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 | 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 -}}
|
|
{{- $delimiters := slice (dict "left" "$$" "right" "$$" "display" true) (dict "left" "\\[" "right" "\\]" "display" true) -}}
|
|
{{- if and $math.blockLeftDelimiter $math.blockRightDelimiter -}}
|
|
{{- $delimiters = $delimiters | append (dict "left" $math.blockLeftDelimiter "right" $math.blockRightDelimiter "display" true) -}}
|
|
{{- end -}}
|
|
{{- $delimiters = $delimiters | append (dict "left" "$" "right" "$" "display" false) (dict "left" "\\(" "right" "\\)" "display" false) -}}
|
|
{{- if and $math.inlineLeftDelimiter $math.inlineRightDelimiter -}}
|
|
{{- $delimiters = $delimiters | append (dict "left" $math.inlineRightDelimiter "right" $math.inlineRightDelimiter "display" false) -}}
|
|
{{- end -}}
|
|
{{- $config = dict "strict" false "delimiters" $delimiters | dict "math" | merge $config -}}
|
|
{{- end -}}
|
|
|
|
{{- /* mermaid */ -}}
|
|
{{- if (.Scratch.Get "this").mermaid -}}
|
|
{{- $source := $cdn.mermaidJS | default "lib/mermaid/mermaid.min.js" -}}
|
|
{{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
|
|
{{- $options := dict "targetPath" "lib/mermaid/mermaid.min.css" "enableSourceMap" true -}}
|
|
{{- dict "Source" "lib/mermaid/mermaid.scss" "ToCSS" $options "Fingerprint" $fingerprint | dict "Scratch" .Scratch "Data" | partial "scratch/style.html" -}}
|
|
{{- end -}}
|
|
|
|
{{- /* ECharts */ -}}
|
|
{{- if (.Scratch.Get "this").echarts -}}
|
|
{{- $source := $cdn.echartsJS | default "lib/echarts/echarts.min.js" -}}
|
|
{{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
|
|
{{- $source := $cdn.echartsMacaronsJS | default "lib/echarts/macarons.js" -}}
|
|
{{- dict "Source" $source "Minify" true "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
|
|
{{- end -}}
|
|
|
|
{{- /* Mapbox GL */ -}}
|
|
{{- if (.Scratch.Get "this").mapbox -}}
|
|
{{- $source := $cdn.mapboxGLCSS | default "lib/mapbox-gl/mapbox-gl.min.css" -}}
|
|
{{- dict "Source" $source "Fingerprint" $fingerprint | dict "Scratch" .Scratch "Data" | partial "scratch/style.html" -}}
|
|
{{- $source := $cdn.mapboxGLJS | default "lib/mapbox-gl/mapbox-gl.min.js" -}}
|
|
{{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
|
|
{{- dict "Source" "lib/mapbox-gl/mapbox-gl-language.js" "Minify" true "Fingerprint" $fingerprint | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
|
|
{{- $config = dict "accessToken" $params.mapbox.accessToken "RTLTextPlugin" "https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-rtl-text/v0.2.0/mapbox-gl-rtl-text.js" | dict "mapbox" | merge $config -}}
|
|
{{- end -}}
|
|
|
|
{{- /* Music */ -}}
|
|
{{- if (.Scratch.Get "this").music -}}
|
|
{{- /* APlayer */ -}}
|
|
{{- $source := $cdn.aplayerCSS | default "lib/aplayer/APlayer.min.css" -}}
|
|
{{- dict "Source" $source "Fingerprint" $fingerprint | dict "Scratch" .Scratch "Data" | partial "scratch/style.html" -}}
|
|
{{- $options := dict "targetPath" "lib/aplayer/dark.min.css" "enableSourceMap" true -}}
|
|
{{- dict "Source" "lib/aplayer/dark.scss" "ToCSS" $options "Fingerprint" $fingerprint | dict "Scratch" .Scratch "Data" | partial "scratch/style.html" -}}
|
|
{{- $source := $cdn.aplayerJS | default "lib/aplayer/APlayer.min.js" -}}
|
|
{{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
|
|
|
|
{{- /* MetingJS */ -}}
|
|
{{- $source := $cdn.metingJS | default "lib/meting/Meting.min.js" -}}
|
|
{{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
|
|
{{- end -}}
|
|
|
|
{{- /* Cookie Consent */ -}}
|
|
{{- if .Site.Params.cookieconsent | and .Site.Params.cookieconsent.enable -}}
|
|
{{- $source := $cdn.cookieconsentCSS | default "lib/cookieconsent/cookieconsent.min.css" -}}
|
|
{{- dict "Source" $source "Fingerprint" $fingerprint | dict "Scratch" .Scratch "Data" | partial "scratch/style.html" -}}
|
|
{{- $source := $cdn.cookieconsentJS | default "lib/cookieconsent/cookieconsent.min.js" -}}
|
|
{{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
|
|
{{- $cookieconsentConfig := dict "popup" (dict "background" "#1aa3ff") "button" (dict "background" "#f0f0f0") | dict "theme" "edgeless" "palette" -}}
|
|
{{- $cookieconsentConfig = .Site.Params.cookieconsent | merge $cookieconsentConfig -}}
|
|
{{- $cookieconsentConfig = dict "message" ($cookieconsentConfig.content.message | default (T "cookieconsentMessage")) "dismiss" ($cookieconsentConfig.content.dismiss | default (T "cookieconsentDismiss")) "link" ($cookieconsentConfig.content.link | default (T "cookieconsentLink")) | dict "content" | merge $cookieconsentConfig -}}
|
|
{{- $config = $cookieconsentConfig | dict "cookieconsent" | merge $config -}}
|
|
{{- end -}}
|
|
|
|
{{- /* PanguJS */ -}}
|
|
{{- if eq .Site.Params.pangu.enable true -}}
|
|
{{- $source := $cdn.metingJS | default "lib/pangu/pangu.min.js" -}}
|
|
{{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
|
|
{{- end -}}
|
|
|
|
{{- /* Watermark */ -}}
|
|
{{- if eq .Site.Params.watermark.enable true -}}
|
|
{{- $source := "lib/watermark/watermark.min.js" -}}
|
|
{{- dict "Source" $source "Fingerprint" $fingerprint | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
|
|
{{- end -}}
|
|
|
|
{{- /* 不蒜子 */ -}}
|
|
{{- if eq .Site.Params.ibruce.enable true -}}
|
|
{{- $source := "//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" -}}
|
|
{{- dict "Source" $source "Fingerprint" $fingerprint "Async" true "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
|
|
{{- end -}}
|
|
|
|
{{- range $params.library.css -}}
|
|
{{- dict "Source" . "Fingerprint" $fingerprint | dict "Scratch" $.Scratch "Data" | partial "scratch/style.html" -}}
|
|
{{- end -}}
|
|
|
|
{{- range $params.library.js -}}
|
|
{{- dict "Source" . "Fingerprint" $fingerprint "Defer" true | dict "Scratch" $.Scratch "Data" | partial "scratch/script.html" -}}
|
|
{{- end -}}
|
|
|
|
{{- with (.Scratch.Get "this").styleArr -}}
|
|
{{- $content := delimit . "" -}}
|
|
{{- $path := substr (md5 $content) 0 6 | printf "css/%v" -}}
|
|
{{- $options := printf "%v.min.css" $path | dict "targetPath" -}}
|
|
{{- dict "Content" $content "Path" (printf "%v.scss" $path) "ToCSS" $options | dict "Scratch" $.Scratch "Data" | partial "scratch/style.html" -}}
|
|
{{- end -}}
|
|
|
|
{{- /* Config script */ -}}
|
|
{{- $config | jsonify | printf "window.config=%s;" | dict "Content" | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
|
|
|
|
{{- /* Theme script */ -}}
|
|
{{- dict "Source" "js/theme.min.js" "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
|
|
{{- $_ := (resources.Get "js/theme.min.js.map").RelPermalink -}}
|
|
|
|
{{- /* Custom script */ -}}
|
|
{{- if eq .Site.Params.customJS.enable true -}}
|
|
{{- $source = "js/_custom.js" -}}
|
|
{{- if eq .Site.Params.customJS.minify true -}}
|
|
{{- $source = "js/_custom.min.js" -}}
|
|
{{- end -}}
|
|
{{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
|
|
{{- end -}}
|
|
|
|
{{- with (.Scratch.Get "this").scriptArr -}}
|
|
{{- delimit . "\n" | dict "Content" | dict "Scratch" $.Scratch "Data" | partial "scratch/script.html" -}}
|
|
{{- end -}}
|
|
|
|
{{- range (.Scratch.Get "this").style -}}
|
|
{{- partial "plugin/style.html" . -}}
|
|
{{- end -}}
|
|
|
|
{{- range (.Scratch.Get "this").script -}}
|
|
{{- partial "plugin/script.html" . -}}
|
|
{{- end -}}
|
|
|
|
{{- partial "plugin/analytics.html" . -}}
|
|
|
|
{{- /* Initialize libraries scripts */ -}}
|
|
<script type="text/javascript">
|
|
{{- /* Calculate run time */ -}}
|
|
{{- if eq .Site.Params.ibruce.enable true | and .Site.Params.ibruce.siteTime -}}
|
|
function createTime() {
|
|
let now = new Date();
|
|
let run = new Date({{ $.Site.Params.ibruce.siteTime }});
|
|
//總的秒數
|
|
let runTime = (now - run) / 1000,
|
|
days = Math.floor(runTime / 60 / 60 / 24),
|
|
hours = Math.floor(runTime / 60 / 60 - (24 * days)),
|
|
minutes = Math.floor(runTime / 60 - (24 * 60 * days) - (60 * hours)),
|
|
seconds = Math.floor((now - run) / 1000 - (24 * 60 * 60 * days) - (60 * 60 * hours) - (60 * minutes));
|
|
document.querySelector(".run-times").innerHTML = `${days}d ${String(hours).padStart(2,0)}h ${String(minutes).padStart(2,0)}m ${String(seconds).padStart(2,0)}s`;
|
|
}
|
|
{{- end -}}
|
|
|
|
/**
|
|
* Immediate.
|
|
*/
|
|
(() => {
|
|
{{- /* PWA Initialization */ -}}
|
|
{{- if eq hugo.Environment "production" | and .Site.Params.enablePWA -}}
|
|
if ('serviceWorker' in navigator) {
|
|
navigator.serviceWorker
|
|
.register('/service-worker.min.js', { scope: '/' })
|
|
.then(function (registration) {
|
|
// console.log('Service Worker Registered');
|
|
})
|
|
.catch(function (error) {
|
|
console.error('error: ', error);
|
|
});
|
|
navigator.serviceWorker.ready.then(function (registration) {
|
|
// console.log('Service Worker Ready');
|
|
});
|
|
}
|
|
{{- end -}}
|
|
|
|
{{- /* Watermark Initialization */ -}}
|
|
{{- if eq .Site.Params.watermark.enable true -}}
|
|
{{- with .Site.Params.watermark -}}
|
|
new Watermark({
|
|
content: {{ .Content }} || '<i class="fa-stack fa-xs logo-icon"><i class="fas fa-bug fa-stack-1x"></i><i class="fas fa-ban fa-stack-2x"></i></i> Theme FixIt',
|
|
appendTo: {{ .AppendTo }} || '.wrapper>.main',
|
|
opacity: {{ .Opacity }},
|
|
width: {{ .Width }},
|
|
height: {{ .Height }},
|
|
rowSpacing: {{ .RowSpacing }},
|
|
colSpacing: {{ .ColSpacing }},
|
|
rotate: {{ .Rotate }},
|
|
fontSize: {{ .FontSize }}
|
|
});
|
|
{{- end -}}
|
|
{{- end -}}
|
|
|
|
{{- /* Site time Initialization */ -}}
|
|
{{- if eq .Site.Params.ibruce.enable true | and .Site.Params.ibruce.siteTime -}}
|
|
if (!document.hidden) {
|
|
var siteTime = setInterval("createTime()", 500);
|
|
} else {
|
|
clearInterval(siteTime);
|
|
}
|
|
{{- end -}}
|
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
// Listen to any DOM change and automatically perform spacing via MutationObserver()
|
|
{{ if eq .Site.Params.pangu.enable true }}pangu.autoSpacingPage();{{ end }}
|
|
});
|
|
|
|
})();
|
|
</script>
|