mirror of
https://github.com/hugo-fixit/FixIt.git
synced 2026-08-24 23:38:56 +00:00
⚡ Perf: remove inline script (#32)
This commit is contained in:
Vendored
+1
-1
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -170,18 +170,27 @@
|
||||
{{- 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" -}}
|
||||
{{- $config = dict "enablePangu" true | merge $config -}}
|
||||
{{- 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" -}}
|
||||
{{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
|
||||
{{- $config = dict "watermark" .Site.Params.watermark | merge $config -}}
|
||||
{{- 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" -}}
|
||||
{{- $ibruceConfig := dict "enable" true "siteTime" .Site.Params.ibruce.siteTime -}}
|
||||
{{- $config = dict "ibruce" $ibruceConfig | merge $config -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- /* PWA */ -}}
|
||||
{{- if eq hugo.Environment "production" -}}
|
||||
{{- $config = dict "enablePWA" .Site.Params.enablePWA | merge $config -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- range $params.library.css -}}
|
||||
@@ -228,78 +237,3 @@
|
||||
{{- 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},${String(hours).padStart(2,0)}:${String(minutes).padStart(2,0)}:${String(seconds).padStart(2,0)}`;
|
||||
}
|
||||
{{- 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> FixIt Theme',
|
||||
appendTo: {{ .AppendTo }} || '.wrapper>.main',
|
||||
opacity: {{ .Opacity }},
|
||||
width: {{ .Width }},
|
||||
height: {{ .Height }},
|
||||
rowSpacing: {{ .RowSpacing }},
|
||||
colSpacing: {{ .ColSpacing }},
|
||||
rotate: {{ .Rotate }},
|
||||
fontSize: {{ .FontSize }},
|
||||
fontFamily: {{ .fontFamily }}
|
||||
});
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- /* Site time Initialization */ -}}
|
||||
{{- if eq .Site.Params.ibruce.enable true | and .Site.Params.ibruce.siteTime -}}
|
||||
var siteTime = setInterval("createTime()", 500);
|
||||
document.addEventListener("visibilitychange", () => {
|
||||
if (document.hidden) {
|
||||
return clearInterval(siteTime);
|
||||
}
|
||||
var siteTime = setInterval("createTime()", 500);
|
||||
});
|
||||
{{- 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>
|
||||
|
||||
@@ -652,6 +652,64 @@ class Theme {
|
||||
if (this.config.cookieconsent) cookieconsent.initialise(this.config.cookieconsent);
|
||||
}
|
||||
|
||||
getSiteTime() {
|
||||
let now = new Date();
|
||||
let run = new Date(this.config.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},${String(hours).padStart(2,0)}:${String(minutes).padStart(2,0)}:${String(seconds).padStart(2,0)}`;
|
||||
}
|
||||
|
||||
initSiteTime() {
|
||||
if(this.config.ibruce.enable && this.config.ibruce.siteTime){
|
||||
this.siteTime = setInterval(this.getSiteTime, 500);
|
||||
document.addEventListener("visibilitychange", () => {
|
||||
if (document.hidden) {
|
||||
return clearInterval(this.siteTime);
|
||||
}
|
||||
this.siteTime = setInterval(this.getSiteTime, 500);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
initServiceWorker() {
|
||||
if (this.config.enablePWA && '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');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
initWatermark() {
|
||||
this.config.watermark.enable && new Watermark({
|
||||
content: this.config.watermark.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> FixIt Theme',
|
||||
appendTo:this.config.watermark.appendTo || '.wrapper>.main',
|
||||
opacity: this.config.watermark.opacity,
|
||||
width: this.config.watermark.width,
|
||||
height: this.config.watermark.height,
|
||||
rowSpacing: this.config.watermark.rowSpacing,
|
||||
colSpacing: this.config.watermark.colSpacing,
|
||||
rotate: this.config.watermark.rotate,
|
||||
fontSize: this.config.watermark.fontSize,
|
||||
fontFamily: this.config.watermark.fontFamily
|
||||
});
|
||||
}
|
||||
|
||||
initPangu() {
|
||||
this.config.enablePangu && pangu.autoSpacingPage();
|
||||
}
|
||||
|
||||
onScroll() {
|
||||
const $headers = [];
|
||||
if (document.body.getAttribute('header-desktop') === 'auto') $headers.push(document.getElementById('header-desktop'));
|
||||
@@ -736,6 +794,10 @@ class Theme {
|
||||
this.initTypeit();
|
||||
this.initMapbox();
|
||||
this.initCookieconsent();
|
||||
this.initSiteTime();
|
||||
this.initServiceWorker();
|
||||
this.initWatermark();
|
||||
this.initPangu();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user