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

feat: poc generated image #10432

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
10 changes: 10 additions & 0 deletions packages/docusaurus-theme-classic/src/theme-classic.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,16 @@ declare module '@theme/Blog/Components/Author/Socials' {
export default function BlogAuthorSocials(props: Props): JSX.Element;
}

declare module '@theme/Blog/Components/Author/GeneratedImage' {
export interface Props {
readonly name: string;
readonly link?: string;
readonly className?: string;
}

export default function GeneratedImage(props: Props): JSX.Element;
}

declare module '@theme/BlogListPaginator' {
import type {BlogPaginatedMetadata} from '@docusaurus/plugin-content-blog';

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import React from 'react';
import clsx from 'clsx';
import Link, {type Props as LinkProps} from '@docusaurus/Link';
import type {Props} from '@theme/Blog/Components/Author/GeneratedImage';

function MaybeLink(props: LinkProps): JSX.Element {
if (props.href) {
return <Link {...props} />;
}
return <>{props.children}</>;
}

export default function GeneratedImage({
name,
link,
className,
}: Props): JSX.Element {
return (
<MaybeLink href={link} className="avatar__photo-link">
OzakIOne marked this conversation as resolved.
Show resolved Hide resolved
<svg
OzakIOne marked this conversation as resolved.
Show resolved Hide resolved
className={clsx('avatar__photo', className)}
viewBox="0 0 72 72"
xmlns="http://www.w3.org/2000/svg">
<defs>
<linearGradient id="greyGradient" x1="0" y1="0" x2="1" y2="1">
<stop offset="0%" style={{stopColor: '#ccc', stopOpacity: 1}} />
<stop offset="100%" style={{stopColor: '#777', stopOpacity: 1}} />
OzakIOne marked this conversation as resolved.
Show resolved Hide resolved
</linearGradient>
</defs>
<circle cx="36" cy="36" r="36" fill="url(#greyGradient)" />
<text
x="50%"
y="50%"
textAnchor="middle"
alignmentBaseline="central"
fontSize="2rem"
fill="#fff">
{name[0]?.toLocaleUpperCase()}
OzakIOne marked this conversation as resolved.
Show resolved Hide resolved
</text>
</svg>
</MaybeLink>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Link, {type Props as LinkProps} from '@docusaurus/Link';
import AuthorSocials from '@theme/Blog/Components/Author/Socials';
import type {Props} from '@theme/Blog/Components/Author';
import Heading from '@theme/Heading';
import GeneratedImage from '@theme/Blog/Components/Author/GeneratedImage';
import styles from './styles.module.css';

function MaybeLink(props: LinkProps): JSX.Element {
Expand Down Expand Up @@ -65,14 +66,20 @@ export default function BlogAuthor({
className,
styles[`author-as-${as}`],
)}>
{imageURL && (
{imageURL ? (
<MaybeLink href={link} className="avatar__photo-link">
<img
className={clsx('avatar__photo', styles.authorImage)}
src={imageURL}
alt={name}
/>
</MaybeLink>
) : (
<GeneratedImage
name={name!}
link={link}
className={clsx(styles.authorImage)}
/>
)}

{(name || title) && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

.authorImage {
--ifm-avatar-photo-size: 3.6rem;
background: grey;
OzakIOne marked this conversation as resolved.
Show resolved Hide resolved
}

.author-as-h1 .authorImage {
Expand Down
8 changes: 8 additions & 0 deletions website/_dogfooding/_blog tests/authors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,11 @@ slorber:
ozaki:
name: ozaki
page: {permalink: '/custom/ozaki/permalink'}

john:
name: John Doe
page: true

bob:
name: Bob Smith
page: true