Skip to content

Commit

Permalink
Merge pull request #915 from gethinode/develop
Browse files Browse the repository at this point in the history
Improve image set rendering
  • Loading branch information
markdumay authored May 6, 2024
2 parents 6d57058 + 9300a79 commit 9c71856
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 24 deletions.
8 changes: 8 additions & 0 deletions data/structures/card.yml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,14 @@ arguments:
optional: true
comment: Render hook for the image partial.
group: partial
sizes:
type: string
default: 100vw
optional: true
comment: >-
One or more strings separated by commas, indicating the source sizes of an
image set.
group: partial
body:
optional: true
comment: >-
Expand Down
8 changes: 8 additions & 0 deletions data/structures/image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ arguments:
- low
- auto
group: partial
sizes:
type: string
default: 100vw
optional: true
comment: >-
One or more strings separated by commas, indicating the source sizes of an
image set.
group: partial
title:
type: string
optional: true
Expand Down
9 changes: 0 additions & 9 deletions exampleSite/hugo_stats.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,6 @@
"fa-2xs",
"fa-4x",
"fa-activity",
"fa-angle-left",
"fa-angle-right",
"fa-angles-left",
"fa-angles-right",
"fa-arrow-left",
"fa-arrow-right",
"fa-bootstrap",
Expand Down Expand Up @@ -331,10 +327,6 @@
"p-2",
"p-3",
"p-4",
"page-item",
"page-link",
"pagination",
"pagination-terse",
"pb-2",
"pb-3",
"pb-4",
Expand All @@ -351,7 +343,6 @@
"ps-1",
"ps-3",
"pt-1",
"pt-3",
"pt-5",
"pt-md-3",
"ptw-3",
Expand Down
37 changes: 32 additions & 5 deletions layouts/partials/assets/card-group.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,38 @@
{{- $responsive := .responsive | default true -}}
{{- $cols := string .cols | default "3" -}}

{{- $sizes := "100vw" }}
{{- $colGrid := "" -}}
{{- if eq $cols "1" }}{{ $colGrid = "row-cols-1" -}}
{{- else if eq $cols "2" }}{{ if $responsive }}{{ $colGrid = printf "row-cols-1 row-cols-%s-1 row-cols-%s-2" $breakpoint.prev $breakpoint.current }}{{ else }}{{ $colGrid = "row-cols-2" }}{{ end -}}
{{- else if eq $cols "3" }}{{ if $responsive }}{{ $colGrid = printf "row-cols-1 row-cols-%s-2 row-cols-%s-3" $breakpoint.prev $breakpoint.current }}{{ else }}{{ $colGrid = "row-cols-3" }}{{ end -}}
{{- else if eq $cols "4" }}{{ if $responsive }}{{ $colGrid = printf "row-cols-1 row-cols-%s-2 row-cols-%s-4" $breakpoint.prev $breakpoint.current }}{{ else }}{{ $colGrid = "row-cols-4" }}{{ end -}}
{{- else if eq $cols "5" }}{{ if $responsive }}{{ $colGrid = printf "row-cols-1 row-cols-%s-3 row-cols-%s-5" $breakpoint.prev $breakpoint.current }}{{ else }}{{ $colGrid = "row-cols-5" }}{{ end -}}
{{- if eq $cols "1" }}
{{ $colGrid = "row-cols-1" -}}
{{- else if eq $cols "2" }}
{{ if $responsive }}
{{ $colGrid = printf "row-cols-1 row-cols-%s-1 row-cols-%s-2" $breakpoint.prev $breakpoint.current }}
{{ else }}
{{ $colGrid = "row-cols-2" }}
{{ end -}}
{{ $sizes = printf "(min-width: %s) 50vw, 100vw" $breakpoint.currentSize }}
{{- else if eq $cols "3" }}
{{ if $responsive }}
{{ $colGrid = printf "row-cols-1 row-cols-%s-2 row-cols-%s-3" $breakpoint.prev $breakpoint.current }}
{{ else }}
{{ $colGrid = "row-cols-3" }}
{{ end -}}
{{ $sizes = printf "(min-width: %s) 33.3vw, (min-width: %s) 50vw, 100vw" $breakpoint.currentSize $breakpoint.prevSize }}
{{- else if eq $cols "4" }}
{{ if $responsive }}
{{ $colGrid = printf "row-cols-1 row-cols-%s-2 row-cols-%s-4" $breakpoint.prev $breakpoint.current }}
{{ else }}
{{ $colGrid = "row-cols-4" }}
{{ end -}}
{{ $sizes = printf "(min-width: %s) 25vw, (min-width: %s) 50vw, 100vw" $breakpoint.currentSize $breakpoint.prevSize }}
{{- else if eq $cols "5" }}
{{ if $responsive }}
{{ $colGrid = printf "row-cols-1 row-cols-%s-3 row-cols-%s-5" $breakpoint.prev $breakpoint.current }}
{{ else }}
{{ $colGrid = "row-cols-5" }}
{{ end -}}
{{ $sizes = printf "(min-width: %s) 20vw, (min-width: %s) 33.3vw, 100vw" $breakpoint.currentSize $breakpoint.prevSize }}
{{ end -}}

{{- if not $paginate -}}
Expand All @@ -102,6 +128,7 @@
"footer" $footer
"header" $header
"loading" $loading
"sizes" $sizes
"orientation" $orientation
"padding" $padding
"ratio" $ratio
Expand Down
5 changes: 3 additions & 2 deletions layouts/partials/assets/card.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
{{- $iconStyle := "" -}}
{{- $align := .align | default "start" -}}
{{- $style := .style | default "" -}}
{{- $sizes := .sizes | default "100vw" -}}
{{- $loading := .loading -}}
{{- $orientation := .orientation | default "stacked" -}}
{{- $padding := (string .padding) | default "auto" -}}
Expand Down Expand Up @@ -131,7 +132,7 @@
<div class="row g-0 row-cols-1 h-100{{ if $button }} pb-5{{ end }}">
<div class="{{ if eq $orientation "horizontal-sm" }}col-4 col-md-2{{ else }}col-4{{ end }}">
{{- if $thumbnail -}}
{{- partial $hook (dict "url" $thumbnail "ratio" (or $ratio "1x1") "wrapper" "h-100 card-img-wrap" "class" "rounded-start card-img-h100" "title" $title "loading" $loading) -}}
{{- partial $hook (dict "url" $thumbnail "ratio" (or $ratio "1x1") "sizes" $sizes "wrapper" "h-100 card-img-wrap" "class" "rounded-start card-img-h100" "title" $title "loading" $loading) -}}
{{- else if $icon -}}
<div class="card-icon p-{{ $padding }} h-100 fa-wrapper d-flex align-items-{{ $align}} justify-content-center {{ $iconStyle }}">
{{- partial "assets/icon.html" (dict "icon" (printf "%s %s" $icon $style)) -}}
Expand All @@ -157,7 +158,7 @@
<!-- Render stacked / default card -->
<div class="card {{ $colorStyle }} {{ $class }} text-{{ $align }}">
{{- if $thumbnail -}}
{{- partial $hook (dict "url" $thumbnail "ratio" (or $ratio "16x9") "wrapper" "card-img-wrap" "class" "card-img-top" "title" (or $alt $title) "loading" $loading) -}}
{{- partial $hook (dict "url" $thumbnail "ratio" (or $ratio "16x9") "sizes" $sizes "wrapper" "card-img-wrap" "class" "card-img-top" "title" (or $alt $title) "loading" $loading) -}}
{{- else if $icon -}}
<div class="card-icon p-{{ $padding }} {{ $iconStyle }} text-{{ $align }}">
{{- partial "assets/icon.html" (dict "icon" (printf "%s %s" $icon $style)) -}}
Expand Down
6 changes: 5 additions & 1 deletion layouts/partials/assets/image.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
{{- $lazy := eq $loading "lazy" -}}
{{- $priority := .priority -}}
{{- if eq $priority "auto" }}{{ $priority = "" }}{{ end -}}
{{- $sizes := .sizes | default "100vw" -}}


{{- define "partials/image-portrait.html" -}}
{{- $dimensions := slice }}
Expand Down Expand Up @@ -168,6 +170,7 @@
{{- $modes := .modes -}}
{{- $lazy := .lazy -}}
{{- $page := .page -}}
{{- $sizes := .sizes -}}
{{- $priority := .priority -}}
{{- $isVector := false -}}

Expand Down Expand Up @@ -235,7 +238,7 @@
src="{{ $fallbackURL }}"
{{ if $lazy }}loading="lazy"{{ end }}
{{ with $priority }}fetchpriority="{{ . }}"{{ end }}
{{ with $imgset -}}srcset="{{ . }}" sizes="100vw"{{- end }}
{{ with $imgset -}}srcset="{{ . }}" sizes="{{ $sizes }}"{{- end }}
{{ with $height }}height="{{ . }}"{{ end }}
{{ with $width }}width="{{ . }}"{{ end }}
{{ with $title }}alt="{{ . }}"{{ end }}>
Expand Down Expand Up @@ -263,6 +266,7 @@
"figclass" $figclass
"lazy" $lazy
"priority" $priority
"sizes" $sizes
"page" $page)
-}}

Expand Down
19 changes: 15 additions & 4 deletions layouts/partials/list/featured.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{{- $orientation := .orientation | default "stacked" -}}
{{- $actions := .actions -}}
{{- $width := .width | default 6 }}
{{ $sizes := "100vw" }}
{{- if or (lt $width 1) (gt $width 12) -}}
{{- $width = 6 -}}
{{- warnf "partial [list/featured.html] - Invalid column width: %d" $width -}}
Expand All @@ -19,6 +20,11 @@
{{- end -}}
{{- $breadcrumb := and (not $page.IsHome) site.Params.navigation.breadcrumb -}}

{{- define "partials/list/featured-sizes.html" }}
{{ $sizes := printf "(min-width: 768px) %dvw, 50vw" (int (math.Round (div (mul .width 100) 12))) }}
{{ return $sizes }}
{{ end }}

{{- define "partials/list/featured-body.html" }}
{{- $page := .page -}}
{{- $headings := .headings -}}
Expand All @@ -44,6 +50,7 @@
{{- define "partials/list/featured-illustration.html" }}
{{- $page := .page -}}
{{- $style := printf "img-wrap mx-auto mx-md-0 %s" .style -}}
{{ $sizes := .sizes }}

{{ if $page.Params.icon }}
{{- $icon := (or (and (reflect.IsMap $page.Params.Icon) $page.Params.Icon.url) $page.Params.Icon) -}}
Expand All @@ -56,7 +63,7 @@
{{ else }}
{{- $thumbnail := (or (and (reflect.IsMap $page.Params.Thumbnail) $page.Params.Thumbnail.url) $page.Params.Thumbnail) -}}
{{- if $thumbnail }}
{{ partial "assets/image.html" (dict "url" $thumbnail "ratio" "16x9" "wrapper" $style "class" "rounded" "title" $page.Site.Title "priority" "high") }}
{{ partial "assets/image.html" (dict "url" $thumbnail "ratio" "16x9" "sizes" $sizes "wrapper" $style "class" "rounded" "title" $page.Site.Title "priority" "high") }}
{{ end }}
{{ end }}
{{- end -}}
Expand All @@ -70,7 +77,8 @@
{{ if eq $orientation "stacked" }}
<div class="row justify-content-center flex-fill">
<div class="col-12 col-md-{{ $width }} m-auto text-center">
{{ partial "partials/list/featured-illustration.html" (dict "page" $page "style" "pb-4") }}
{{ $sizes = partial "partials/list/featured-sizes.html" (dict "width" $width) }}
{{ partial "partials/list/featured-illustration.html" (dict "page" $page "sizes" $sizes "style" "pb-4") }}
{{ partial "partials/list/featured-body.html" (dict "page" $page "headings" $headings "orientation" $orientation "actions" $actions) }}
</div>
</div>
Expand All @@ -79,8 +87,11 @@
<div class="col col-12 col-md-{{ $width }} order-1 order-md-0 my-md-auto">
{{ partial "partials/list/featured-body.html" (dict "page" $page "headings" $headings "orientation" $orientation "actions" $actions "align" $align) }}
</div>
<div class="col col-12 col-md-{{ if gt $width 6 }}{{ sub 12 $width }}{{ else }}{{ $width }}{{ end }} order-0 order-md-1 text-center my-md-auto align-self-end">
{{ partial "partials/list/featured-illustration.html" (dict "page" $page "style" "pb-4 pb-md-0") }}
{{ $newWidth := $width }}
{{ if gt $width 6 }}{{ $newWidth = sub 12 $width }}{{ end }}
{{ $sizes = partial "partials/list/featured-sizes.html" (dict "width" $newWidth) }}
<div class="col col-12 col-md-{{ $newWidth }} order-0 order-md-1 text-center my-md-auto align-self-end">
{{ partial "partials/list/featured-illustration.html" (dict "page" $page "sizes" $sizes "style" "pb-4 pb-md-0") }}
</div>
</div>
{{ end }}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gethinode/hinode",
"version": "0.23.12",
"version": "0.23.13",
"description": "Hinode is a clean documentation and blog theme for Hugo, an open-source static site generator",
"keywords": [
"hugo",
Expand Down

0 comments on commit 9c71856

Please sign in to comment.