-
-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
86dd657
commit 7d562c7
Showing
4 changed files
with
92 additions
and
145 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,4 @@ | ||
{{ $url := urls.Parse .Destination }} | ||
{{ $altText := .Text }} | ||
{{ $caption := .Title }} | ||
{{ $lazyLoad := $.Page.Site.Params.enableImageLazyLoading | default true }} | ||
{{ $webp := $.Page.Site.Params.enableWebp | default true }} | ||
{{ if findRE "^https?" $url.Scheme }} | ||
<figure> | ||
<img | ||
class="mx-auto my-0 rounded-md" | ||
src="{{ $url.String }}" | ||
alt="{{ $altText }}" | ||
{{ if $lazyLoad }} | ||
loading="lazy" | ||
{{ end }} | ||
/> | ||
{{ with $caption }}<figcaption class="text-center">{{ . | markdownify }}</figcaption>{{ end }} | ||
</figure> | ||
{{ else }} | ||
{{ $resource := "" }} | ||
{{ if $.Page.Resources.GetMatch ($url.String) }} | ||
{{ $resource = $.Page.Resources.GetMatch ($url.String) }} | ||
{{ else if resources.GetMatch ($url.String) }} | ||
{{ $resource = resources.Get ($url.String) }} | ||
{{ end }} | ||
{{ with $resource }} | ||
<figure> | ||
<picture> | ||
{{ if (and (ne .MediaType.SubType "svg") $webp) }} | ||
<source | ||
{{ if lt .Width 660 }} | ||
{{ with .Resize (printf "%dx%d webp" .Width .Height) }} | ||
src="{{ .RelPermalink }}" | ||
{{ end }} | ||
{{ else }} | ||
srcset=" | ||
{{- (.Resize "330x webp").RelPermalink }} 330w, | ||
{{- (.Resize "660x webp").RelPermalink }} 660w, | ||
{{- (.Resize "1024x webp").RelPermalink }} 1024w, | ||
{{- (.Resize "1320x webp").RelPermalink }} 2x" | ||
src="{{ (.Resize "660x webp").RelPermalink }}" | ||
{{ end }} | ||
type="image/webp" | ||
/> | ||
{{ end }} | ||
<img | ||
class="mx-auto my-0 rounded-md" | ||
{{ if eq .MediaType.SubType "svg" }} | ||
src="{{ .RelPermalink }}" | ||
{{ else }} | ||
width="{{ .Width }}" | ||
height="{{ .Height }}" | ||
decoding="async" | ||
{{ if lt .Width 660 }} | ||
src="{{ .RelPermalink }}" | ||
{{ else }} | ||
srcset=" | ||
{{- (.Resize "330x").RelPermalink }} 330w, | ||
{{- (.Resize "660x").RelPermalink }} 660w, | ||
{{- (.Resize "1024x").RelPermalink }} 1024w, | ||
{{- (.Resize "1320x").RelPermalink }} 2x" | ||
src="{{ (.Resize "660x").RelPermalink }}" | ||
{{ end }} | ||
{{ end }} | ||
alt="{{ $altText }}" | ||
{{ if $lazyLoad }} | ||
loading="lazy" | ||
{{ end }} | ||
/> | ||
</picture> | ||
{{ with $caption }}<figcaption class="text-center">{{ . | markdownify }}</figcaption>{{ end }} | ||
</figure> | ||
{{ else }} | ||
<figure> | ||
<img | ||
class="mx-auto my-0 rounded-md" | ||
src="{{ $url.String }}" | ||
alt="{{ $altText }}" | ||
{{ if $lazyLoad }} | ||
loading="lazy" | ||
{{ end }} | ||
/> | ||
{{ with $caption }}<figcaption class="text-center">{{ . | markdownify }}</figcaption>{{ end }} | ||
</figure> | ||
{{ end }} | ||
{{ end }} | ||
<figure> | ||
{{ partial "picture.html" (dict "context" . "src" .Destination "alt" .Text) }} | ||
{{ with .Title }}<figcaption class="text-center">{{ . | markdownify }}</figcaption>{{ end }} | ||
</figure> |
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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
{{ $url := urls.Parse .src }} | ||
{{ $altText := .alt }} | ||
{{ $class := .class | default "mx-auto my-0 rounded-md" }} | ||
|
||
{{ $lazyLoad := .context.Page.Site.Params.enableImageLazyLoading | default true }} | ||
{{ $webp := .context.Page.Site.Params.enableWebp | default true }} | ||
|
||
{{ if findRE "^https?" $url.Scheme }} | ||
<img | ||
class="{{ $class }}" | ||
src="{{ $url.String }}" | ||
alt="{{ $altText }}" | ||
{{ if $lazyLoad }} | ||
loading="lazy" | ||
{{ end }} | ||
/> | ||
{{ else }} | ||
{{ $resource := "" }} | ||
{{ if .context.Page.Resources.GetMatch ($url.String) }} | ||
{{ $resource = .context.Page.Resources.GetMatch ($url.String) }} | ||
{{ else if resources.GetMatch ($url.String) }} | ||
{{ $resource = resources.Get ($url.String) }} | ||
{{ end }} | ||
{{ with $resource }} | ||
<picture> | ||
{{ if (and (ne .MediaType.SubType "svg") $webp) }} | ||
<source | ||
{{ if lt .Width 660 }} | ||
{{ with .Resize (printf "%dx%d webp" .Width .Height) }} | ||
src="{{ .RelPermalink }}" | ||
{{ end }} | ||
{{ else }} | ||
srcset=" | ||
{{- (.Resize "330x webp").RelPermalink }} 330w, | ||
{{- (.Resize "660x webp").RelPermalink }} 660w, | ||
{{- (.Resize "1024x webp").RelPermalink }} 1024w, | ||
{{- (.Resize "1320x webp").RelPermalink }} 2x" | ||
src="{{ (.Resize "660x webp").RelPermalink }}" | ||
{{ end }} | ||
type="image/webp" | ||
/> | ||
{{ end }} | ||
<img | ||
class="mx-auto my-0 rounded-md" | ||
{{ if eq .MediaType.SubType "svg" }} | ||
src="{{ .RelPermalink }}" | ||
{{ else }} | ||
width="{{ .Width }}" | ||
height="{{ .Height }}" | ||
decoding="async" | ||
{{ if lt .Width 660 }} | ||
src="{{ .RelPermalink }}" | ||
{{ else }} | ||
srcset=" | ||
{{- (.Resize "330x").RelPermalink }} 330w, | ||
{{- (.Resize "660x").RelPermalink }} 660w, | ||
{{- (.Resize "1024x").RelPermalink }} 1024w, | ||
{{- (.Resize "1320x").RelPermalink }} 2x" | ||
src="{{ (.Resize "660x").RelPermalink }}" | ||
{{ end }} | ||
{{ end }} | ||
alt="{{ $altText }}" | ||
{{ if $lazyLoad }} | ||
loading="lazy" | ||
{{ end }} | ||
/> | ||
</picture> | ||
{{ else }} | ||
<img | ||
class="mx-auto my-0 rounded-md" | ||
src="{{ $url.String }}" | ||
alt="{{ $altText }}" | ||
{{ if $lazyLoad }} | ||
loading="lazy" | ||
{{ end }} | ||
/> | ||
{{ end }} | ||
{{ end }} | ||
|
||
|
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