-
Notifications
You must be signed in to change notification settings - Fork 47
Allow images in resource folder and resize for mobile #31
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
base: main
Are you sure you want to change the base?
Changes from all commits
9702070
55cbca6
ff4bd76
74c18bc
f764db6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,50 @@ | ||
| {{ define "main" }} | ||
| <header> | ||
| <h2>{{ .Title }}</h2> | ||
| {{ with .Description -}} | ||
| <p>{{ . }}</p> | ||
| {{- end }} | ||
| </header> | ||
|
|
||
| {{- if .Params.image }} | ||
| <span class="image featured"><img src="{{ .Params.image | relURL }}" alt="{{ .Params.image_alt }}" /></span> | ||
| <header> | ||
| <h2>{{ .Title }}</h2> | ||
| {{ with .Description }} | ||
| <p>{{ . }}</p> | ||
| {{ end }} | ||
| </header> | ||
|
|
||
| {{ range .RegularPages }} | ||
| {{ .Render "shortblock" }} | ||
| {{ end }} | ||
| {{- if .Params.image }} | ||
| {{- $alt := .Params.image_alt | default .Title -}} | ||
| {{- with $img := resources.Get .Params.image }} | ||
| {{ $image_options := $.Site.Params.image_options | default "webp q85 lanczos photo" }} | ||
| <picture class="image featured"> | ||
| {{- $breakpoints := slice 1920 1600 1366 900 600 360 -}} | ||
| {{- range $bp := $breakpoints }} | ||
| {{- if le $bp .Width }} | ||
| {{- with .Resize (printf "%dx %s" $bp $image_options) }} | ||
| <source srcset="{{ .RelPermalink }}" type="{{ .MediaType.Type }}" media="(max-width: {{ $bp }}px)"> | ||
| {{- end }} | ||
| {{- end }} | ||
| {{- end }} | ||
|
|
||
| {{- /* Fallback: full-sized optimized image */ -}} | ||
| {{- with .Resize (printf "%dx %s" .Width $image_options) }} | ||
| <img | ||
| src="{{ .RelPermalink }}" | ||
| srcset="{{- range $bp := $breakpoints -}} | ||
| {{- with $.Resize (printf "%dx %s" $bp $image_options) -}} | ||
| {{ .RelPermalink }} {{ .Width }}w, | ||
| {{- end -}} | ||
| {{- end -}}" | ||
| sizes="(max-width: 1920px) 100vw, 1920px" | ||
| alt="{{ $alt }}" | ||
| width="{{ .Width }}" | ||
| height="{{ .Height }}" | ||
| loading="lazy" | ||
| class="img-fluid" /> | ||
| {{- end }} | ||
| </picture> | ||
| {{- else }} | ||
| <span class="image featured"> | ||
| <img src="{{ .Params.image | relURL }}" alt="{{ $alt }}"> | ||
| </span> | ||
| {{- end }} | ||
| {{ end }} | ||
|
|
||
| {{ range .RegularPages }} | ||
| {{ .Render "shortblock" }} | ||
| {{ end }} | ||
| {{ end }} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,55 @@ | ||
| <section class="col-6 col-12-narrower"> | ||
| <div class="box post"> | ||
| <a href="{{ .RelPermalink }}" class="image left"><img src="{{ .Params.image | relURL }}" alt="{{ .Params.image_alt }}" /></a> | ||
| <div class="inner"> | ||
| <h3><a href="{{ .RelPermalink }}">{{ .Title }}</a></h3> | ||
| {{ if .Site.Params.show_post_dates | default true }} | ||
| {{- with .Date }}<time>{{ . | time.Format ":date_medium" }}</time>{{ end }} | ||
| {{ end }} | ||
| <p> | ||
| {{ with .Description }} | ||
| {{- . }} | ||
| {{- else }} | ||
| {{- .Summary }} | ||
| {{- end }} | ||
| </p> | ||
| </div> | ||
| <div class="box post"> | ||
| <a href="{{ .RelPermalink }}" class="image left"> | ||
| {{- $alt := .Params.image_alt | default .Title -}} | ||
| {{- with $img := resources.Get .Params.image }} | ||
| {{ $image_options := $.Site.Params.image_options | default "webp q85 lanczos photo" }} | ||
| {{- $breakpoints := slice 800 600 400 300 -}} | ||
| {{- $orig := $img -}} | ||
|
|
||
| <picture> | ||
| {{- range $bp := $breakpoints }} | ||
| {{- if le $bp $orig.Width }} | ||
| {{- with $orig.Resize (printf "%dx %s" $bp $image_options) }} | ||
| <source srcset="{{ .RelPermalink }}" type="{{ .MediaType.Type }}" media="(max-width: {{ $bp }}px)"> | ||
| {{- end }} | ||
| {{- end }} | ||
| {{- end }} | ||
|
|
||
| {{- /* Fallback main image (max 800px) */ -}} | ||
| {{- with $orig.Resize (printf "800x %s" $image_options) }} | ||
| <img | ||
| src="{{ .RelPermalink }}" | ||
| srcset="{{- range $bp := $breakpoints -}} | ||
| {{- with $orig.Resize (printf "%dx %s" $bp $image_options) -}} | ||
| {{ .RelPermalink }} {{ .Width }}w, | ||
| {{- end -}} | ||
| {{- end -}}" | ||
| sizes="(max-width: 800px) 100vw, 300px" | ||
| alt="{{ $alt }}" | ||
| width="{{ .Width }}" | ||
| height="{{ .Height }}" | ||
|
Comment on lines
+30
to
+31
Owner
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. Moving the exampleSite images from static/ to assets/ to test, this makes the front page block show a very tall left 10% of the image. Similar scale/size issues on the post list and post pages. |
||
| loading="lazy" | ||
| class="img-fluid" /> | ||
| {{- end }} | ||
| </picture> | ||
| {{- else }} | ||
| <img src="{{ .Params.image | relURL }}" alt="{{ $alt }}"> | ||
| {{- end }} | ||
| </a> | ||
|
|
||
| <div class="inner"> | ||
| <h3><a href="{{ .RelPermalink }}">{{ .Title }}</a></h3> | ||
| {{ if .Site.Params.show_post_dates | default true }} | ||
| {{- with .Date }}<time>{{ . | time.Format ":date_medium" }}</time>{{ end }} | ||
| {{ end }} | ||
| <p> | ||
| {{ with .Description }} | ||
| {{- . }} | ||
| {{- else }} | ||
| {{- .Summary }} | ||
| {{- end }} | ||
| </p> | ||
| </div> | ||
| </div> | ||
| </section> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,11 @@ | ||
| <script src="{{ (resources.Get "js/jquery.min.js").RelPermalink }}"></script> | ||
| <script src="{{ (resources.Get "js/jquery.dropotron.min.js").RelPermalink }}"></script> | ||
| <script src="{{ (resources.Get "js/browser.min.js").RelPermalink }}"></script> | ||
| <script src="{{ (resources.Get "js/breakpoints.min.js").RelPermalink }}"></script> | ||
| <script src="{{ (resources.Get "js/util.js").RelPermalink }}"></script> | ||
| <script src="{{ (resources.Get "js/main.js").RelPermalink }}"></script> | ||
| {{- $js := slice | ||
| (resources.Get "js/jquery.min.js") | ||
| (resources.Get "js/jquery.dropotron.min.js") | ||
| (resources.Get "js/browser.min.js") | ||
| (resources.Get "js/breakpoints.min.js") | ||
| (resources.Get "js/util.js") | ||
| (resources.Get "js/main.js") | ||
| -}} | ||
|
|
||
| {{- $bundle := $js | resources.Concat "js/bundle.js" | resources.Minify | resources.Fingerprint -}} | ||
| <script src="{{ $bundle.RelPermalink }}" integrity="{{ $bundle.Data.Integrity }}" crossorigin="anonymous"></script> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,27 +2,27 @@ | |
| font-family:"Source Sans Pro"; | ||
| font-style:normal; | ||
| font-weight:300; | ||
| font-display:auto; | ||
| font-display:swap; | ||
|
Owner
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. Why swap? I assume responsiveness, but is it a best practice or solving a specific problem? |
||
| src:url(../webfonts/SourceSansPro-Light.ttf); | ||
| } | ||
| @font-face{ | ||
| font-family:"Source Sans Pro"; | ||
| font-style:italic; | ||
| font-weight:300; | ||
| font-display:auto; | ||
| font-display:swap; | ||
| src:url(../webfonts/SourceSansPro-LightItalic.ttf); | ||
| } | ||
| @font-face{ | ||
| font-family:"Source Sans Pro"; | ||
| font-style:normal; | ||
| font-weight:600; | ||
| font-display:auto; | ||
| font-display:swap; | ||
| src:url(../webfonts/SourceSansPro-SemiBold.ttf); | ||
| } | ||
| @font-face{ | ||
| font-family:"Source Sans Pro"; | ||
| font-style:italic; | ||
| font-weight:600; | ||
| font-display:auto; | ||
| font-display:swap; | ||
| src:url(../webfonts/SourceSansPro-SemiBoldItalic.ttf); | ||
| } | ||
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.
Should this exclude sizes larger than the original image?