Skip to content

Commit

Permalink
feat: add hextra hero-container shortcode (#389)
Browse files Browse the repository at this point in the history
* Implement hextra hero-container

* Fix width

* Fix width

* Fix width

* Set number of columns

* Fix display for mobile devices

* Trim image prefix

* Implement image card

* Fix width

* Fix css
  • Loading branch information
fmunteanu authored May 23, 2024
1 parent 4eca719 commit d43ac66
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions layouts/shortcodes/hextra/hero-container.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{{- $class := .Get "class" -}}
{{- $cols := .Get "cols" | default 2 -}}
{{- $image := .Get "image" -}}
{{- $imageCard := .Get "imageCard" | default false -}}
{{- $imageClass := .Get "imageClass" -}}
{{- $imageLink := .Get "imageLink" -}}
{{- $imageLinkExternal := hasPrefix $imageLink "http" -}}
{{- $imageStyle := .Get "imageStyle" -}}
{{- $imageTitle := .Get "imageTitle" -}}
{{- $imageWidth := .Get "imageWidth" | default 350 -}}
{{- $imageHeight := .Get "imageHeight" | default 350 -}}
{{- $style := .Get "style" -}}

{{- $css := printf "--hextra-feature-grid-cols: %v; %s" $cols $style -}}
{{- $href := cond (hasPrefix $imageLink "/") ($imageLink | relURL) $imageLink -}}
{{- if hasPrefix $image "/" -}}
{{- $image = relURL (strings.TrimPrefix "/" $image) -}}
{{- end -}}

<div
class="{{ $class }} hextra-feature-grid hx-grid sm:max-lg:hx-grid-cols-2 max-sm:hx-grid-cols-1 hx-gap-4 hx-w-full not-prose"
{{ with $css }}style="{{ . | safeCSS }}"{{ end }}
>
<div class="hx-w-full">
{{ .Inner }}
</div>
{{- with $image }}
<div class="hx-mx-auto">
<a
{{ with $imageLink }}href="{{ $href }}" {{ with $imageLinkExternal }} target="_blank" rel="noreferrer"{{ end }}{{ end }}
{{ with $imageStyle }}style="{{ . | safeCSS }}"{{ end }}
class="{{ $imageClass }} {{ if $imageCard }}hextra-feature-card not-prose hx-block hx-relative hx-p-6 hx-overflow-hidden hx-rounded-3xl hx-border hx-border-gray-200 hover:hx-border-gray-300 dark:hx-border-neutral-800 dark:hover:hx-border-neutral-700 before:hx-pointer-events-none before:hx-absolute before:hx-inset-0 before:hx-bg-glass-gradient{{ end }}"
>
<img src="{{ $image }}" width="{{ $imageWidth }}" height="{{ $imageHeight }}" {{ with $imageTitle }}alt="{{ $imageTitle }}"{{ end }}/>
</a>
</div>
{{ end -}}
</div>

0 comments on commit d43ac66

Please sign in to comment.