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 all 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,18 @@
/**
* 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 type {Props} from '@theme/Blog/Components/Author/GeneratedImage';

export default function GeneratedImage({name, className}: Props): JSX.Element {
return (
<div className={clsx('avatar__photo', className)}>
{name[0]?.toLocaleUpperCase()}
</div>
);
}
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,22 @@ 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>
) : (
<MaybeLink href={link} className="avatar__photo-link">
<GeneratedImage
name={name!}
link={link}
className={clsx(styles.authorImage, styles.authorGeneratedImage)}
/>
</MaybeLink>
)}

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

.authorImage {
--ifm-avatar-photo-size: 3.6rem;
background: var(--ifm-color-emphasis-200);
}

.author-as-h1 .authorImage {
--ifm-avatar-photo-size: 7rem;
}

.authorGeneratedImage {
display: flex;
justify-content: center;
align-items: center;
color: var(--ifm-color-emphasis-0);
font-size: 2rem;
background: linear-gradient(
135deg,
var(--ifm-color-emphasis-700) 0%,
var(--ifm-color-emphasis-1000) 100%
);
}

[data-theme='dark'] .authorGeneratedImage {
background: linear-gradient(
135deg,
var(--ifm-color-emphasis-800) 0%,
var(--ifm-color-emphasis-200) 100%
);
}

.author-as-h2 .authorImage {
--ifm-avatar-photo-size: 5.4rem;
}
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