Skip to content

Commit 547c9cf

Browse files
authored
Replace buggy Author avatar object with block (#1723)
1 parent 5af1d70 commit 547c9cf

File tree

3 files changed

+37
-19
lines changed

3 files changed

+37
-19
lines changed

.changeset/good-ligers-arrive.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@cloudfour/patterns': major
3+
---
4+
5+
Replaces the buggy Author `avatar.src` functionality with a template block

src/components/author/author.stories.mdx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const allAuthors = [
1313
},
1414
{
1515
name: 'Danielle Romo',
16-
avatar: { src: danielleImage, width: 64 },
16+
avatar: danielleImage,
1717
link: 'https://cloudfour.com/is/danielle',
1818
},
1919
{
@@ -142,7 +142,7 @@ Multiple authors are also supported.
142142
`authors` (array): Array of [author objects](https://timber.github.io/docs/reference/timber-user/#properties), each containing:
143143

144144
- `name` (string): The author's name.
145-
- `avatar` (string or object): If this is an object containing a `src`, this will be passed directly to [the Avatar component](/?path=/docs/components-avatar--empty) (along with any other properties, for example `srcset` or `sizes`). Otherwise, it is assumed to be a string and used as the Avatar's `src` property.
145+
- `avatar` (string): A URL for the author's avatar. For more complex customization, use the `avatars` block.
146146
- `link` (optional, string): An `href` for the author's name to link to, for example a bio page.
147147

148148
`author_prefix` (optional, string, default "By"): Used to create a more
@@ -154,3 +154,9 @@ accessible user experience by adding visually hidden text, prefixes the author n
154154

155155
`date_prefix` (optional, string, default "Published on"): Used to create a more
156156
accessible user experience by adding visually hidden text, prefixes the date value (e.g. "Published on March 31st, 2021")
157+
158+
## Template Blocks
159+
160+
- `authors`: The author links to display.
161+
- `avatars`: The [Avatars](/?path=/docs/components-avatar--empty), which will be passed to a [Bunch](/?path=/docs/objects-bunch--of-avatars). Use this if you want to make deeper customizations to the avatars, for example adding `srcset` and `sizes`.
162+
- `meta_content`: The date or other additional content to display.

src/components/author/author.twig

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,22 @@
4040
{% endblock %}
4141
{% endset %}
4242

43+
{% set _avatars %}
44+
{% block avatars %}
45+
{% for author in authors %}
46+
{% include '@cloudfour/components/avatar/avatar.twig' with { src: author.avatar } only %}
47+
{% endfor %}
48+
{% endblock %}
49+
{% endset %}
50+
4351
<div class="c-author o-media{% if class %} {{ class }}{% endif %}">
4452
{# Avatar(s) #}
45-
{% embed '@cloudfour/objects/bunch/bunch.twig' with { class: 'o-media__object' } %}
53+
{% embed '@cloudfour/objects/bunch/bunch.twig' with {
54+
class: 'o-media__object',
55+
_avatars: _avatars
56+
} only %}
4657
{% block content %}
47-
{% for author in authors %}
48-
{% if author.avatar.src is defined %}
49-
{% include '@cloudfour/components/avatar/avatar.twig' with author.avatar only %}
50-
{% else %}
51-
{% include '@cloudfour/components/avatar/avatar.twig' with { src: author.avatar } only %}
52-
{% endif %}
53-
{% endfor %}
58+
{{_avatars}}
5459
{% endblock %}
5560
{% endembed %}
5661

@@ -59,15 +64,17 @@
5964
{# Author links #}
6065
<p class="c-author__author">
6166
<span class="u-hidden-visually">{{ author_prefix|default("By") }}</span>
62-
{% for author in authors %}
63-
{% if loop.last and loop.length > 1 %}and {% endif %}
64-
{% if author.link %}
65-
<a href="{{ author.link }}">{{ author.name }}</a>
66-
{% else %}
67-
<span>{{ author.name }}</span>
68-
{% endif %}
69-
{%- if not loop.last and loop.length > 2 %},{% endif %}
70-
{% endfor %}
67+
{% block authors %}
68+
{% for author in authors %}
69+
{% if loop.last and loop.length > 1 %}and {% endif %}
70+
{% if author.link %}
71+
<a href="{{ author.link }}">{{ author.name }}</a>
72+
{% else %}
73+
<span>{{ author.name }}</span>
74+
{% endif %}
75+
{%- if not loop.last and loop.length > 2 %},{% endif %}
76+
{% endfor %}
77+
{% endblock %}
7178
</p>
7279

7380
{# Author meta content #}

0 commit comments

Comments
 (0)