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

Adds twitter "related" tag #281

Merged
merged 4 commits into from
Mar 14, 2020
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ import {
| RedditShareButton | - | **`title`** (string): Title of the shared page |
| TelegramShareButton | - | **`title`** (string): Title of the shared page<br/> |
| TumblrShareButton | - | **`title`** (string): Title of the shared page<br/>**`tags`**: (`Array<string>`)<br/>**`caption`** (string): Description of the shared page<br/>**`posttype`** (string, default=`link`) |
| TwitterShareButton | - | **`title`** (string): Title of the shared page<br/>**`via`**: (string)<br/>**`hashtags`** (array): Hashtags |
| TwitterShareButton | - | **`title`** (string): Title of the shared page<br/>**`via`**: (string)<br/>**`hashtags`** (array): Hashtags<br/>**`related`** (array): Accounts to recommend following |
| ViberShareButton | - | **`title`** (string): Title of the shared page<br/>**`separator`** (string), default=`" "`: Separates title from the url |
| VKShareButton | - | **`title`** (string): Title of the shared page<br/>**`image`** (string): An absolute link to the image that will be shared<br/>**`noParse`** (boolean): If true is passed, VK will not retrieve URL information<br/>**`noVkLinks`** (boolean): If true is passed, there will be no links to the user's profile in the open window. Only for mobile devices |
| WeiboShareButton | - | **`title`** (string): Title of the shared page<br/>**`image`** (string): An absolute link to the image that will be shared |
Expand Down
17 changes: 15 additions & 2 deletions src/TwitterShareButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ import createShareButton from './hocs/createShareButton';

function twitterLink(
url: string,
{ title, via, hashtags = [] }: { title?: string; via?: string; hashtags?: string[] },
{
title,
via,
hashtags = [],
related = [],
}: { title?: string; via?: string; hashtags?: string[]; related?: string[] },
) {
assert(url, 'twitter.url');
assert(Array.isArray(hashtags), 'twitter.hashtags is not an array');
assert(Array.isArray(related), 'twitter.related is not an array');

return (
'https://twitter.com/share' +
Expand All @@ -17,17 +23,24 @@ function twitterLink(
text: title,
via,
hashtags: hashtags.length > 0 ? hashtags.join(',') : undefined,
related: related.join(','),
})
);
}

const TwitterShareButton = createShareButton<{ title?: string; via?: string; hashtags?: string[] }>(
const TwitterShareButton = createShareButton<{
title?: string;
via?: string;
hashtags?: string[];
related?: string[];
}>(
'twitter',
twitterLink,
props => ({
hashtags: props.hashtags,
title: props.title,
via: props.via,
related: props.related,
}),
{
windowWidth: 550,
Expand Down