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(blog): author header social icons #10222

Merged
merged 40 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
27479a4
feat(blog): author header social icons
OzakIOne Jun 17, 2024
c3a8ad5
update style
OzakIOne Jun 17, 2024
51a8e08
refactor: review
OzakIOne Jun 20, 2024
7c45cfc
refactor: apply lint autofix
OzakIOne Jun 20, 2024
a93f742
remove unused class
OzakIOne Jun 20, 2024
685b2fe
refactor: apply lint autofix
OzakIOne Jun 20, 2024
30022fc
Merge branch 'main' into ozaki/blogSocialIcons
slorber Jul 1, 2024
0ab5afd
add tests and move normalize outside of joi
OzakIOne Jul 2, 2024
be05dc7
add test
OzakIOne Jul 2, 2024
eb4a2fc
wip
OzakIOne Jul 2, 2024
0c26f22
add default icon & refactor code
OzakIOne Jul 3, 2024
e98b0ed
refactor: apply lint autofix
OzakIOne Jul 3, 2024
dec190e
fix css
OzakIOne Jul 3, 2024
39d7403
add dogfood ui
OzakIOne Jul 3, 2024
0e19baf
add tests
OzakIOne Jul 5, 2024
f83e860
fix links
OzakIOne Jul 6, 2024
bb08c72
fix links
OzakIOne Jul 6, 2024
9395d5f
Merge branch 'main' into ozaki/blogSocialIcons
slorber Jul 11, 2024
45e4950
adjust design of blog author social icons
slorber Jul 11, 2024
7ad8bed
refactor: apply lint autofix
slorber Jul 11, 2024
eb5522f
correct casing for GitHub
slorber Jul 11, 2024
a2071f9
Merge remote-tracking branch 'origin/ozaki/blogSocialIcons' into ozak…
slorber Jul 11, 2024
3429481
Fix Icon/Socials swizzle config
slorber Jul 11, 2024
7905a5b
fix blog author socials
slorber Jul 11, 2024
fd2b81a
add test case for normalizeSocials
slorber Jul 11, 2024
8641bef
Ensure author socials normalization is wired properly
slorber Jul 11, 2024
9ed1e6a
refactor: apply lint autofix
slorber Jul 11, 2024
ccc6a04
Extract AuthorSocials component + fix JS comments + docs
slorber Jul 11, 2024
d19480d
Add socials to init template
slorber Jul 11, 2024
5e1723f
Add socials to init template + newsletter extra as a demo
slorber Jul 11, 2024
605ceed
better blog author socials normalization
slorber Jul 11, 2024
229c4c2
Add authors slorber linkedin platform
slorber Jul 11, 2024
b3d5942
fix SO social platforms
slorber Jul 11, 2024
4975427
refactor: apply lint autofix
slorber Jul 11, 2024
c01fe89
Joi schema should validate inline socials
slorber Jul 12, 2024
e0b54ae
Merge remote-tracking branch 'origin/ozaki/blogSocialIcons' into ozak…
slorber Jul 12, 2024
9005a4f
refactor: apply lint autofix
slorber Jul 12, 2024
91ca3af
remove word
slorber Jul 12, 2024
f8dc2f8
Merge remote-tracking branch 'origin/ozaki/blogSocialIcons' into ozak…
slorber Jul 12, 2024
42dae65
remove word
slorber Jul 12, 2024
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 @@ -9,9 +9,17 @@ yangshun:
title: Front End Engineer @ Facebook
url: https://github.com/yangshun
image_url: https://github.com/yangshun.png
socials:
x: yangshunz
github: yangshun

slorber:
name: Sébastien Lorber
title: Docusaurus maintainer
url: https://sebastienlorber.com
image_url: https://github.com/slorber.png
socials:
x: sebastienlorber
linkedin: sebastienlorber
github: slorber
newsletter: https://thisweekinreact.com

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,52 @@ describe('getBlogPostAuthors', () => {
]);
});

it('can normalize inline authors', () => {
expect(
getBlogPostAuthors({
frontMatter: {
authors: [
{
name: 'Seb1',
socials: {
x: 'https://x.com/sebastienlorber',
twitter: 'sebastienlorber',
github: 'slorber',
},
},
{
name: 'Seb2',
socials: {
x: 'sebastienlorber',
twitter: 'https://twitter.com/sebastienlorber',
github: 'https://github.com/slorber',
},
},
],
},
authorsMap: {},
baseUrl: '/',
}),
).toEqual([
{
name: 'Seb1',
socials: {
x: 'https://x.com/sebastienlorber',
twitter: 'https://twitter.com/sebastienlorber',
github: 'https://github.com/slorber',
},
},
{
name: 'Seb2',
socials: {
x: 'https://x.com/sebastienlorber',
twitter: 'https://twitter.com/sebastienlorber',
github: 'https://github.com/slorber',
},
},
]);
});

it('throw when using author key with no authorsMap', () => {
expect(() =>
getBlogPostAuthors({
Expand Down Expand Up @@ -412,6 +458,29 @@ describe('getAuthorsMap', () => {
}),
).resolves.toBeUndefined();
});

describe('getAuthorsMap returns normalized', () => {
it('socials', async () => {
const authorsMap = await getAuthorsMap({
contentPaths,
authorsMapPath: 'authors.yml',
});
expect(authorsMap.slorber.socials).toMatchInlineSnapshot(`
{
"stackoverflow": "https://stackoverflow.com/users/82609",
"twitter": "https://twitter.com/sebastienlorber",
"x": "https://x.com/sebastienlorber",
}
`);
expect(authorsMap.JMarcey.socials).toMatchInlineSnapshot(`
{
"stackoverflow": "https://stackoverflow.com/users/102705/Joel-Marcey",
"twitter": "https://twitter.com/JoelMarcey",
"x": "https://x.com/JoelMarcey",
}
`);
});
});
});

describe('validateAuthorsMap', () => {
Expand Down Expand Up @@ -529,3 +598,68 @@ describe('validateAuthorsMap', () => {
);
});
});

describe('authors socials', () => {
it('valid known author map socials', () => {
const authorsMap: AuthorsMap = {
ozaki: {
name: 'ozaki',
socials: {
twitter: 'ozakione',
github: 'ozakione',
},
},
};

expect(validateAuthorsMap(authorsMap)).toEqual(authorsMap);
});

it('throw socials that are not strings', () => {
const authorsMap: AuthorsMap = {
ozaki: {
name: 'ozaki',
socials: {
// @ts-expect-error: for tests
twitter: 42,
},
},
};

expect(() =>
validateAuthorsMap(authorsMap),
).toThrowErrorMatchingInlineSnapshot(
`""ozaki.socials.twitter" must be a string"`,
);
});

it('throw socials that are objects', () => {
const authorsMap: AuthorsMap = {
ozaki: {
name: 'ozaki',
socials: {
// @ts-expect-error: for tests
twitter: {link: 'ozakione'},
},
},
};

expect(() =>
validateAuthorsMap(authorsMap),
).toThrowErrorMatchingInlineSnapshot(
`""ozaki.socials.twitter" must be a string"`,
);
});

it('valid unknown author map socials', () => {
const authorsMap: AuthorsMap = {
ozaki: {
name: 'ozaki',
socials: {
random: 'ozakione',
},
},
};

expect(validateAuthorsMap(authorsMap)).toEqual(authorsMap);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/**
* 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 {normalizeSocials} from '../authorsSocials';
import type {AuthorSocials} from '@docusaurus/plugin-content-blog';

describe('normalizeSocials', () => {
it('only username', () => {
const socials: AuthorSocials = {
twitter: 'ozakione',
linkedin: 'ozakione',
github: 'ozakione',
stackoverflow: 'ozakione',
};

expect(normalizeSocials(socials)).toMatchInlineSnapshot(`
{
"github": "https://github.com/ozakione",
"linkedin": "https://www.linkedin.com/in/ozakione/",
"stackoverflow": "https://stackoverflow.com/users/ozakione",
"twitter": "https://twitter.com/ozakione",
}
`);
});

it('only username - case insensitive', () => {
const socials: AuthorSocials = {
Twitter: 'ozakione',
linkedIn: 'ozakione',
gitHub: 'ozakione',
STACKoverflow: 'ozakione',
};

expect(normalizeSocials(socials)).toMatchInlineSnapshot(`
{
"github": "https://github.com/ozakione",
"linkedin": "https://www.linkedin.com/in/ozakione/",
"stackoverflow": "https://stackoverflow.com/users/ozakione",
"twitter": "https://twitter.com/ozakione",
}
`);
});

it('only links', () => {
const socials: AuthorSocials = {
twitter: 'https://x.com/ozakione',
linkedin: 'https://linkedin.com/ozakione',
github: 'https://github.com/ozakione',
stackoverflow: 'https://stackoverflow.com/ozakione',
};

expect(normalizeSocials(socials)).toEqual(socials);
});

it('mixed links', () => {
const socials: AuthorSocials = {
twitter: 'ozakione',
linkedin: 'ozakione',
github: 'https://github.com/ozakione',
stackoverflow: 'https://stackoverflow.com/ozakione',
};

expect(normalizeSocials(socials)).toMatchInlineSnapshot(`
{
"github": "https://github.com/ozakione",
"linkedin": "https://www.linkedin.com/in/ozakione/",
"stackoverflow": "https://stackoverflow.com/ozakione",
"twitter": "https://twitter.com/ozakione",
}
`);
});

it('one link', () => {
const socials: AuthorSocials = {
twitter: 'ozakione',
};

expect(normalizeSocials(socials)).toMatchInlineSnapshot(`
{
"twitter": "https://twitter.com/ozakione",
}
`);
});

it('rejects strings that do not look like username/userId/handle or fully-qualified URLs', () => {
const socials: AuthorSocials = {
twitter: '/ozakione/XYZ',
};

expect(() => normalizeSocials(socials)).toThrowErrorMatchingInlineSnapshot(`
"Author socials should be usernames/userIds/handles, or fully qualified HTTP(s) absolute URLs.
Social platform 'twitter' has illegal value '/ozakione/XYZ'"
`);
});

it('allow other form of urls', () => {
const socials: AuthorSocials = {
twitter: 'https://bit.ly/sebastienlorber-twitter',
};

expect(normalizeSocials(socials)).toEqual(socials);
});

it('allow unknown social platforms urls', () => {
const socials: AuthorSocials = {
twitch: 'https://www.twitch.tv/sebastienlorber',
newsletter: 'https://thisweekinreact.com',
};

expect(normalizeSocials(socials)).toEqual(socials);
});
});
Loading