diff options
author | Dillon <dillonzq@outlook.com> | 2022-05-13 21:28:35 +0300 |
---|---|---|
committer | Dillon <dillonzq@outlook.com> | 2022-05-13 21:28:35 +0300 |
commit | a0c340316aedbc6725c68f284c67d5a4f3075e1a (patch) | |
tree | fec0e2651d07d2df17cdc9bccb632f05d95e12eb /layouts | |
parent | f4c7857f4fadfcb19d4304d5ddfbc079b1216f76 (diff) |
feat: preload some stylesheets and rename some plugin partials
Diffstat (limited to 'layouts')
-rw-r--r-- | layouts/_default/_markup/render-image.html | 4 | ||||
-rw-r--r-- | layouts/_default/_markup/render-link.html | 2 | ||||
-rw-r--r-- | layouts/_default/summary.html | 4 | ||||
-rw-r--r-- | layouts/partials/head/link.html | 16 | ||||
-rw-r--r-- | layouts/partials/header.html | 4 | ||||
-rw-r--r-- | layouts/partials/home/profile.html | 4 | ||||
-rw-r--r-- | layouts/partials/plugin/a.html (renamed from layouts/partials/plugin/link.html) | 2 | ||||
-rw-r--r-- | layouts/partials/plugin/img.html (renamed from layouts/partials/plugin/image.html) | 0 | ||||
-rw-r--r-- | layouts/partials/plugin/script.html | 54 | ||||
-rw-r--r-- | layouts/partials/plugin/social.html | 2 | ||||
-rw-r--r-- | layouts/partials/plugin/style.html | 17 | ||||
-rw-r--r-- | layouts/posts/single.html | 4 | ||||
-rw-r--r-- | layouts/shortcodes/image.html | 4 | ||||
-rw-r--r-- | layouts/shortcodes/link.html | 2 | ||||
-rw-r--r-- | layouts/shortcodes/version.html | 2 |
15 files changed, 76 insertions, 45 deletions
diff --git a/layouts/_default/_markup/render-image.html b/layouts/_default/_markup/render-image.html index a79cddf0..b92397e4 100644 --- a/layouts/_default/_markup/render-image.html +++ b/layouts/_default/_markup/render-image.html @@ -1,10 +1,10 @@ {{- if .Title -}} <figure> - {{- dict "Src" .Destination "Title" .Text "Caption" .Title "Linked" true "Resources" .Page.Resources | partial "plugin/image.html" -}} + {{- dict "Src" .Destination "Title" .Text "Caption" .Title "Linked" true "Resources" .Page.Resources | partial "plugin/img.html" -}} <figcaption class="image-caption"> {{- .Title | safeHTML -}} </figcaption> </figure> {{- else -}} - {{- dict "Src" .Destination "Title" .Text "Resources" .Page.Resources | partial "plugin/image.html" -}} + {{- dict "Src" .Destination "Title" .Text "Resources" .Page.Resources | partial "plugin/img.html" -}} {{- end -}} diff --git a/layouts/_default/_markup/render-link.html b/layouts/_default/_markup/render-link.html index 0c053962..f10d4416 100644 --- a/layouts/_default/_markup/render-link.html +++ b/layouts/_default/_markup/render-link.html @@ -3,4 +3,4 @@ {{- $destination = .RelPermalink -}} {{- end -}} {{- $options := dict "Destination" $destination "Title" .Title "Content" .Text -}} -{{- partial "plugin/link.html" $options -}} +{{- partial "plugin/a.html" $options -}} diff --git a/layouts/_default/summary.html b/layouts/_default/summary.html index 6d40d6ac..3689b712 100644 --- a/layouts/_default/summary.html +++ b/layouts/_default/summary.html @@ -12,7 +12,7 @@ {{- with $image -}} <div class="featured-image-preview"> <a href="{{ $.RelPermalink }}"> - {{- dict "Src" . "Title" $.Description "Resources" $.Resources | partial "plugin/image.html" -}} + {{- dict "Src" . "Title" $.Description "Resources" $.Resources | partial "plugin/img.html" -}} </a> </div> {{- end -}} @@ -28,7 +28,7 @@ {{- $authorLink := $params.authorlink | default .Site.Author.link | default .Site.Home.RelPermalink -}} <span class="post-author"> {{- $options := dict "Class" "author" "Destination" $authorLink "Title" "Author" "Rel" "author" "Icon" (dict "Class" "fas fa-user-circle fa-fw") "Content" $author -}} - {{- partial "plugin/link.html" $options -}} + {{- partial "plugin/a.html" $options -}} </span> {{- with .Site.Params.dateFormat | default "2006-01-02" | .PublishDate.Format -}} diff --git a/layouts/partials/head/link.html b/layouts/partials/head/link.html index 0473ce94..e944cdd2 100644 --- a/layouts/partials/head/link.html +++ b/layouts/partials/head/link.html @@ -30,17 +30,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/header.html b/layouts/partials/header.html index 98177797..092f4742 100644 --- a/layouts/partials/header.html +++ b/layouts/partials/header.html @@ -5,7 +5,7 @@ <a href="{{ .Site.Home.RelPermalink }}" title="{{ .Site.Title }}"> {{- with .Site.Params.header.title -}} {{- with .logo -}} - {{- dict "Src" . "Class" "logo" | partial "plugin/image.html" -}} + {{- dict "Src" . "Class" "logo" | partial "plugin/img.html" -}} {{- end -}} {{- with .pre -}} <span class="header-title-pre">{{ . | safeHTML }}</span> @@ -92,7 +92,7 @@ <a href="{{ .Site.Home.RelPermalink }}" title="{{ .Site.Title }}"> {{- with .Site.Params.header.title -}} {{- with .logo -}} - {{- dict "Src" . "Class" "logo" | partial "plugin/image.html" -}} + {{- dict "Src" . "Class" "logo" | partial "plugin/img.html" -}} {{- end -}} {{- with .pre -}} <span class="header-title-pre">{{ . | safeHTML }}</span> diff --git a/layouts/partials/home/profile.html b/layouts/partials/home/profile.html index b453fad3..db715dbe 100644 --- a/layouts/partials/home/profile.html +++ b/layouts/partials/home/profile.html @@ -13,10 +13,10 @@ {{- $url = .RelPermalink -}} {{- end -}} <a href="{{ $url }}"{{ with .Title | default .Name }} title="{{ . }}"{{ end }}{{ if (urls.Parse $url).Host }} rel="noopener noreffer" target="_blank"{{ end }}> - {{- dict "Src" $avatar | partial "plugin/image.html" -}} + {{- dict "Src" $avatar | partial "plugin/img.html" -}} </a> {{- else -}} - {{- dict "Src" $avatar | partial "plugin/image.html" -}} + {{- dict "Src" $avatar | partial "plugin/img.html" -}} {{- end -}} </div> {{- end -}} diff --git a/layouts/partials/plugin/link.html b/layouts/partials/plugin/a.html index 83da75fa..ceaefc62 100644 --- a/layouts/partials/plugin/link.html +++ b/layouts/partials/plugin/a.html @@ -6,4 +6,4 @@ {{- with .Content -}} {{- . | safeHTML -}} {{- end -}} -</a> +</a>
\ No newline at end of file diff --git a/layouts/partials/plugin/image.html b/layouts/partials/plugin/img.html index 8468583e..8468583e 100644 --- a/layouts/partials/plugin/image.html +++ b/layouts/partials/plugin/img.html diff --git a/layouts/partials/plugin/script.html b/layouts/partials/plugin/script.html index e12e74e2..9b9fa378 100644 --- a/layouts/partials/plugin/script.html +++ b/layouts/partials/plugin/script.html @@ -1,25 +1,41 @@ -{{- if .Content -}} - <script type="text/javascript"> - {{- .Content | safeJS -}} - </script> -{{- else if strings.HasPrefix .Source "<script" -}} - {{- safeHTML .Source -}} +{{- with .Content -}} + <script type="text/javascript">{{ . | safeJS }}</script> {{- else -}} - {{- $src := .Source -}} - {{- $integrity := .Integrity -}} - {{- if (urls.Parse $src).Host | not -}} - {{- $resource := resources.Get $src -}} - {{- with .Template -}} - {{- $resource = $resource | resources.ExecuteAsTemplate . $.Context -}} + {{- if strings.HasPrefix .Source "<script" -}} + {{- safeHTML .Source -}} + {{- else -}} + {{- $src := .Source -}} + {{- $integrity := .Integrity -}} + {{- if (urls.Parse $src).Host | not -}} + {{- $resource := resources.Get $src -}} + {{- with .Template -}} + {{- $resource = $resource | resources.ExecuteAsTemplate . $.Context -}} + {{- end -}} + {{- if .Minify -}} + {{- $resource = $resource | minify -}} + {{- end -}} + {{- with .Fingerprint -}} + {{- $resource = $resource | fingerprint . -}} + {{- $integrity = $resource.Data.Integrity -}} + {{- end -}} + {{- $src = $resource.RelPermalink -}} {{- end -}} - {{- if .Minify -}} - {{- $resource = $resource | minify -}} + {{- $attrs := printf `src="%v"` $src -}} + {{- if .Crossorigin -}} + {{- $attrs = ` crossorigin="anonymous"` | add $attrs -}} {{- end -}} - {{- with .Fingerprint -}} - {{- $resource = $resource | fingerprint . -}} - {{- $integrity = $resource.Data.Integrity -}} + {{- with $integrity -}} + {{- $attrs = printf ` integrity="%v"` . | add $attrs -}} {{- end -}} - {{- $src = $resource.RelPermalink -}} + {{- if .Async -}} + {{- $attrs = " async" | add $attrs -}} + {{- end -}} + {{- if .Defer -}} + {{- $attrs = " defer" | add $attrs -}} + {{- end -}} + {{- with .Attr -}} + {{- $attrs = add " " . | add $attrs -}} + {{- end -}} + <script type="text/javascript" {{ $attrs | safeHTMLAttr }}></script> {{- end -}} - <script type="text/javascript" src="{{ $src }}"{{ if .Crossorigin }} crossorigin="anonymous"{{ end }}{{ with $integrity }} integrity="{{ . }}"{{ end }}{{ if .Async }} async{{ end }}{{ if .Defer }} defer{{ end }}{{ with .Attr }} {{ . | safeHTMLAttr }}{{ end }}></script> {{- end -}} diff --git a/layouts/partials/plugin/social.html b/layouts/partials/plugin/social.html index e6d20054..67a27b7d 100644 --- a/layouts/partials/plugin/social.html +++ b/layouts/partials/plugin/social.html @@ -8,4 +8,4 @@ {{- end -}} {{- $destination = printf (string $template) .Id -}} {{- end -}} -{{- dict "Destination" $destination "Rel" "me" | merge . | partial "plugin/link.html" -}} +{{- dict "Destination" $destination "Rel" "me" | merge . | partial "plugin/a.html" -}} diff --git a/layouts/partials/plugin/style.html b/layouts/partials/plugin/style.html index 9c9c9895..c6e42a02 100644 --- a/layouts/partials/plugin/style.html +++ b/layouts/partials/plugin/style.html @@ -27,5 +27,20 @@ {{- end -}} {{- $href = $resource.RelPermalink -}} {{- end -}} - <link rel="stylesheet" href="{{ $href }}"{{ if .Crossorigin }} crossorigin="anonymous"{{ end }}{{ with $integrity }} integrity="{{ . }}"{{ end }}{{ with .Attr }} {{ . | safeHTMLAttr }}{{ 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 -}} + <link rel="preload" {{ $attrs | safeHTMLAttr }} as="style" onload="this.onload=null;this.rel='stylesheet'"> + <noscript></noscript><link rel="stylesheet" {{ $attrs | safeHTMLAttr }}></noscript> + {{- else -}} + <link rel="stylesheet" {{ $attrs | safeHTMLAttr }}> + {{- end -}} {{- end -}} diff --git a/layouts/posts/single.html b/layouts/posts/single.html index 56e816f2..d37ed47b 100644 --- a/layouts/posts/single.html +++ b/layouts/posts/single.html @@ -34,7 +34,7 @@ {{- $authorLink := $params.authorlink | default .Site.Author.link | default .Site.Home.RelPermalink -}} <span class="post-author"> {{- $options := dict "Class" "author" "Destination" $authorLink "Title" "Author" "Rel" "author" "Icon" (dict "Class" "fas fa-user-circle fa-fw") "Content" $author -}} - {{- partial "plugin/link.html" $options -}} + {{- partial "plugin/a.html" $options -}} </span> {{- $categories := slice -}} @@ -70,7 +70,7 @@ {{- end -}} {{- with $image -}} <div class="featured-image"> - {{- dict "Src" . "Title" $.Description "Resources" $.Resources | partial "plugin/image.html" -}} + {{- dict "Src" . "Title" $.Description "Resources" $.Resources | partial "plugin/img.html" -}} </div> {{- end -}} diff --git a/layouts/shortcodes/image.html b/layouts/shortcodes/image.html index 4bb365af..ec010f08 100644 --- a/layouts/shortcodes/image.html +++ b/layouts/shortcodes/image.html @@ -19,11 +19,11 @@ {{- with $caption -}} <figure{{ with cond $.IsNamedParams ($.Get "class") "" }} class="{{ . }}"{{ end }}> - {{- partial "plugin/image.html" $options -}} + {{- partial "plugin/img.html" $options -}} <figcaption class="image-caption"> {{- . | safeHTML -}} </figcaption> </figure> {{- else -}} - {{- partial "plugin/image.html" $options -}} + {{- partial "plugin/img.html" $options -}} {{- end -}} diff --git a/layouts/shortcodes/link.html b/layouts/shortcodes/link.html index cac09e93..ab11a495 100644 --- a/layouts/shortcodes/link.html +++ b/layouts/shortcodes/link.html @@ -12,4 +12,4 @@ {{- $options = dict "Content" (.Get 1 | default (.Get 0)) | merge $options -}} {{- $options = dict "Title" (.Get 2) | merge $options -}} {{- end -}} -{{- partial "plugin/link.html" $options -}} +{{- partial "plugin/a.html" $options -}} diff --git a/layouts/shortcodes/version.html b/layouts/shortcodes/version.html index 904be2df..d9875589 100644 --- a/layouts/shortcodes/version.html +++ b/layouts/shortcodes/version.html @@ -9,5 +9,5 @@ {{- $resource = $resource | resources.ExecuteAsTemplate $path (dict "version" $version "label" $label "color" $color) | minify -}} {{- $alt := printf "LoveIt %v | %v" $label $version -}} <a href="{{ $url }}" rel="noopener noreffer" target="_blank"> - {{- dict "Src" $resource.RelPermalink "Alt" $alt "Class" "version" | partial "plugin/image.html" -}} + {{- dict "Src" $resource.RelPermalink "Alt" $alt "Class" "version" | partial "plugin/img.html" -}} </a>
\ No newline at end of file |