-
-
Notifications
You must be signed in to change notification settings - Fork 199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: make srcset
actually useful
#1170
Merged
+107
−77
Merged
Changes from 10 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
c91f502
feat: add isUrlRemote.html file for remote URL detection
Sped0n 9b14906
refactor: refactor image resource pipeline
Sped0n e65b2f9
feat: create image handler for dynamic `srcset` generatation
Sped0n 4209031
refactor: adapt `image.html` to new image pipeline
Sped0n 8e43e91
feat: add new configuration options for image optimization
Sped0n 45c602b
refactor: update parameters in render and image HTML files
Sped0n 7acd817
refactor: optimize preview image handling in layout files
Sped0n 95def4c
chore: refine comment about caching remote images
Sped0n f7aaa2f
fix: set experimental `optimizeImages` to false
Sped0n 032d6d7
fix: fix wrong dict key and value in md render hook
Sped0n 5f7b19a
fix: remove debug `warnf`
Sped0n 4e7c350
fix: refactor image.html template attributes
Sped0n 031b0ba
Merge branch 'main' into srcset
Sped0n0ld 13b6069
chore: enable optimisation on the exampleSite
HEIGE-PCloud 0abc1d9
fix: remove sizes=auto
HEIGE-PCloud 33aa16c
docs: update documentation on `optimizeImages` and `cacheRemoteImages`
Sped0n File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,13 +1,13 @@ | ||
{{- $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 | partial "plugin/image.html" -}} | ||
{{- dict "Src" .Destination "Title" .Text "Caption" .Title "Linked" $lightgallery "Resources" .Page.Resources "Optim" true "Remote" true | partial "plugin/image.html" -}} | ||
<figcaption class="image-caption"> | ||
{{- .Title | safeHTML -}} | ||
</figcaption> | ||
</figure> | ||
{{- else -}} | ||
<figure> | ||
{{- dict "Src" .Destination "Title" .Text "Linked" $lightgallery "Resources" .Page.Resources | partial "plugin/image.html" -}} | ||
{{- dict "Src" .Destination "Title" .Text "Linked" $lightgallery "Resources" .Page.Resources "Optim" true "Remote" true | partial "plugin/image.html" -}} | ||
</figure> | ||
{{- 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{{- $path:= .Path -}} | ||
{{- $imageResource := 0 -}} | ||
|
||
{{- with dict "Path" $path "Resources" .Resources | partial "function/resource.html" -}} | ||
{{- $imageResource = . -}} | ||
{{- else -}} | ||
{{- $url := urls.Parse .Path -}} | ||
{{- if (eq site.Params.cacheRemoteImages true) | and (partial "function/isUrlRemote.html" $url) | and .Remote -}} | ||
{{- $imageResource = partial "function/getRemoteImage.html" $path -}} | ||
{{- end -}} | ||
{{- end -}} | ||
|
||
{{- if not (and (not (eq $imageResource 0)) (eq $imageResource.ResourceType "image")) -}} | ||
{{- $imageResource = 0 -}} | ||
{{- end -}} | ||
|
||
{{- return $imageResource -}} |
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,20 @@ | ||
{{- $return := 0 -}} | ||
{{- $suffixList := slice ".jpeg" ".jpg" ".png" ".gif" ".bmp" ".tif" ".tiff" ".webp" -}} | ||
|
||
{{- if not (eq .Optim true) -}} | ||
{{- warnf .Image.RelPermalink -}} | ||
{{- $return = dict "S" .Image "M" .Image "L" .Image "Optimized" false -}} | ||
{{- else if or | ||
(not (eq site.Params.optimizeImages true)) | ||
(not (dict "Path" .Image.RelPermalink "Suffixes" $suffixList | partial "function/suffixValidation.html")) | ||
-}} | ||
{{- $return = dict "S" .Image "M" .Image "L" .Image "Optimized" true -}} | ||
{{- else -}} | ||
{{- $s := .Image.Resize (site.Params.srcsetSmallResizeMethod | default "700x webp Lanczos q60") -}} | ||
{{- $m := .Image.Resize (site.Params.srcsetDefaultResizeMethod | default "1200x webp Lanczos q60") -}} | ||
{{- $l := .Image.Resize (site.Params.srcsetLargeResizeMethod | default "2000x webp Lanczos q60") -}} | ||
{{- $return = dict "S" $s "M" $m "L" $l "Optimized" true -}} | ||
{{- warnf $m.RelPermalink -}} | ||
{{- end -}} | ||
|
||
{{- return $return -}} |
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 @@ | ||
{{- return .Host | and .Path | and (strings.HasSuffix .Path "/" | not) -}} |
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To avoid interfering with the images in the header and other sections, I have created two variables: The srcset optimization is now enabled in the following parts:
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just revert the changes I made in
cacheRemoteImages
pr, many other partial will use this hook, would be better to keep it "neutral".