mirror of
https://github.com/imfing/hextra.git
synced 2025-05-13 17:56:26 -04:00
Merge remote-tracking branch 'origin/main' into refactor-width-utility
This commit is contained in:
commit
13d7680886
@ -1,27 +1,43 @@
|
|||||||
{{- $alt := .PlainText | safeHTML -}}
|
{{- $alt := .PlainText | safeHTML -}}
|
||||||
{{- $lazyLoading := .Page.Site.Params.enableImageLazyLoading | default true -}}
|
{{- $lazyLoading := .Page.Site.Params.enableImageLazyLoading | default true -}}
|
||||||
{{- $dest := .Destination -}}
|
{{- $dest := .Destination -}}
|
||||||
|
{{- $url := urls.Parse $dest -}}
|
||||||
|
|
||||||
{{- $isLocal := not (urls.Parse $dest).Scheme -}}
|
{{- $isLocal := not $url.Scheme -}}
|
||||||
{{- $isPage := and (eq .Page.Kind "page") (not .Page.BundleType) -}}
|
{{- $isPage := and (eq .Page.Kind "page") (not .Page.BundleType) -}}
|
||||||
{{- $startsWithSlash := hasPrefix $dest "/" -}}
|
{{- $startsWithSlash := hasPrefix $dest "/" -}}
|
||||||
{{- $startsWithRelative := hasPrefix $dest "../" -}}
|
{{- $startsWithRelative := hasPrefix $dest "../" -}}
|
||||||
|
|
||||||
{{- if and $dest $isLocal -}}
|
{{- if and $dest $isLocal -}}
|
||||||
{{- if $startsWithSlash -}}
|
{{- if $startsWithSlash -}}
|
||||||
{{/* Images under static directory */}}
|
{{- with or (.PageInner.Resources.Get $url.Path) (resources.Get $url.Path) -}}
|
||||||
{{- $dest = (relURL (strings.TrimPrefix "/" $dest)) -}}
|
{{/* Images under assets directory */}}
|
||||||
|
{{- $query := cond $url.RawQuery (printf "?%s" $url.RawQuery) "" -}}
|
||||||
|
{{- $fragment := cond $url.Fragment (printf "?%s" $url.Fragment) "" -}}
|
||||||
|
{{- $dest = printf "%s%s%s" .RelPermalink $query $fragment -}}
|
||||||
|
{{- else -}}
|
||||||
|
{{/* Images under static directory */}}
|
||||||
|
{{- $dest = (relURL (strings.TrimPrefix "/" $dest)) -}}
|
||||||
|
{{- end -}}
|
||||||
{{- else if and $isPage (not $startsWithRelative) -}}
|
{{- else if and $isPage (not $startsWithRelative) -}}
|
||||||
{{/* Images that are sibling to the individual page file */}}
|
{{/* Images that are sibling to the individual page file */}}
|
||||||
{{ $dest = (printf "../%s" $dest) }}
|
{{ $dest = (printf "../%s" $dest) }}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
|
{{- $attributes := "" -}}
|
||||||
|
{{- range $key, $value := .Attributes -}}
|
||||||
|
{{- if $value -}}
|
||||||
|
{{- $pair := printf "%s=%q" $key ($value | transform.HTMLEscape) -}}
|
||||||
|
{{- $attributes = printf "%s %s" $attributes $pair -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
{{- with .Title -}}
|
{{- with .Title -}}
|
||||||
<figure>
|
<figure>
|
||||||
<img src="{{ $dest | safeURL }}" title="{{ . }}" alt="{{ $alt }}" {{ if $lazyLoading }}loading="lazy"{{ end }} />
|
<img src="{{ $dest | safeURL }}" title="{{ . }}" alt="{{ $alt }}" {{ $attributes | safeHTMLAttr }} {{ if $lazyLoading }}loading="lazy"{{ end }} />
|
||||||
<figcaption>{{ . }}</figcaption>
|
<figcaption>{{ . }}</figcaption>
|
||||||
</figure>
|
</figure>
|
||||||
{{- else -}}
|
{{- else -}}
|
||||||
<img src="{{ $dest | safeURL }}" alt="{{ $alt }}" {{ if $lazyLoading }}loading="lazy"{{ end }} />
|
<img src="{{ $dest | safeURL }}" alt="{{ $alt }}" {{ $attributes | safeHTMLAttr }} {{ if $lazyLoading }}loading="lazy"{{ end }} />
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
@ -76,12 +76,17 @@
|
|||||||
{{ $noop := .WordCount -}}
|
{{ $noop := .WordCount -}}
|
||||||
{{ if .Page.Store.Get "hasMath" -}}
|
{{ if .Page.Store.Get "hasMath" -}}
|
||||||
<!-- TODO: make url configurable -->
|
<!-- TODO: make url configurable -->
|
||||||
{{ $katexCssUrl := printf "https://cdn.jsdelivr.net/npm/katex@latest/dist/katex%s.css" (cond hugo.IsProduction ".min" "") -}}
|
{{ $katexBaseUrl := "https://cdn.jsdelivr.net/npm/katex@latest/dist" }}
|
||||||
|
{{ $katexCssUrl := printf "%s/katex%s.css" $katexBaseUrl (cond hugo.IsProduction ".min" "") -}}
|
||||||
|
{{ $katexFontPattern := "url(fonts/" }}
|
||||||
|
{{ $katexFontSubstituted := printf "url(%s/fonts/" $katexBaseUrl }}
|
||||||
|
|
||||||
{{ with try (resources.GetRemote $katexCssUrl) -}}
|
{{ with try (resources.GetRemote $katexCssUrl) -}}
|
||||||
{{ with .Err -}}
|
{{ with .Err -}}
|
||||||
{{ errorf "Could not retrieve KaTeX css file from %s. Reason: %s." $katexCssUrl . -}}
|
{{ errorf "Could not retrieve KaTeX css file from %s. Reason: %s." $katexCssUrl . -}}
|
||||||
{{ else with.Value -}}
|
{{ else with.Value -}}
|
||||||
{{ with resources.Copy (printf "css/katex%s.css" (cond hugo.IsProduction ".min" "")) . -}}
|
{{ $katexCssContent := strings.Replace .Content $katexFontPattern $katexFontSubstituted }}
|
||||||
|
{{ with resources.FromString (printf "css/katex%s.css" (cond hugo.IsProduction ".min" "")) $katexCssContent -}}
|
||||||
<link rel="stylesheet" href="{{- .RelPermalink -}}" integrity="{{- . | fingerprint -}}" crossorigin="anonymous" />
|
<link rel="stylesheet" href="{{- .RelPermalink -}}" integrity="{{- . | fingerprint -}}" crossorigin="anonymous" />
|
||||||
{{ end -}}
|
{{ end -}}
|
||||||
{{ end -}}
|
{{ end -}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user