-
-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: get remote resource logic * refactor: image optimisation pipeline * refactor: profile * refactor: adjust params names * chore: add more comments * refactor: restore light gallary * refactor: optimise render-image and image shortcod * feat: optimise author * fix: home alt text * fix: home alt text * fix: alt text * fix: home-profile sizing * chore: add documentation * chore: add correct width and height to featuredImage * chore: sizes auto * fix: sizes 800px for front page images * feat: optimise sizes option * refactor: read options from config * feat: support optimise and cachRemote override in image shortcode * feat(docs): add image shortcode docs * feat(docs): update params config * fix: author avatar margin right
- Loading branch information
1 parent
14aa93b
commit 357d445
Showing
14 changed files
with
152 additions
and
119 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
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
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,13 +1,14 @@ | ||
{{- $lightgallery := .Page.Params.lightgallery | default site.Params.Page.lightgallery | default false -}} | ||
{{- if .Title -}} | ||
<figure> | ||
{{- dict "Src" .Destination "Title" .Text "Caption" .Title "Linked" $lightgallery "Resources" .Page.Resources "Optim" true "Remote" true | partial "plugin/image.html" -}} | ||
{{- $optim := slice | ||
(dict "Process" "resize 800x webp q75" "descriptor" "800w") | ||
(dict "Process" "resize 1200x webp q75" "descriptor" "1200w") | ||
(dict "Process" "resize 1600x webp q75" "descriptor" "1600w") | ||
-}} | ||
<figure> | ||
{{- dict "Src" .Destination "Title" .Text "Caption" .Title "Linked" $lightgallery "Resources" .Page.Resources "OptimConfig" $optim | partial "plugin/image.html" -}} | ||
{{- if .Title -}} | ||
<figcaption class="image-caption"> | ||
{{- .Title | safeHTML -}} | ||
</figcaption> | ||
</figure> | ||
{{- else -}} | ||
<figure> | ||
{{- dict "Src" .Destination "Title" .Text "Linked" $lightgallery "Resources" .Page.Resources "Optim" true "Remote" true | partial "plugin/image.html" -}} | ||
</figure> | ||
{{- end -}} | ||
{{- 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 was deleted.
Oops, something went wrong.
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
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,51 +1,70 @@ | ||
{{- /* lightgallery.js */ -}} | ||
{{- $default := dict "RelPermalink" .Src -}} | ||
{{- $remote := .Remote | default false -}} | ||
{{- $optimize := .Optim | default false -}} | ||
{{- $small := $default -}} | ||
{{- $large := $default -}} | ||
{{- $height := "" -}} | ||
{{- $width := "" -}} | ||
{{- $optimized := false -}} | ||
|
||
{{- with dict "Path" .Src "Resources" .Resources "Remote" $remote | partial "function/getImage.html" -}} | ||
{{- $output := dict "Optim" $optimize "Image" . | partial "function/imageHandler.html" -}} | ||
{{- $small = $output.S -}} | ||
{{- $default = $output.M -}} | ||
{{- $large = $output.L -}} | ||
{{- $optimized = $output.Optimized -}} | ||
{{- $height = $default.Height -}} | ||
{{- $width = $default.Width -}} | ||
{{- end -}} | ||
{{/* | ||
The image plugin is a partial that handles image resources. | ||
|
||
Parameters: | ||
- Src: The path to the image. | ||
It can be a page resource (inside a page bundle) https://gohugo.io/methods/page/resources/ | ||
or a global resource (inside the assets directory) https://gohugo.io/functions/resources/get/ | ||
or a link to a remote resource, which can be cached if the site parameter is set https://gohugo.io/functions/resources/getremote/ | ||
- Resources: If the image is a page resource, this parameter is required. It is the .Resources of the page. | ||
- OptimConfig: optimisation parameter, defined like | ||
{{- $optim := slice | ||
(dict "Process" "resize 800x Center webp q75" "descriptor" "800w") | ||
(dict "Process" "resize 1200x Center webp q75" "descriptor" "1200w") | ||
(dict "Process" "resize 1600x Center webp q75" "descriptor" "1600w") | ||
-}} | ||
See https://gohugo.io/content-management/image-processing/ for more information. | ||
- Alt: alt text for the image. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#alt | ||
- Height: The intrinsic height of the image, in pixels. Must be an integer without a unit. | ||
We try to generate this value automatically if possible. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#height | ||
- Width: The intrinsic width of the image, in pixels. Must be an integer without a unit. | ||
We try to generate this value automatically if possible. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#width | ||
- Loading: Indicates how the browser should load the image: eager or lazy. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#loading | ||
- Optimise: Override the site parameter to optimise the image. | ||
- CacheRemote: Override the site parameter to cache remote images. | ||
*/}} | ||
|
||
{{- $resource := (.Resources.Get .Src) | default (resources.Get .Src) | default nil -}} | ||
|
||
{{- $cacheRemote := .CacheRemote | default site.Params.image.cacheRemote | default false -}} | ||
{{- $optimise := .Optimise | default site.Params.image.optimise | default false -}} | ||
|
||
{{- $alt := .Alt | default .Title | default .Src -}} | ||
{{- $loading := .Loading | default "lazy" -}} | ||
{{- $isUrlRemote := urls.Parse .Src | partial "function/isUrlRemote.html" -}} | ||
|
||
{{- with .Height -}} | ||
{{- $height = . -}} | ||
{{- if not $resource | and $isUrlRemote | and $cacheRemote -}} | ||
{{- with $remoteResource := resources.GetRemote .Src -}} | ||
{{- with .Err -}} | ||
{{- warnf "%s" . -}} | ||
{{ else }} | ||
{{- if $remoteResource.ResourceType | eq "image" -}} | ||
{{- $resource = $remoteResource -}} | ||
{{- end -}} | ||
{{- end -}} | ||
{{- end -}} | ||
{{- end -}} | ||
|
||
{{- with .Width -}} | ||
{{- $width = . -}} | ||
{{- $optim := .OptimConfig -}} | ||
{{- $srcset := "" -}} | ||
{{- if $optim | and $resource | and $optimise -}} | ||
{{ $srcsetSlice := slice -}} | ||
{{- range $optim -}} | ||
{{- if .Process -}} | ||
{{- $processed := $resource.Process .Process -}} | ||
{{- $srcsetSlice = $srcsetSlice | append (printf "%s %s" $processed.RelPermalink .descriptor) -}} | ||
{{- end -}} | ||
{{- end -}} | ||
{{- $srcset = delimit $srcsetSlice ", " -}} | ||
{{- end -}} | ||
|
||
{{- $src := $resource.RelPermalink | default .Src -}} | ||
{{- $alt := .Alt | default .Title -}} | ||
{{- $height := .Height | default $resource.Height | default "" -}} | ||
{{- $width := .Width | default $resource.Width | default "" -}} | ||
|
||
{{- if .Linked -}} | ||
<a class="lightgallery" href="{{ $large.RelPermalink | safeURL }}" title="{{ .Title | default $alt }}" data-thumbnail="{{ $small.RelPermalink | safeURL }}"{{ with .Caption }} data-sub-html="<h2>{{ . }}</h2>{{ with $.Title }}<p>{{ . }}</p>{{ end }}"{{ end }}{{ with .Rel }} rel="{{ . }}"{{ end }}> | ||
<a class="lightgallery" href="{{ $src }}" title="{{ .Title | default .Alt }}" data-thumbnail="{{ $src }}"{{ with .Caption }} data-sub-html="<h2>{{ . }}</h2>{{ with $.Title }}<p>{{ . }}</p>{{ end }}"{{ end }}{{ with .Rel }} rel="{{ . }}"{{ end }}> | ||
{{- end -}} | ||
<img | ||
{{ with .Class }}class="{{ . }}"{{ end }} | ||
loading="{{ $loading }}" | ||
src="{{ $default.RelPermalink | safeURL }}" | ||
srcset=" | ||
{{- if eq $optimized false -}} | ||
{{ $small.RelPermalink | safeURL }}, {{ $default.RelPermalink | safeURL }} 1.5x, {{ $large.RelPermalink | safeURL }} 2x | ||
{{- else -}} | ||
{{ $small.RelPermalink | safeURL }} {{ $small.Width }}w, | ||
{{ $default.RelPermalink | safeURL }} {{ $default.Width }}w, | ||
{{ $large.RelPermalink | safeURL }} {{ $large.Width }}w | ||
{{- end -}} | ||
" | ||
alt="{{ $alt }}"{{ with $height }} height="{{ . }}" {{ end }}{{ with $width }} width="{{ . }}" {{ end }}> | ||
<img {{ with .Class }}class="{{ . }}"{{ end }} {{ with .Loading }}loading="{{ . }}"{{ end }} src="{{ $src }}" {{ with $srcset }}srcset="{{ . }}"{{ end }} {{ with .Sizes }}sizes="{{ . }}"{{ end }} {{ with $alt }}alt="{{ . }}"{{ end }} {{ with $height }}height="{{ . }}"{{ end }} {{ with $width }}width="{{ . }}"{{ end }}> | ||
{{- if .Linked -}} | ||
</a> | ||
</a> | ||
{{- 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
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
Oops, something went wrong.