-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #123 from plusserver/housekeeping/guidelines-for-i…
…mages Modify image guidelines
- Loading branch information
Showing
3 changed files
with
83 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{{/* get file that matches the filename as specified as src="" in shortcode */}} | ||
{{ $src := .Page.Resources.GetMatch (printf "*%s*" (.Get "src")) }} | ||
|
||
{{/* set image sizes, these are hardcoded for now, x dictates that images are resized to this width */}} | ||
|
||
{{ $tinyw := default "500x" }} | ||
{{ $smallw := default "800x" }} | ||
{{ $mediumw := default "1200x" }} | ||
{{ $largew := default "1500x" }} | ||
|
||
{{/* resize the src image to the given sizes */}} | ||
|
||
{{ .Scratch.Set "tiny" ($src.Resize $tinyw) }} | ||
{{ .Scratch.Set "small" ($src.Resize $smallw) }} | ||
{{ .Scratch.Set "medium" ($src.Resize $mediumw) }} | ||
{{ .Scratch.Set "large" ($src.Resize $largew) }} | ||
|
||
{{/* add the processed images to the scratch */}} | ||
|
||
{{ $tiny := .Scratch.Get "tiny" }} | ||
{{ $small := .Scratch.Get "small" }} | ||
{{ $medium := .Scratch.Get "medium" }} | ||
{{ $large := .Scratch.Get "large" }} | ||
|
||
{{/* only use images smaller than or equal to the src (original) image size, as Hugo will upscale small images */}} | ||
{{/* set the sizes attribute to (min-width: 35em) 1200px, 100vw unless overridden in shortcode */}} | ||
|
||
<img | ||
{{ with .Get "sizes" }}sizes='{{.}}'{{ else }}sizes="(min-width: 35em) 1200px, 100vw"{{ end }} | ||
srcset=' | ||
{{ if ge $src.Width "500" }} | ||
{{ with $tiny.RelPermalink }}{{.}} 500w{{ end }} | ||
{{ end }} | ||
{{ if ge $src.Width "800" }} | ||
{{ with $small.RelPermalink }}, {{.}} 800w{{ end }} | ||
{{ end }} | ||
{{ if ge $src.Width "1200" }} | ||
{{ with $medium.RelPermalink }}, {{.}} 1200w{{ end }} | ||
{{ end }} | ||
{{ if ge $src.Width "1500" }} | ||
{{ with $large.RelPermalink }}, {{.}} 1500w {{ end }} | ||
{{ end }}' | ||
{{ if .Get (print $medium) }} | ||
src="{{ $medium.RelPermalink }}" | ||
{{ else }} | ||
src="{{ $src.RelPermalink }}" | ||
{{ end }} | ||
{{ with .Get "alt" }}alt="{{.}}" title="{{.}}"{{ end }} | ||
> |