Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ describe('normalizeSocials', () => {
twitch: 'gingergeek',
youtube: 'gingergeekuk',
mastodon: 'Mastodon',
email: 'seb@example.com',
};

expect(normalizeSocials(socials)).toMatchInlineSnapshot(`
{
"bluesky": "https://bsky.app/profile/gingergeek.co.uk",
"email": "mailto:seb@example.com",
"github": "https://github.com/ozakione",
"instagram": "https://www.instagram.com/thisweekinreact",
"linkedin": "https://www.linkedin.com/in/ozakione/",
Expand All @@ -48,11 +50,13 @@ describe('normalizeSocials', () => {
instaGRam: 'thisweekinreact',
BLUESKY: 'gingergeek.co.uk',
tHrEaDs: 'gingergeekuk',
eMAil: 'seb@example.com',
};

expect(normalizeSocials(socials)).toMatchInlineSnapshot(`
{
"bluesky": "https://bsky.app/profile/gingergeek.co.uk",
"email": "mailto:seb@example.com",
"github": "https://github.com/ozakione",
"instagram": "https://www.instagram.com/thisweekinreact",
"linkedin": "https://www.linkedin.com/in/ozakione/",
Expand All @@ -69,6 +73,7 @@ describe('normalizeSocials', () => {
linkedin: 'https://linkedin.com/ozakione',
github: 'https://github.com/ozakione',
stackoverflow: 'https://stackoverflow.com/ozakione',
email: 'mailto:seb@example.com',
};

expect(normalizeSocials(socials)).toEqual(socials);
Expand All @@ -81,10 +86,12 @@ describe('normalizeSocials', () => {
github: 'https://github.com/ozakione',
stackoverflow: 'https://stackoverflow.com/ozakione',
mastodon: 'https://hachyderm.io/@hachyderm',
email: 'mailto:seb@example.com',
};

expect(normalizeSocials(socials)).toMatchInlineSnapshot(`
{
"email": "mailto:seb@example.com",
"github": "https://github.com/ozakione",
"linkedin": "https://www.linkedin.com/in/ozakione/",
"mastodon": "https://hachyderm.io/@hachyderm",
Expand Down
8 changes: 6 additions & 2 deletions packages/docusaurus-plugin-content-blog/src/authorsSocials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const AuthorSocialsSchema = Joi.object<AuthorSocials>({
mastodon: Joi.string(),
twitch: Joi.string(),
youtube: Joi.string(),
email: Joi.string(),
}).unknown();

type PredefinedPlatformNormalizer = (value: string) => string;
Expand All @@ -47,20 +48,22 @@ const PredefinedPlatformNormalizers: Record<
mastodon: (handle: string) => `https://mastodon.social/@${handle}`, // can be in format user@other.server and it will redirect if needed
twitch: (handle: string) => `https://twitch.tv/${handle}`,
youtube: (handle: string) => `https://youtube.com/@${handle}`, // https://support.google.com/youtube/answer/6180214?hl=en
email: (email: string) => `mailto:${email}`,
};

type SocialEntry = [string, string];

function normalizeSocialEntry([platform, value]: SocialEntry): SocialEntry {
const normalizer = PredefinedPlatformNormalizers[platform.toLowerCase()];
if (typeof value !== 'string') {
throw new Error(
`Author socials should be usernames/userIds/handles, or fully qualified HTTP(s) absolute URLs.
Social platform '${platform}' has illegal value '${value}'`,
);
}
const isAbsoluteUrl =
value.startsWith('http://') || value.startsWith('https://');
value.startsWith('http://') ||
value.startsWith('https://') ||
value.startsWith('mailto:');
if (isAbsoluteUrl) {
return [platform, value];
} else if (value.includes('/')) {
Expand All @@ -69,6 +72,7 @@ Social platform '${platform}' has illegal value '${value}'`,
Social platform '${platform}' has illegal value '${value}'`,
);
}
const normalizer = PredefinedPlatformNormalizers[platform.toLowerCase()];
if (normalizer && !isAbsoluteUrl) {
const normalizedPlatform = platform.toLowerCase();
const normalizedValue = normalizer(value);
Expand Down
8 changes: 8 additions & 0 deletions packages/docusaurus-theme-classic/src/theme-classic.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1894,6 +1894,14 @@ declare module '@theme/Icon/Socials/Twitch' {
export default function Twitch(props: Props): ReactNode;
}

declare module '@theme/Icon/Socials/Email' {
import type {ComponentProps, ReactNode} from 'react';

export interface Props extends ComponentProps<'svg'> {}

export default function Email(props: Props): ReactNode;
}

declare module '@theme/Icon/Socials/Mastodon' {
import type {ComponentProps, ReactNode} from 'react';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import Threads from '@theme/Icon/Socials/Threads';
import Youtube from '@theme/Icon/Socials/YouTube';
import Mastodon from '@theme/Icon/Socials/Mastodon';
import Twitch from '@theme/Icon/Socials/Twitch';
import Email from '@theme/Icon/Socials/Email';

import styles from './styles.module.css';

Expand All @@ -42,6 +43,7 @@ const SocialPlatformConfigs: Record<string, SocialPlatformConfig> = {
mastodon: {Icon: Mastodon, label: 'Mastodon'},
youtube: {Icon: Youtube, label: 'YouTube'},
twitch: {Icon: Twitch, label: 'Twitch'},
email: {Icon: Email, label: 'Email'},
};

function getSocialPlatformConfig(platformKey: string): SocialPlatformConfig {
Expand All @@ -57,7 +59,7 @@ function SocialLink({platform, link}: {platform: string; link: string}) {
const {Icon, label} = getSocialPlatformConfig(platform);
return (
<Link className={styles.authorSocialLink} href={link} title={label}>
<Icon className={clsx(styles.authorSocialLink)} />
<Icon className={clsx(styles.authorSocialIcon)} />
</Link>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import type {ReactNode, SVGProps} from 'react';

// SVG Source: https://tabler.io/
// SVG Source: https://github.com/tabler/tabler-icons
function DefaultSocial(props: SVGProps<SVGSVGElement>): ReactNode {
return (
<svg
Expand All @@ -22,11 +22,11 @@ function DefaultSocial(props: SVGProps<SVGSVGElement>): ReactNode {
strokeLinejoin="round"
{...props}>
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path d="M3 12a9 9 0 1 0 18 0a9 9 0 0 0 -18 0" />
<path d="M3.6 9h16.8" />
<path d="M3.6 15h16.8" />
<path d="M11.5 3a17 17 0 0 0 0 18" />
<path d="M12.5 3a17 17 0 0 1 0 18" />
<path d="M1.2 12a10.8 10.8 0 1 0 21.6 0a10.8 10.8 0 0 0 -21.6 0" />
<path d="M1.92 8.4h20.16" />
<path d="M1.92 15.6h20.16" />
<path d="M11.4 1.2a20.4 20.4 0 0 0 0 21.6" />
<path d="M12.6 1.2a20.4 20.4 0 0 1 0 21.6" />
</svg>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* 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 type {ReactNode, SVGProps} from 'react';

// SVG Source: https://github.com/tabler/tabler-icons
function Email(props: SVGProps<SVGSVGElement>): ReactNode {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
{...props}>
<path stroke="none" d="M0 0h24v24H0z" />
<path d="M7.2 12a4.8 4.8 0 1 0 9.6 0 4.8 4.8 0 1 0-9.6 0" />
<path d="M16.8 12v1.8a3 3 0 0 0 6 0V12a10.8 10.8 0 1 0-6.6 9.936" />
</svg>
);
}
export default Email;
10 changes: 9 additions & 1 deletion packages/docusaurus-theme-classic/src/theme/Tabs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import React, {cloneElement, type ReactElement, type ReactNode} from 'react';
import clsx from 'clsx';
import {ThemeClassNames} from '@docusaurus/theme-common';
import {
useScrollPositionBlocker,
useTabs,
Expand Down Expand Up @@ -143,7 +144,14 @@ function TabContent({
function TabsComponent(props: Props): ReactNode {
const tabs = useTabs(props);
return (
<div className={clsx('tabs-container', styles.tabList)}>
<div
className={clsx(
ThemeClassNames.tabs.container,
// former name kept for backward compatibility
// see https://github.com/facebook/docusaurus/pull/4086
'tabs-container',
styles.tabList,
)}>
<TabList {...tabs} {...props} />
<TabContent {...tabs} {...props} />
</div>
Expand Down
4 changes: 4 additions & 0 deletions packages/docusaurus-theme-common/src/utils/ThemeClassNames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ export const ThemeClassNames = {
container: 'theme-announcement-bar',
},

tabs: {
container: 'theme-tabs-container',
},

layout: {
navbar: {
container: 'theme-layout-navbar',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ authors:
linkedin: https://www.linkedin.com/in/sebastienlorber/
instagram: https://www.instagram.com/thisweekinreact/
newsletter: https://thisweekinreact.com/newsletter
email: seb@example.com
- name: Sébastien Lorber
imageURL: https://github.com/slorber.png
socials:
Expand Down
1 change: 1 addition & 0 deletions website/_dogfooding/_blog tests/authors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ slorber:
page: true
socials:
x: sebastienlorber
email: seb@example.com

ozaki:
name: ozaki
Expand Down
3 changes: 2 additions & 1 deletion website/docs/api/plugins/plugin-content-blog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ type AuthorKey = string;
// Social platform name -> Social platform link
// Example: {MyPlatform: 'https://myplatform.com/myusername'}
// Pre-defined platforms
// ("x", "github", "twitter", "linkedin", "stackoverflow", "instagram", "bluesky", "mastodon", "threads", "twitch", "youtube") accept handles:
// ("x", "github", "twitter", "linkedin", "stackoverflow", "instagram", "bluesky", "mastodon", "threads", "twitch", "youtube", "email") accept handles:
// Example: {github: 'slorber'}
type AuthorSocials = Record<string, string>;

Expand Down Expand Up @@ -368,6 +368,7 @@ slorber:
socials:
x: sebastienlorber
github: slorber
email: seb@example.com

jmarcey:
name: Joel Marcey
Expand Down
2 changes: 2 additions & 0 deletions website/docs/blog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ authors:
socials:
x: sebastienlorber
github: slorber
email: seb@example.com
tags: [hello, docusaurus-v2]
image: https://i.imgur.com/mErPwqL.png
hide_table_of_contents: false
Expand Down Expand Up @@ -303,6 +304,7 @@ slorber:
socials:
x: sebastienlorber
github: slorber
email: seb@example.com
```

:::tip
Expand Down
Loading