-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: enhance image resolving * chore: don't process image path that begins with relative link * docs: add instruction for adding images * chore: update docs * chore: add filenames to images docs
- Loading branch information
Showing
2 changed files
with
83 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,27 @@ | ||
{{- if .Title -}} | ||
{{- $alt := .PlainText | safeHTML -}} | ||
{{- $lazyLoading := .Page.Site.Params.enableImagelazyLoading | default true -}} | ||
{{- $dest := .Destination -}} | ||
|
||
{{- $isRemote := not (urls.Parse $dest).Scheme -}} | ||
{{- $isPage := and (eq .Page.Kind "page") (not .Page.BundleType) -}} | ||
{{- $startsWithSlash := hasPrefix $dest "/" -}} | ||
{{- $startsWithRelative := hasPrefix $dest "../" -}} | ||
|
||
{{- if and $dest $isRemote -}} | ||
{{- if $startsWithSlash -}} | ||
{{/* Images under static directory */}} | ||
{{- $dest = (relURL $dest) -}} | ||
{{- else if and $isPage (not $startsWithRelative) -}} | ||
{{/* Images that are sibling to the individual page file */}} | ||
{{ $dest = (printf "../%s" $dest) }} | ||
{{- end -}} | ||
{{- end -}} | ||
|
||
{{- with .Title -}} | ||
<figure> | ||
<img src="{{ .Destination | safeURL }}" title="{{ .Title }}" alt="{{ .PlainText | safeHTML }}" loading="lazy" /> | ||
<figcaption>{{ .Title }}</figcaption> | ||
<img src="{{ $dest | safeURL }}" title="{{ . }}" alt="{{ $alt }}" {{ if $lazyLoading }}loading="lazy"{{ end }} /> | ||
<figcaption>{{ . }}</figcaption> | ||
</figure> | ||
{{- else -}} | ||
<img src="{{ .Destination | safeURL }}" alt="{{ .PlainText | safeHTML }}" loading="lazy" /> | ||
<img src="{{ $dest | safeURL }}" alt="{{ $alt }}" {{ if $lazyLoading }}loading="lazy"{{ end }} /> | ||
{{- end -}} |