Skip to content

Commit 13d7680

Browse files
committed
Merge remote-tracking branch 'origin/main' into refactor-width-utility
2 parents 892101b + d08b077 commit 13d7680

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed
Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,43 @@
11
{{- $alt := .PlainText | safeHTML -}}
22
{{- $lazyLoading := .Page.Site.Params.enableImageLazyLoading | default true -}}
33
{{- $dest := .Destination -}}
4+
{{- $url := urls.Parse $dest -}}
45

5-
{{- $isLocal := not (urls.Parse $dest).Scheme -}}
6+
{{- $isLocal := not $url.Scheme -}}
67
{{- $isPage := and (eq .Page.Kind "page") (not .Page.BundleType) -}}
78
{{- $startsWithSlash := hasPrefix $dest "/" -}}
89
{{- $startsWithRelative := hasPrefix $dest "../" -}}
910

1011
{{- if and $dest $isLocal -}}
1112
{{- if $startsWithSlash -}}
12-
{{/* Images under static directory */}}
13-
{{- $dest = (relURL (strings.TrimPrefix "/" $dest)) -}}
13+
{{- with or (.PageInner.Resources.Get $url.Path) (resources.Get $url.Path) -}}
14+
{{/* Images under assets directory */}}
15+
{{- $query := cond $url.RawQuery (printf "?%s" $url.RawQuery) "" -}}
16+
{{- $fragment := cond $url.Fragment (printf "?%s" $url.Fragment) "" -}}
17+
{{- $dest = printf "%s%s%s" .RelPermalink $query $fragment -}}
18+
{{- else -}}
19+
{{/* Images under static directory */}}
20+
{{- $dest = (relURL (strings.TrimPrefix "/" $dest)) -}}
21+
{{- end -}}
1422
{{- else if and $isPage (not $startsWithRelative) -}}
1523
{{/* Images that are sibling to the individual page file */}}
1624
{{ $dest = (printf "../%s" $dest) }}
1725
{{- end -}}
1826
{{- end -}}
1927

28+
{{- $attributes := "" -}}
29+
{{- range $key, $value := .Attributes -}}
30+
{{- if $value -}}
31+
{{- $pair := printf "%s=%q" $key ($value | transform.HTMLEscape) -}}
32+
{{- $attributes = printf "%s %s" $attributes $pair -}}
33+
{{- end -}}
34+
{{- end -}}
35+
2036
{{- with .Title -}}
2137
<figure>
22-
<img src="{{ $dest | safeURL }}" title="{{ . }}" alt="{{ $alt }}" {{ if $lazyLoading }}loading="lazy"{{ end }} />
38+
<img src="{{ $dest | safeURL }}" title="{{ . }}" alt="{{ $alt }}" {{ $attributes | safeHTMLAttr }} {{ if $lazyLoading }}loading="lazy"{{ end }} />
2339
<figcaption>{{ . }}</figcaption>
2440
</figure>
2541
{{- else -}}
26-
<img src="{{ $dest | safeURL }}" alt="{{ $alt }}" {{ if $lazyLoading }}loading="lazy"{{ end }} />
42+
<img src="{{ $dest | safeURL }}" alt="{{ $alt }}" {{ $attributes | safeHTMLAttr }} {{ if $lazyLoading }}loading="lazy"{{ end }} />
2743
{{- end -}}

layouts/partials/head.html

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,17 @@
7676
{{ $noop := .WordCount -}}
7777
{{ if .Page.Store.Get "hasMath" -}}
7878
<!-- TODO: make url configurable -->
79-
{{ $katexCssUrl := printf "https://cdn.jsdelivr.net/npm/katex@latest/dist/katex%s.css" (cond hugo.IsProduction ".min" "") -}}
79+
{{ $katexBaseUrl := "https://cdn.jsdelivr.net/npm/katex@latest/dist" }}
80+
{{ $katexCssUrl := printf "%s/katex%s.css" $katexBaseUrl (cond hugo.IsProduction ".min" "") -}}
81+
{{ $katexFontPattern := "url(fonts/" }}
82+
{{ $katexFontSubstituted := printf "url(%s/fonts/" $katexBaseUrl }}
83+
8084
{{ with try (resources.GetRemote $katexCssUrl) -}}
8185
{{ with .Err -}}
8286
{{ errorf "Could not retrieve KaTeX css file from %s. Reason: %s." $katexCssUrl . -}}
8387
{{ else with.Value -}}
84-
{{ with resources.Copy (printf "css/katex%s.css" (cond hugo.IsProduction ".min" "")) . -}}
88+
{{ $katexCssContent := strings.Replace .Content $katexFontPattern $katexFontSubstituted }}
89+
{{ with resources.FromString (printf "css/katex%s.css" (cond hugo.IsProduction ".min" "")) $katexCssContent -}}
8590
<link rel="stylesheet" href="{{- .RelPermalink -}}" integrity="{{- . | fingerprint -}}" crossorigin="anonymous" />
8691
{{ end -}}
8792
{{ end -}}

0 commit comments

Comments
 (0)