Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multi byline element #12496

Merged
merged 51 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
69f0ac4
Add foundation for multi-byline element, based on mini-profiles
rhystmills Sep 25, 2024
5132540
Add Story for multi byline element and update model to include byline…
rhystmills Sep 25, 2024
6e33d0d
Show a byline in the multi-byline element
rhystmills Sep 25, 2024
7ec9ebd
Improve styles on Multi byline element
rhystmills Sep 25, 2024
efed52a
Push pending changes
rhystmills Oct 3, 2024
ffb2f18
fix import errors following https://github.com/guardian/dotcom-render…
rebecca-thompson Oct 28, 2024
465761d
fix eslint errors
rebecca-thompson Oct 28, 2024
7c5c88e
fix stylelint errors
rebecca-thompson Oct 29, 2024
8e67059
style contributor names that don't have a corresponding tag
rebecca-thompson Oct 30, 2024
df848f3
add stories for opinion and culture pillars
rebecca-thompson Oct 30, 2024
2d026ba
byline image styling
rebecca-thompson Oct 31, 2024
2b3ac4f
add multi-bylines to DCR model
rebecca-thompson Oct 31, 2024
014dbed
retrieve image url from contributor tag
rebecca-thompson Oct 31, 2024
b89df84
run 'make gen-schema'
rebecca-thompson Oct 31, 2024
f174743
add end note to component
rebecca-thompson Nov 1, 2024
bfb00cb
replace img tag with Avatar component
rebecca-thompson Nov 1, 2024
ffaf65a
update bottom margin to match designs
rebecca-thompson Nov 1, 2024
562ba95
fix css linting
rebecca-thompson Nov 1, 2024
26756cf
filter out audio designs in stories
rebecca-thompson Nov 1, 2024
978453b
tidy up labs-specific styling and remove `!important` to keep linter …
rebecca-thompson Nov 1, 2024
44502c3
make stories shorter to fix chromatic build
rebecca-thompson Nov 1, 2024
31f8401
break up design stories to fix chromatic build
rebecca-thompson Nov 1, 2024
1a45c1a
Break out `EndNote` into its own component
simonbyford Nov 20, 2024
a580b78
Break out `Bio` into its own component
simonbyford Nov 20, 2024
4ae9daf
Remove unused exports
simonbyford Nov 21, 2024
bf15345
Remove unnecessary fragment
simonbyford Nov 21, 2024
68d5095
Remove irrelevant comments
simonbyford Nov 21, 2024
31ebb39
Don't skip `h2`
simonbyford Nov 21, 2024
d30fded
Multi-byline articles are not ordered lists
simonbyford Nov 21, 2024
384f334
Make byline, bylineHtml, contributorIds required
simonbyford Nov 21, 2024
c1a614a
Remove redundancy in stories file
simonbyford Nov 21, 2024
95daefb
Be consistent in how we reuse `args`
simonbyford Nov 21, 2024
c5f7d38
Use colour from palette for bottom separator
simonbyford Nov 21, 2024
76e8ed2
Add bottom separator to Q and A Explainer element
simonbyford Nov 21, 2024
894ca06
Lint
simonbyford Nov 21, 2024
c85c3b0
Fix schema
simonbyford Nov 21, 2024
c59dfd8
Disable amp
simonbyford Nov 26, 2024
b522e05
Support list of contents
simonbyford Nov 26, 2024
86173e2
`Timeline` doesn't need `tags`
simonbyford Nov 26, 2024
28236e4
Rename colours
simonbyford Dec 3, 2024
3914352
Add new colour `--bio-link-underline`
simonbyford Dec 3, 2024
fbca108
Use `bylineImageUrl` not `bylineLargeImageUrl`
simonbyford Dec 5, 2024
138e7e9
Add new colour `--multi-byline-non-linked-text`
simonbyford Dec 9, 2024
cb01858
Use typography presets
simonbyford Dec 11, 2024
cb86c1b
Lint
simonbyford Dec 11, 2024
6ef8291
Remove redundant styles
simonbyford Dec 13, 2024
7d99004
Simplify naming
simonbyford Dec 13, 2024
0f41a1d
Use `hgroup` instead of `h3` to better follow spec
simonbyford Dec 13, 2024
1d0dab1
Derive `imageUrl` in the enhancer
simonbyford Dec 16, 2024
8ffa626
Skip elements without a `byline` or `bylineHtml`
simonbyford Jan 6, 2025
ad506b0
Remove unused import
simonbyford Jan 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions dotcom-rendering/src/components/Bio.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { css } from '@emotion/react';
import { space, textSans14 } from '@guardian/source/foundations';
import sanitise from 'sanitize-html';
import { palette } from '../palette';

/** Nesting is necessary in the bio styles because we receive a string of html from the
* field. This can contain the following tags:
* Blocks: p, ul, li
* Inline: strong, em, a
*/
const bioStyles = css`
${textSans14};
padding: ${space[1]}px 0;
color: ${palette('--bio-text-subdued')};
p {
margin-bottom: ${space[2]}px;
}
a {
color: ${palette('--link-kicker-text')};
text-underline-offset: 3px;
}
a:not(:hover) {
text-decoration-color: ${palette('--bio-link-underline')};
}
a:hover {
text-decoration: underline;
}
ul {
list-style: none;
margin: 0 0 ${space[2]}px;
padding: 0;
}
ul li {
padding-left: ${space[5]}px;
}
ul li p {
display: inline-block;
margin-bottom: 0;
}
ul li:before {
display: inline-block;
content: '';
border-radius: 0.375rem;
height: 10px;
width: 10px;
margin: 0 ${space[2]}px 0 -${space[5]}px;
background-color: ${palette('--bullet-fill')};
}
strong {
font-weight: bold;
}
`;

const bottomBorderStyles = css`
border-top: 1px solid ${palette('--article-border')};
margin-bottom: ${space[2]}px;
`;

const containsText = (html: string) => {
const htmlWithoutTags = sanitise(html, {
allowedTags: [],
allowedAttributes: {},
});
return htmlWithoutTags.length > 0;
};

export const Bio = ({ html }: { html?: string }) => {
if (!html || !containsText(html)) return null;
const sanitizedHtml = sanitise(html, {});
return (
<>
<div
css={bioStyles}
dangerouslySetInnerHTML={{ __html: sanitizedHtml }}
/>
<div css={bottomBorderStyles} />
</>
);
};
1 change: 1 addition & 0 deletions dotcom-rendering/src/components/Elements.amp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const listElements = [
'model.dotcomrendering.pageElements.KeyTakeawaysBlockElement',
'model.dotcomrendering.pageElements.ListBlockElement',
'model.dotcomrendering.pageElements.MiniProfilesBlockElement',
'model.dotcomrendering.pageElements.MultiBylinesBlockElement',
'model.dotcomrendering.pageElements.TimelineBlockElement',
'model.dotcomrendering.pageElements.QAndAExplainerBlockElement',
];
Expand Down
18 changes: 18 additions & 0 deletions dotcom-rendering/src/components/EndNote.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { css } from '@emotion/react';
import { space, textSans14 } from '@guardian/source/foundations';
import { palette } from '../palette';

const endNoteStyles = css`
${textSans14};
color: ${palette('--end-note-text-subdued')};
margin-bottom: ${space[3]}px;
`;

export const EndNote = ({ text }: { text?: string }) => {
if (!text) return null;
return (
<p css={endNoteStyles}>
<em>{text}</em>
</p>
);
};
4 changes: 2 additions & 2 deletions dotcom-rendering/src/components/KeyTakeaways.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { css } from '@emotion/react';
import { palette } from '@guardian/source/foundations';
import type { ArticleFormat } from '../lib/articleFormat';
import type { EditionId } from '../lib/edition';
import type { ArticleElementRenderer } from '../lib/renderElement';
import { palette } from '../palette';
import type { ServerSideTests, Switches } from '../types/config';
import type { KeyTakeaway, StarRating } from '../types/content';
import { KeyTakeaway as KeyTakeawayComponent } from './KeyTakeaway';
Expand Down Expand Up @@ -30,7 +30,7 @@ interface KeyTakeawaysProps {
const separatorStyles = css`
width: 140px;
margin: 8px 0 2px 0;
border-top: 1px solid ${palette.neutral[86]};
border-top: 1px solid ${palette('--article-border')};
`;

export const KeyTakeaways = ({
Expand Down
96 changes: 3 additions & 93 deletions dotcom-rendering/src/components/MiniProfile.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { css } from '@emotion/react';
import { neutral, space, textSans14 } from '@guardian/source/foundations';
import sanitise from 'sanitize-html';
import { space } from '@guardian/source/foundations';
import type { ArticleFormat } from '../lib/articleFormat';
import { slugify } from '../model/enhance-H2s';
import { palette } from '../palette';
import type { MiniProfile as MiniProfileModel } from '../types/content';
import { Bio } from './Bio';
import { EndNote } from './EndNote';
import { Heading } from './Heading';
import { headingLineStyles } from './KeyTakeaway';
import { subheadingStyles } from './Subheading';
Expand All @@ -13,65 +13,6 @@ const miniProfileStyles = css`
padding-top: 8px;
`;

/** Nesting is necessary in the bio styles because we receive a string of html from the
* field. This can contain the following tags:
* Blocks: p, ul, li
* Inline: strong, em, a
*/
const bioStyles = css`
${textSans14};
padding: ${space[1]}px 0;
color: ${palette('--mini-profiles-text-subdued')};
p {
margin-bottom: ${space[2]}px;
}
a {
color: ${palette('--link-kicker-text')};
text-underline-offset: 3px;
}
a:not(:hover) {
text-decoration-color: ${neutral[86]};
}
a:hover {
text-decoration: underline;
}
ul {
list-style: none;
margin: 0 0 ${space[2]}px;
padding: 0;
}
ul li {
padding-left: ${space[5]}px;
}
ul li p {
display: inline-block;
margin-bottom: 0;
}
ul li:before {
display: inline-block;
content: '';
border-radius: 0.375rem;
height: 10px;
width: 10px;
margin: 0 ${space[2]}px 0 -${space[5]}px;
background-color: ${palette('--bullet-fill')};
}
strong {
font-weight: bold;
}
`;

const endNoteStyles = css`
${textSans14};
color: ${palette('--mini-profiles-text-subdued')};
margin-bottom: ${space[3]}px;
`;

const bottomBorderStyles = css`
border-top: 1px solid ${palette('--article-border')};
margin-bottom: ${space[2]}px;
`;

const headingMarginStyle = css`
margin-bottom: ${space[2]}px;
`;
Expand Down Expand Up @@ -115,34 +56,3 @@ export const MiniProfile = ({
</>
);
};

const containsText = (html: string) => {
const htmlWithoutTags = sanitise(html, {
allowedTags: [],
allowedAttributes: {},
});
return htmlWithoutTags.length > 0;
};

const Bio = ({ html }: { html?: string }) => {
if (!html || !containsText(html)) return null;
const sanitizedHtml = sanitise(html, {});
return (
<>
<div
css={bioStyles}
dangerouslySetInnerHTML={{ __html: sanitizedHtml }}
/>
<div css={bottomBorderStyles} />
</>
);
};

const EndNote = ({ text }: { text?: string }) => {
if (!text) return null;
return (
<p css={endNoteStyles}>
<em>{text}</em>
</p>
);
};
4 changes: 2 additions & 2 deletions dotcom-rendering/src/components/MiniProfiles.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { css } from '@emotion/react';
import { palette } from '@guardian/source/foundations';
import type { ArticleFormat } from '../lib/articleFormat';
import type { EditionId } from '../lib/edition';
import type { ArticleElementRenderer } from '../lib/renderElement';
import { palette } from '../palette';
import type { ServerSideTests, Switches } from '../types/config';
import type { MiniProfile, StarRating } from '../types/content';
import { MiniProfile as MiniProfileComponent } from './MiniProfile';
Expand Down Expand Up @@ -31,7 +31,7 @@ interface MiniProfilesProps {
const separatorStyles = css`
width: 140px;
margin: 8px 0 2px 0;
border-top: 1px solid ${palette.neutral[86]};
border-top: 1px solid ${palette('--article-border')};
`;

export const MiniProfiles = ({
Expand Down
Loading
Loading