diff --git a/layouts/_default/_markup/render-image.html b/layouts/_default/_markup/render-image.html
index 16a91f9..5c00c4c 100644
--- a/layouts/_default/_markup/render-image.html
+++ b/layouts/_default/_markup/render-image.html
@@ -1,27 +1,43 @@
{{- $alt := .PlainText | safeHTML -}}
{{- $lazyLoading := .Page.Site.Params.enableImageLazyLoading | default true -}}
{{- $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) -}}
{{- $startsWithSlash := hasPrefix $dest "/" -}}
{{- $startsWithRelative := hasPrefix $dest "../" -}}
{{- if and $dest $isLocal -}}
{{- if $startsWithSlash -}}
- {{/* Images under static directory */}}
- {{- $dest = (relURL (strings.TrimPrefix "/" $dest)) -}}
+ {{- with or (.PageInner.Resources.Get $url.Path) (resources.Get $url.Path) -}}
+ {{/* 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) -}}
{{/* Images that are sibling to the individual page file */}}
{{ $dest = (printf "../%s" $dest) }}
{{- 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 -}}
-
+
{{ . }}
{{- else -}}
-
+
{{- end -}}
diff --git a/layouts/partials/head.html b/layouts/partials/head.html
index d8f2152..8e0a9e6 100644
--- a/layouts/partials/head.html
+++ b/layouts/partials/head.html
@@ -76,12 +76,17 @@
{{ $noop := .WordCount -}}
{{ if .Page.Store.Get "hasMath" -}}
- {{ $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 .Err -}}
{{ errorf "Could not retrieve KaTeX css file from %s. Reason: %s." $katexCssUrl . -}}
{{ 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 -}}
{{ end -}}
{{ end -}}