feat(blox): add fill_image option to article-grid view

Also
- Fixes Tailwind safelist/whitelistPatterns given change in Tailwind v3 config structure
- Renames new `resume-biography-2` to `resume-biography-3` due to clash
This commit is contained in:
George Cushen 2024-05-19 16:32:46 +01:00
commit 928399f2cd
7 changed files with 52 additions and 12 deletions

File diff suppressed because one or more lines are too long

View file

@ -94,11 +94,11 @@
<div class="flex flex-col items-center">
{{ $config := dict "columns" ($block.design.columns | default 2) "len" (len $query) }}
{{ $config := dict "columns" ($block.design.columns | default 2) "len" (len $query) "fill_image" ($block.design.fill_image | default true) }}
{{ partial "functions/render_view" (dict "fragment" "start" "page" $block "item" . "view" $view "config" $config) }}
{{ range $index, $item := $query }}
{{ partial "functions/render_view" (dict "page" $block "item" . "view" $view "index" $index) }}
{{ partial "functions/render_view" (dict "page" $block "item" . "view" $view "index" $index "config" $config) }}
{{end}}
{{ partial "functions/render_view" (dict "fragment" "end" "page" $block "item" . "view" $view) }}

View file

@ -1,4 +1,4 @@
{{/* Hugo Blox: Biography */}}
{{/* Hugo Blox: Biography 3 */}}
{{/* Documentation: https://hugoblox.com/blocks/ */}}
{{/* License: https://github.com/HugoBlox/hugo-blox-builder/blob/main/LICENSE.md */}}

View file

@ -15,7 +15,7 @@
{{ end }}
{{ if eq $fragment "body" }}
{{ $html = (partial (printf "views/%s" $view) (dict "page" $page "item" $item "index" $index)) }}
{{ $html = (partial (printf "views/%s" $view) (dict "page" $page "item" $item "index" $index "config" (.config | default dict))) }}
{{ else }}
{{ $html = (partial (printf "views/%s.%s" $view $fragment) (dict "page" $page "item" $item "index" $index "config" (.config | default dict))) }}
{{ end }}

View file

@ -1,21 +1,34 @@
{{ $item := .item }}
{{ $fill_image := .config.fill_image | default true }}
{{ $resource := partial "functions/get_featured_image.html" $item }}
{{ $anchor := $item.Params.image.focal_point | default "Center" }}
{{ $link := $item.Params.external_link | default $item.RelPermalink }}
{{ $target := "" }}
{{ if $item.Params.external_link }}
{{ $link = $item.Params.external_link }}
{{ $target = "target=\"_blank\" rel=\"noopener\"" }}
{{ end }}
<div class="group cursor-pointer">
{{ with $resource }}
{{ $image := .Fill (printf "655x655 %s" $anchor) }}
{{ $image := "" }}
{{if $fill_image}}
{{ $image = .Fill (printf "960x540 %s" $anchor) }}
{{else}}
{{ $image = .Fit (printf "960x540 %s" $anchor) }}
{{end}}
{{ if ne $image.MediaType.SubType "gif" }}{{ $image = $image.Process "webp" }}{{ end }}
<div class="overflow-hidden rounded-md bg-gray-100 transition-all hover:scale-105 dark:bg-gray-800">
<a
class="relative block aspect-video"
href="{{ $item.RelPermalink }}">
href="{{ $link }}" {{ $target | safeHTMLAttr }}>
<img alt="{{ $item.Title | plainify }}"
class="object-cover transition-all"
class="{{if $fill_image}}object-fill{{else}}object-contain{{end}} transition-all"
data-nimg="fill"
decoding="async"
fetchpriority="high" height="{{ $image.Height }}" loading="lazy" src="{{ $image.RelPermalink }}"
@ -33,14 +46,15 @@
</div>
<!-- <div class="relative line-clamp-2" style="display: block; height: 4em">-->
<h2 class="text-lg font-semibold leading-snug tracking-tight mt-2 dark:text-white"><a
href="{{ $item.RelPermalink }}"><span
href="{{ $link }}" {{ $target | safeHTMLAttr }}><span
class="bg-gradient-to-r from-primary-200 to-primary-100 bg-[length:0px_10px] bg-left-bottom bg-no-repeat transition-[background-size] duration-500 hover:bg-[length:100%_3px] group-hover:bg-[length:100%_10px] dark:from-primary-800 dark:to-primary-900">
{{- $item.Title -}}
{{if $target}}{{ partial "functions/get_icon" (dict "name" "arrow-top-right-on-square" "attributes" "style=\"height: 1em;\" class=\"inline-flex h-6 w-6 pl-2\"") }}{{end}}
</span></a>
</h2>
<!-- </div>-->
<div class="grow"><p class="mt-2 line-clamp-3 text-sm text-gray-500 dark:text-gray-400"><a
href="{{ $item.RelPermalink }}">
href="{{ $link }}" {{ $target | safeHTMLAttr }}>
{{ ($item.Params.summary | default $item.Summary) | plainify | htmlUnescape | chomp -}}
</a></p>
</div>

View file

@ -1,4 +1,5 @@
{{ $columns := .config.columns | default 2 }}
{{ $len := .config.len | default 2 }}
{{/* NOTE: dynamic `md:grid-cols-{{$columns}}` class requires Tailwind exception */}}
<div class="container px-8 mx-auto xl:px-5 py-5 lg:py-8 {{ if eq $len 1 }}max-w-[500px] justify-center{{else}}max-w-screen-lg {{end}}">
<div class="grid gap-10 md:grid-cols-{{$columns}} lg:gap-10">

View file

@ -25,8 +25,33 @@ module.exports = {
'task-list', /* As it's added via JS */
'pl-4', 'pl-8', 'pl-12', /* TOC indents */
'min-h-screen', /* Blox options */
{
/* For dynamic article-grid.start */
pattern: /grid-cols-+/,
variants: ['md'],
},
{
pattern: /bg-white+/,
},
{
pattern: /bg-gray+/,
},
{
pattern: /bg-primary+/,
},
{
pattern: /bg-gradient+/,
},
{
pattern: /from-primary+/,
},
{
pattern: /to-primary+/,
},
],
whitelistPatterns: [/^bg-white/, /^bg-gray-/, /^bg-primary-/, /^bg-gradient-/, /^from-primary-/, /^to-primary-/], /* /^pl-/ for TOC */
/* /^bg-white/, /^bg-gray-/, /^bg-primary-/, /^bg-gradient-/, /^from-primary-/, /^to-primary-/,
/^md:grid-cols-+/], */
/* /^pl-/ for TOC */
darkMode: ['class'],
theme: {
extend: {