Skip to content

Commit

Permalink
Merge pull request #1056 from gethinode/develop
Browse files Browse the repository at this point in the history
Add anchor support to cards
  • Loading branch information
markdumay authored Jul 29, 2024
2 parents 1c8912e + 2394f14 commit 92dc97d
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 6 deletions.
19 changes: 19 additions & 0 deletions data/structures/card.yml
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,25 @@ arguments:
One or more strings separated by commas, indicating the source sizes of an
image set.
group: partial
anchor:
type: select
optional: true
comment:
Anchor of the thumbnail's crop box, defaults to anchor value set in
`imaging` section of the site configuration (usually `Smart`).
options:
values:
- TopLeft
- Top
- TopRight
- Left
- Center
- Right
- BottomLeft
- Bottom
- BottomRight
- Smart
release: v0.24.23
body:
optional: true
comment: >-
Expand Down
9 changes: 8 additions & 1 deletion layouts/partials/assets/adapters/hugo.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,14 @@
{{ end }}

{{- $clean := path.Ext $img.RelPermalink -}}
{{- $scaled = $scaled | resources.Copy (replace $img.RelPermalink $clean (printf "-%dx%d.%s" $width $height $format)) -}}
{{ $destination := "" }}
{{ if $anchor }}
{{ $destination = printf "-%dx%d-%s.%s" $width $height (lower $anchor) $format }}
{{ else }}
{{ $destination = printf "-%dx%d.%s" $width $height $format }}
{{ end }}

{{- $scaled = $scaled | resources.Copy (replace $img.RelPermalink $clean $destination) -}}
{{- if $absoluteURL -}}
{{- $element = $scaled.Permalink -}}
{{- else -}}
Expand Down
2 changes: 2 additions & 0 deletions layouts/partials/assets/card-group.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,13 @@
<!-- headless page -->
{{- else -}}
{{- $thumbnail := (or (and (reflect.IsMap $element.Params.Thumbnail) $element.Params.Thumbnail.url) $element.Params.Thumbnail) -}}
{{- $anchor := (or (and (reflect.IsMap $element.Params.Thumbnail) $element.Params.Thumbnail.anchor) "") -}}
{{- $params = merge $params (dict
"title" $element.Title
"href" $element.RelPermalink
"description" (partial "utilities/GetDescription.html" (dict "page" $element "raw" true))
"thumbnail" $thumbnail
"anchor" $anchor
"icon" $element.Params.icon
) -}}
{{- end -}}
Expand Down
6 changes: 4 additions & 2 deletions layouts/partials/assets/card.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
{{- $ratio := .ratio -}}
{{- $portrait := .portrait | default false -}}
{{- $thumbnail := .thumbnail -}}
{{- $anchor := .anchor | default "" -}}
{{- $title := .title -}}
{{- $subtle := .subtle -}}
{{- $button := .button -}}
Expand Down Expand Up @@ -64,6 +65,7 @@
{{- if and (reflect.IsMap .Params.Thumbnail) .Params.Thumbnail.ratio }}{{ $ratio = .Params.Thumbnail.ratio }}{{ end -}}
{{ end }}
{{- if not $icon }}{{ $icon = .Params.icon }}{{ end -}}
{{- if not $anchor }}{{ $anchor = (or (and (reflect.IsMap .Params.Thumbnail) .Params.Thumbnail.anchor) "") }}{{ end -}}
{{- end -}}

{{ if (hasPrefix $orientation "horizontal") }}
Expand Down Expand Up @@ -167,7 +169,7 @@
<div class="row g-0 row-cols-2 h-100{{ if $button }} pb-5{{ end }}">
{{- if $thumbnail -}}
<div class="{{ $col1 }}">
{{- partial $hook (dict "url" $thumbnail "ratio" (or $ratio "1x1") "portrait" $portrait "sizes" $sizes "wrapper" "h-100 card-img-wrap" "class" "rounded-start card-img-h100 card-img-bg" "title" $title "loading" $loading) -}}
{{- partial $hook (dict "url" $thumbnail "ratio" (or $ratio "1x1") "portrait" $portrait "sizes" $sizes "anchor" $anchor "wrapper" "h-100 card-img-wrap" "class" "rounded-start card-img-h100 card-img-bg" "title" $title "loading" $loading) -}}
</div>
{{- else if $icon -}}
<div class="{{ $col1 }} p-{{ $padding }}">
Expand Down Expand Up @@ -212,7 +214,7 @@
<!-- Render stacked / default card -->
<div class="card {{ $colorStyle }} {{ $class }} text-{{ $align }}">
{{- if $thumbnail -}}
{{- partial $hook (dict "url" $thumbnail "ratio" (or $ratio "16x9") "portrait" $portrait "sizes" $sizes "wrapper" "card-img-wrap" "class" "card-img-top card-img-bg" "title" (or $alt $title) "loading" $loading) -}}
{{- partial $hook (dict "url" $thumbnail "ratio" (or $ratio "16x9") "portrait" $portrait "anchor" $anchor "sizes" $sizes "wrapper" "card-img-wrap" "class" "card-img-top card-img-bg" "title" (or $alt $title) "loading" $loading) -}}
{{- else if $icon -}}
<div class="card-icon p-{{ $padding }} {{ $iconStyle }} text-{{ $align }} {{ if $iconRounded }}fa-stack {{ $stack }}{{ end }} w-100">
{{ if $iconRounded }}
Expand Down
2 changes: 2 additions & 0 deletions layouts/shortcodes/card.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
{{- $page := .Page -}}
{{- $path := .Get "path" -}}
{{- $thumbnail := .Get "thumbnail" -}}
{{- $anchor := .Get "anchor" -}}
{{- $title := .Get "title" -}}
{{- $button := partial "utilities/GetArgParent" (dict "page" . "arg" "button") | default false -}}
{{- $buttonType := partial "utilities/GetArgParent" (dict "page" . "arg" "buttonType") | default "" -}}
Expand Down Expand Up @@ -81,6 +82,7 @@
"wrapper" $wrapper
"thumbnail" $thumbnail
"loading" $loading
"anchor" $anchor
"alt" $alt
"button" $button
"buttonType" $buttonType
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.24.22",
"version": "0.24.23",
"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 92dc97d

Please sign in to comment.