From a1833aaf4102048cc1eeb7b04dd1a5a2d023d4c1 Mon Sep 17 00:00:00 2001
From: Cell <1024@lruihao.cn>
Date: Mon, 20 Nov 2023 18:00:04 +0800
Subject: [PATCH] :zap: Perf: preload some stylesheet
---
layouts/partials/assets.html | 6 +++---
layouts/partials/head/link.html | 16 ++++++++--------
layouts/partials/plugin/style.html | 17 ++++++++++++++++-
3 files changed, 27 insertions(+), 12 deletions(-)
diff --git a/layouts/partials/assets.html b/layouts/partials/assets.html
index bddc2cb4..38192d42 100644
--- a/layouts/partials/assets.html
+++ b/layouts/partials/assets.html
@@ -95,7 +95,7 @@
{{- $math := .Scratch.Get "math" -}}
{{- 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" -}}
+ {{- dict "Source" $source "Fingerprint" $fingerprint "Preload" true | 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" -}}
@@ -147,7 +147,7 @@
{{- /* Mapbox GL */ -}}
{{- if (.Scratch.Get "this").mapbox -}}
{{- $source := $cdn.mapboxGLCSS | default "lib/mapbox-gl/mapbox-gl.css" -}}
- {{- dict "Source" $source "Minify" true "Fingerprint" $fingerprint | dict "Scratch" .Scratch "Data" | partial "scratch/style.html" -}}
+ {{- dict "Source" $source "Minify" true "Fingerprint" $fingerprint "Preload" true | dict "Scratch" .Scratch "Data" | partial "scratch/style.html" -}}
{{- $source = $cdn.mapboxGLJS | default "lib/mapbox-gl/mapbox-gl.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 "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
@@ -158,7 +158,7 @@
{{- 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" -}}
+ {{- dict "Source" $source "Fingerprint" $fingerprint "Preload" true | 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" -}}
diff --git a/layouts/partials/head/link.html b/layouts/partials/head/link.html
index 224eecb2..2fc03020 100644
--- a/layouts/partials/head/link.html
+++ b/layouts/partials/head/link.html
@@ -32,17 +32,17 @@
{{- end -}}
{{- /* style.min.css */ -}}
-{{- $style := dict "Source" "css/style.scss" "Fingerprint" $fingerprint -}}
-{{- $options := dict "targetPath" "css/style.min.css" "enableSourceMap" true -}}
-{{- $style = dict "Context" . "ToCSS" $options | merge $style -}}
-{{- partial "plugin/style.html" $style -}}
+{{- $options := dict "Source" "css/style.scss" "Fingerprint" $fingerprint -}}
+{{- $toCSS := dict "targetPath" "css/style.min.css" "enableSourceMap" true -}}
+{{- $options = dict "Context" . "ToCSS" $toCSS | merge $options -}}
+{{- partial "plugin/style.html" $options -}}
{{- /* Font Awesome */ -}}
{{- $source := $cdn.fontawesomeFreeCSS | default "lib/fontawesome-free/all.min.css" -}}
-{{- $style := dict "Source" $source "Fingerprint" $fingerprint -}}
-{{- partial "plugin/style.html" $style -}}
+{{- $options := dict "Source" $source "Fingerprint" $fingerprint "Preload" true -}}
+{{- partial "plugin/style.html" $options -}}
{{- /* Animate.css */ -}}
{{- $source := $cdn.animateCSS | default "lib/animate/animate.min.css" -}}
-{{- $style := dict "Source" $source "Fingerprint" $fingerprint -}}
-{{- partial "plugin/style.html" $style -}}
+{{- $options := dict "Source" $source "Fingerprint" $fingerprint "Preload" true -}}
+{{- partial "plugin/style.html" $options -}}
diff --git a/layouts/partials/plugin/style.html b/layouts/partials/plugin/style.html
index 103a1a0f..f0da6a6c 100644
--- a/layouts/partials/plugin/style.html
+++ b/layouts/partials/plugin/style.html
@@ -27,5 +27,20 @@
{{- end -}}
{{- $href = $resource.RelPermalink -}}
{{- end -}}
-
+ {{- $attrs := printf `href="%v"` $href -}}
+ {{- if .Crossorigin -}}
+ {{- $attrs = ` crossorigin="anonymous"` | add $attrs -}}
+ {{- end -}}
+ {{- with $integrity -}}
+ {{- $attrs = printf ` integrity="%v"` . | add $attrs -}}
+ {{- end -}}
+ {{- with .Attr -}}
+ {{- $attrs = add " " . | add $attrs -}}
+ {{- end -}}
+ {{- if .Preload -}}
+
+
+ {{- else -}}
+
+ {{- end -}}
{{- end -}}