Skip to content

Commit f3391db

Browse files
Move MetaTags from utils lib to community-app
1 parent 1bb3ae0 commit f3391db

File tree

12 files changed

+98
-11
lines changed

12 files changed

+98
-11
lines changed

src/shared/components/Contentful/Route.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import _ from 'lodash';
77
import ContentfulLoader from 'containers/ContentfulLoader';
88
import Error404 from 'components/Error404';
99
import LoadingIndicator from 'components/LoadingIndicator';
10-
import { MetaTags } from 'topcoder-react-utils';
10+
import MetaTags from 'components/MetaTags';
1111
import PT from 'prop-types';
1212
import React from 'react';
1313
import { Route, Switch } from 'react-router-dom';

src/shared/components/MetaTags.jsx

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/**
2+
* Auxiliary wrapper around React Helmet that helps to generate meta tags for
3+
* generic use cases.
4+
*
5+
* NOTE: This component relies on `domain` path of Redux store to hold
6+
* the current app domain, which will serve as the base path for the bundled
7+
* images.
8+
*/
9+
10+
import PT from 'prop-types';
11+
import React from 'react';
12+
import { connect } from 'react-redux';
13+
import { Helmet } from 'react-helmet';
14+
15+
function MetaTags({
16+
description,
17+
domain,
18+
image,
19+
siteName,
20+
socialDescription,
21+
socialTitle,
22+
title,
23+
url,
24+
}) {
25+
const img = `${domain}${image}`;
26+
const socTitle = socialTitle || title;
27+
const socDesc = socialDescription || description;
28+
return (
29+
<Helmet>
30+
{/* General tags. */}
31+
<title>
32+
{title}
33+
</title>
34+
<meta name="description" content={description} />
35+
36+
{/* Twitter cards. */}
37+
<meta name="twitter:card" content="summary_large_image" />
38+
<meta name="twitter:title" content={socTitle} />
39+
<meta name="twitter:description" content={socDesc} />
40+
{ image ? <meta name="twitter:image" content={img} /> : null }
41+
{
42+
siteName ? (
43+
<meta name="twitter:site" content={`@${siteName}`} />
44+
) : null
45+
}
46+
47+
{/* Open Graph data. */}
48+
<meta property="og:title" content={socTitle} />
49+
{ image ? <meta property="og:image" content={img} /> : null }
50+
{ image ? <meta property="og:image:alt" content={socTitle} /> : null }
51+
<meta property="og:description" content={socDesc} />
52+
{
53+
siteName ? (<meta property="og:sitename" content={siteName} />) : null
54+
}
55+
{ url ? (<meta property="og:url" content={url} />) : null }
56+
</Helmet>
57+
);
58+
}
59+
60+
MetaTags.defaultProps = {
61+
image: null,
62+
siteName: null,
63+
socialDescription: null,
64+
socialTitle: null,
65+
url: null,
66+
};
67+
68+
MetaTags.propTypes = {
69+
description: PT.string.isRequired,
70+
domain: PT.string.isRequired,
71+
image: PT.string,
72+
siteName: PT.string,
73+
socialDescription: PT.string,
74+
socialTitle: PT.string,
75+
title: PT.string.isRequired,
76+
url: PT.string,
77+
};
78+
79+
/* TODO: It is not good to depend on the domain written into redux state here,
80+
* better pass it via the renderer context at the server side, and get it from
81+
* the location at the frontend side, or something similar? */
82+
export default connect(state => ({ domain: state.domain }))(MetaTags);

src/shared/components/Settings/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44
import React from 'react';
55
import PT from 'prop-types';
6-
import { MetaTags } from 'topcoder-react-utils';
6+
import MetaTags from 'components/MetaTags';
77

88
import { TABS } from 'actions/page/settings';
99

src/shared/containers/Profile.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import PT from 'prop-types';
77
import { connect } from 'react-redux';
88

99
import { actions } from 'topcoder-react-lib';
10-
import { MetaTags } from 'topcoder-react-utils';
10+
import MetaTags from 'components/MetaTags';
1111
import Error404 from 'components/Error404';
1212
import LoadingIndicator from 'components/LoadingIndicator';
1313
import ProfilePage from 'components/ProfilePage';

src/shared/containers/ProfileStats.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Error404 from 'components/Error404';
99
import LoadingIndicator from 'components/LoadingIndicator';
1010
import ProfileStatsPage from 'components/ProfilePage/Stats';
1111
import { shouldShowGraph, isValidTrack } from 'utils/memberStats';
12-
import { MetaTags } from 'topcoder-react-utils';
12+
import MetaTags from 'components/MetaTags';
1313
import _ from 'lodash';
1414
import qs from 'qs';
1515

src/shared/containers/challenge-detail/index.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ import {
3939
SUBTRACKS,
4040
CHALLENGE_STATUS,
4141
} from 'utils/tc';
42-
import { config, MetaTags } from 'topcoder-react-utils';
42+
import { config } from 'topcoder-react-utils';
43+
import MetaTags from 'components/MetaTags';
4344
import { actions } from 'topcoder-react-lib';
4445
import { getService } from 'services/contentful';
4546
// import {

src/shared/containers/challenge-listing/Listing/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import sidebarActions from 'actions/challenge-listing/sidebar';
2525
import communityActions from 'actions/tc-communities';
2626
// import SORT from 'utils/challenge-listing/sort';
2727
import { BUCKETS, filterChanged, sortChangedBucket } from 'utils/challenge-listing/buckets';
28-
import { MetaTags } from 'topcoder-react-utils';
28+
import MetaTags from 'components/MetaTags';
2929
import { USER_GROUP_MAXAGE } from 'config';
3030
import { updateChallengeType } from 'utils/challenge';
3131

src/shared/containers/terms-detail/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import _ from 'lodash';
1111
import LoadingIndicator from 'components/LoadingIndicator';
1212
import TermDetails from 'components/Terms/TermDetails';
1313
import { actions } from 'topcoder-react-lib';
14-
import { MetaTags } from 'topcoder-react-utils';
14+
import MetaTags from 'components/MetaTags';
1515
import { Modal, PrimaryButton } from 'topcoder-react-ui-kit';
1616
import SwitchWithLabel from 'components/SwitchWithLabel';
1717
import { themr } from 'react-css-super-themr';

src/shared/routes/Communities/Blockchain/Routes.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ import Settings from 'routes/Settings';
2727
import TermsDetail from 'routes/TermsDetail';
2828
import { Route, Switch } from 'react-router-dom';
2929
import { ThemeProvider } from 'react-css-super-themr';
30-
import { config, MetaTags } from 'topcoder-react-utils';
30+
import { config } from 'topcoder-react-utils';
31+
import MetaTags from 'components/MetaTags';
3132

3233
import primaryButtonStyle from 'components/buttons/outline/round/open-sans/green-uppercase.scss';
3334
import secondaryButtonStyle from 'components/buttons/outline/round/open-sans/blue-uppercase.scss';

src/shared/routes/Communities/Cognitive/Routes.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import socialImage from 'assets/images/communities/cognitive/social.jpg';
2323

2424
import TermsDetail from 'routes/TermsDetail';
2525
import { Route, Switch } from 'react-router-dom';
26-
import { config, MetaTags } from 'topcoder-react-utils';
26+
import { config } from 'topcoder-react-utils';
27+
import MetaTags from 'components/MetaTags';
2728

2829
export default function Cognitive({ base, member, meta }) {
2930
return (

src/shared/routes/Communities/Mobile/Routes.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import ProfileStats from 'routes/ProfileStats';
1717

1818
import { Route, Switch } from 'react-router-dom';
1919
import { ThemeProvider } from 'react-css-super-themr';
20-
import { config, MetaTags } from 'topcoder-react-utils';
20+
import { config } from 'topcoder-react-utils';
21+
import MetaTags from 'components/MetaTags';
2122

2223
import primaryButtonStyle from 'components/buttons/outline/round/open-sans/green-uppercase.scss';
2324
import secondaryButtonStyle from 'components/buttons/outline/round/open-sans/blue-uppercase.scss';

src/shared/routes/index.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import React from 'react';
1111
import {
1212
Switch, Route, withRouter, Redirect,
1313
} from 'react-router-dom';
14-
import { MetaTags, config } from 'topcoder-react-utils';
14+
import { config } from 'topcoder-react-utils';
15+
import MetaTags from 'components/MetaTags';
1516

1617
import PT from 'prop-types';
1718

0 commit comments

Comments
 (0)