feat: preload some stylesheets and rename some plugin partials

This commit is contained in:
Dillon 2022-05-14 02:28:35 +08:00
parent f4c7857f4f
commit a0c340316a
No known key found for this signature in database
GPG key ID: 0EF4AE57FB98F108
15 changed files with 76 additions and 45 deletions

View file

@ -1,10 +1,10 @@
{{- if .Title -}} {{- if .Title -}}
<figure> <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"> <figcaption class="image-caption">
{{- .Title | safeHTML -}} {{- .Title | safeHTML -}}
</figcaption> </figcaption>
</figure> </figure>
{{- else -}} {{- 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 -}} {{- end -}}

View file

@ -3,4 +3,4 @@
{{- $destination = .RelPermalink -}} {{- $destination = .RelPermalink -}}
{{- end -}} {{- end -}}
{{- $options := dict "Destination" $destination "Title" .Title "Content" .Text -}} {{- $options := dict "Destination" $destination "Title" .Title "Content" .Text -}}
{{- partial "plugin/link.html" $options -}} {{- partial "plugin/a.html" $options -}}

View file

@ -12,7 +12,7 @@
{{- with $image -}} {{- with $image -}}
<div class="featured-image-preview"> <div class="featured-image-preview">
<a href="{{ $.RelPermalink }}"> <a href="{{ $.RelPermalink }}">
{{- dict "Src" . "Title" $.Description "Resources" $.Resources | partial "plugin/image.html" -}} {{- dict "Src" . "Title" $.Description "Resources" $.Resources | partial "plugin/img.html" -}}
</a> </a>
</div> </div>
{{- end -}} {{- end -}}
@ -28,7 +28,7 @@
{{- $authorLink := $params.authorlink | default .Site.Author.link | default .Site.Home.RelPermalink -}} {{- $authorLink := $params.authorlink | default .Site.Author.link | default .Site.Home.RelPermalink -}}
<span class="post-author"> <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 -}} {{- $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> </span>
{{- with .Site.Params.dateFormat | default "2006-01-02" | .PublishDate.Format -}} {{- with .Site.Params.dateFormat | default "2006-01-02" | .PublishDate.Format -}}

View file

@ -30,17 +30,17 @@
{{- end -}} {{- end -}}
{{- /* style.min.css */ -}} {{- /* style.min.css */ -}}
{{- $style := dict "Source" "css/style.scss" "Fingerprint" $fingerprint -}} {{- $options := dict "Source" "css/style.scss" "Fingerprint" $fingerprint -}}
{{- $options := dict "targetPath" "css/style.min.css" "enableSourceMap" true -}} {{- $toCSS := dict "targetPath" "css/style.min.css" "enableSourceMap" true -}}
{{- $style = dict "Context" . "ToCSS" $options | merge $style -}} {{- $options = dict "Context" . "ToCSS" $toCSS | merge $options -}}
{{- partial "plugin/style.html" $style -}} {{- partial "plugin/style.html" $options -}}
{{- /* Font Awesome */ -}} {{- /* Font Awesome */ -}}
{{- $source := $cdn.fontawesomeFreeCSS | default "lib/fontawesome-free/all.min.css" -}} {{- $source := $cdn.fontawesomeFreeCSS | default "lib/fontawesome-free/all.min.css" -}}
{{- $style := dict "Source" $source "Fingerprint" $fingerprint -}} {{- $options := dict "Source" $source "Fingerprint" $fingerprint "Preload" true -}}
{{- partial "plugin/style.html" $style -}} {{- partial "plugin/style.html" $options -}}
{{- /* Animate.css */ -}} {{- /* Animate.css */ -}}
{{- $source := $cdn.animateCSS | default "lib/animate/animate.min.css" -}} {{- $source := $cdn.animateCSS | default "lib/animate/animate.min.css" -}}
{{- $style := dict "Source" $source "Fingerprint" $fingerprint -}} {{- $options := dict "Source" $source "Fingerprint" $fingerprint "Preload" true -}}
{{- partial "plugin/style.html" $style -}} {{- partial "plugin/style.html" $options -}}

View file

@ -5,7 +5,7 @@
<a href="{{ .Site.Home.RelPermalink }}" title="{{ .Site.Title }}"> <a href="{{ .Site.Home.RelPermalink }}" title="{{ .Site.Title }}">
{{- with .Site.Params.header.title -}} {{- with .Site.Params.header.title -}}
{{- with .logo -}} {{- with .logo -}}
{{- dict "Src" . "Class" "logo" | partial "plugin/image.html" -}} {{- dict "Src" . "Class" "logo" | partial "plugin/img.html" -}}
{{- end -}} {{- end -}}
{{- with .pre -}} {{- with .pre -}}
<span class="header-title-pre">{{ . | safeHTML }}</span> <span class="header-title-pre">{{ . | safeHTML }}</span>
@ -92,7 +92,7 @@
<a href="{{ .Site.Home.RelPermalink }}" title="{{ .Site.Title }}"> <a href="{{ .Site.Home.RelPermalink }}" title="{{ .Site.Title }}">
{{- with .Site.Params.header.title -}} {{- with .Site.Params.header.title -}}
{{- with .logo -}} {{- with .logo -}}
{{- dict "Src" . "Class" "logo" | partial "plugin/image.html" -}} {{- dict "Src" . "Class" "logo" | partial "plugin/img.html" -}}
{{- end -}} {{- end -}}
{{- with .pre -}} {{- with .pre -}}
<span class="header-title-pre">{{ . | safeHTML }}</span> <span class="header-title-pre">{{ . | safeHTML }}</span>

View file

@ -13,10 +13,10 @@
{{- $url = .RelPermalink -}} {{- $url = .RelPermalink -}}
{{- end -}} {{- end -}}
<a href="{{ $url }}"{{ with .Title | default .Name }} title="{{ . }}"{{ end }}{{ if (urls.Parse $url).Host }} rel="noopener noreffer" target="_blank"{{ 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> </a>
{{- else -}} {{- else -}}
{{- dict "Src" $avatar | partial "plugin/image.html" -}} {{- dict "Src" $avatar | partial "plugin/img.html" -}}
{{- end -}} {{- end -}}
</div> </div>
{{- end -}} {{- end -}}

View file

@ -1,8 +1,7 @@
{{- if .Content -}} {{- with .Content -}}
<script type="text/javascript"> <script type="text/javascript">{{ . | safeJS }}</script>
{{- .Content | safeJS -}} {{- else -}}
</script> {{- if strings.HasPrefix .Source "<script" -}}
{{- else if strings.HasPrefix .Source "<script" -}}
{{- safeHTML .Source -}} {{- safeHTML .Source -}}
{{- else -}} {{- else -}}
{{- $src := .Source -}} {{- $src := .Source -}}
@ -21,5 +20,22 @@
{{- end -}} {{- end -}}
{{- $src = $resource.RelPermalink -}} {{- $src = $resource.RelPermalink -}}
{{- end -}} {{- 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> {{- $attrs := printf `src="%v"` $src -}}
{{- if .Crossorigin -}}
{{- $attrs = ` crossorigin="anonymous"` | add $attrs -}}
{{- end -}}
{{- with $integrity -}}
{{- $attrs = printf ` integrity="%v"` . | add $attrs -}}
{{- end -}}
{{- 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 -}}
{{- end -}} {{- end -}}

View file

@ -8,4 +8,4 @@
{{- end -}} {{- end -}}
{{- $destination = printf (string $template) .Id -}} {{- $destination = printf (string $template) .Id -}}
{{- end -}} {{- end -}}
{{- dict "Destination" $destination "Rel" "me" | merge . | partial "plugin/link.html" -}} {{- dict "Destination" $destination "Rel" "me" | merge . | partial "plugin/a.html" -}}

View file

@ -27,5 +27,20 @@
{{- end -}} {{- end -}}
{{- $href = $resource.RelPermalink -}} {{- $href = $resource.RelPermalink -}}
{{- end -}} {{- 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 -}} {{- end -}}

View file

@ -34,7 +34,7 @@
{{- $authorLink := $params.authorlink | default .Site.Author.link | default .Site.Home.RelPermalink -}} {{- $authorLink := $params.authorlink | default .Site.Author.link | default .Site.Home.RelPermalink -}}
<span class="post-author"> <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 -}} {{- $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> </span>
{{- $categories := slice -}} {{- $categories := slice -}}
@ -70,7 +70,7 @@
{{- end -}} {{- end -}}
{{- with $image -}} {{- with $image -}}
<div class="featured-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> </div>
{{- end -}} {{- end -}}

View file

@ -19,11 +19,11 @@
{{- with $caption -}} {{- with $caption -}}
<figure{{ with cond $.IsNamedParams ($.Get "class") "" }} class="{{ . }}"{{ end }}> <figure{{ with cond $.IsNamedParams ($.Get "class") "" }} class="{{ . }}"{{ end }}>
{{- partial "plugin/image.html" $options -}} {{- partial "plugin/img.html" $options -}}
<figcaption class="image-caption"> <figcaption class="image-caption">
{{- . | safeHTML -}} {{- . | safeHTML -}}
</figcaption> </figcaption>
</figure> </figure>
{{- else -}} {{- else -}}
{{- partial "plugin/image.html" $options -}} {{- partial "plugin/img.html" $options -}}
{{- end -}} {{- end -}}

View file

@ -12,4 +12,4 @@
{{- $options = dict "Content" (.Get 1 | default (.Get 0)) | merge $options -}} {{- $options = dict "Content" (.Get 1 | default (.Get 0)) | merge $options -}}
{{- $options = dict "Title" (.Get 2) | merge $options -}} {{- $options = dict "Title" (.Get 2) | merge $options -}}
{{- end -}} {{- end -}}
{{- partial "plugin/link.html" $options -}} {{- partial "plugin/a.html" $options -}}

View file

@ -9,5 +9,5 @@
{{- $resource = $resource | resources.ExecuteAsTemplate $path (dict "version" $version "label" $label "color" $color) | minify -}} {{- $resource = $resource | resources.ExecuteAsTemplate $path (dict "version" $version "label" $label "color" $color) | minify -}}
{{- $alt := printf "LoveIt %v | %v" $label $version -}} {{- $alt := printf "LoveIt %v | %v" $label $version -}}
<a href="{{ $url }}" rel="noopener noreffer" target="_blank"> <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> </a>