Skip to content

Commit

Permalink
Show a byline in the multi-byline element
Browse files Browse the repository at this point in the history
  • Loading branch information
rhystmills committed Sep 25, 2024
1 parent 9a49795 commit d6be124
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 7 deletions.
1 change: 0 additions & 1 deletion dotcom-rendering/src/components/MultiByline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export const MultiByline = ({
return (
<ol data-ignore="global-ol-styling">
{multiBylineItems.map((multiBylineItem, index) => (
// eslint-disable-next-line react/no-array-index-key -- Title should usually be identical, but in case it isn't, also use array index
<MultiBylineItemComponent
multiBylineItem={multiBylineItem}
format={format}
Expand Down
58 changes: 52 additions & 6 deletions dotcom-rendering/src/components/MultiBylineItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,65 @@ export const MultiBylineItem = ({
<>
<li css={multiBylineItemStyles} data-spacefinder-role="nested">
<hr css={headingLineStyles} />
<h3
id={slugify(multiBylineItem.title)}
css={[subheadingStyles(format), headingMarginStyle]}
>
{multiBylineItem.title}
</h3>
<Byline
title={multiBylineItem.title}
byline={multiBylineItem.byline ?? ''}
bylineHtml={multiBylineItem.bylineHtml ?? ''}
contributors={multiBylineItem.contributors ?? []}
format={format}
/>
<Bio html={multiBylineItem.bio} />
{children}
</li>
</>
);
};

type BylineProps = {
title: string;
bylineHtml: string;
byline: string;
imageOverrideUrl?: string;
contributors: BlockContributor[];
format: ArticleFormat;
};

const Byline = ({
title,
bylineHtml,
byline,
imageOverrideUrl,
contributors,
format,
}: BylineProps) => {
const sanitizedHtml = sanitise(bylineHtml, {});

return (
<div>
<div>
<h3
id={slugify(title)}
css={[subheadingStyles(format), headingMarginStyle]}
>
{title}
</h3>
{bylineHtml ? (
<h3
css={[subheadingStyles(format), headingMarginStyle]}
dangerouslySetInnerHTML={{ __html: sanitizedHtml }}
/>
) : null}
</div>
{imageOverrideUrl ?? contributors[0]?.imageUrl ? (
<img
src={imageOverrideUrl ?? contributors[0]?.imageUrl}
alt={byline}
></img>
) : null}
</div>
);
};

const Bio = ({ html }: { html?: string }) => {
if (!html) return null;
const sanitizedHtml = sanitise(html, {});
Expand Down

0 comments on commit d6be124

Please sign in to comment.