-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(blog): author header social icons (#10222)
Co-authored-by: OzakIOne <[email protected]> Co-authored-by: sebastien <[email protected]> Co-authored-by: slorber <[email protected]>
- Loading branch information
1 parent
8b877d2
commit a6de0f2
Showing
35 changed files
with
1,004 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 8 additions & 2 deletions
10
...ges/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/authorsMapFiles/authors.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
...rc/__tests__/__fixtures__/website/blog/2018-12-14-Happy-First-Birthday-Slash.md
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
packages/docusaurus-plugin-content-blog/src/__tests__/__fixtures__/website/blog/authors.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
packages/docusaurus-plugin-content-blog/src/__tests__/authorsSocials.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
Oops, something went wrong.