convert all links on asset page to canonial urls

This commit is contained in:
Travis Eden 2018-10-29 16:39:08 -04:00
parent c912226ae9
commit 8537272692
4 changed files with 32 additions and 25 deletions

View file

@ -1,48 +1,48 @@
import React from 'react'; import React from 'react';
import SocialShareLink from '@components/SocialShareLink'; import SocialShareLink from '@components/SocialShareLink';
const AssetShareButtons = ({ host, name, shortId }) => { const AssetShareButtons = ({ assetUrl, name }) => {
return ( return (
<SocialShareLink > <SocialShareLink >
<a <a
className='link--primary' className='link--primary'
target='_blank' target='_blank'
href={`https://twitter.com/intent/tweet?text=${host}/${shortId}/${name}`} href={`https://twitter.com/intent/tweet?text=${assetUrl}`}
> >
twitter twitter
</a> </a>
<a <a
className='link--primary' className='link--primary'
target='_blank' target='_blank'
href={`https://www.facebook.com/sharer/sharer.php?u=${host}/${shortId}/${name}`} href={`https://www.facebook.com/sharer/sharer.php?u=${assetUrl}`}
> >
facebook facebook
</a> </a>
<a <a
className='link--primary' className='link--primary'
target='_blank' target='_blank'
href={`https://tumblr.com/widgets/share/tool?canonicalUrl=${host}/${shortId}/${name}`} href={`https://tumblr.com/widgets/share/tool?canonicalUrl=${assetUrl}`}
> >
tumblr tumblr
</a> </a>
<a <a
className='link--primary' className='link--primary'
target='_blank' target='_blank'
href={`https://www.reddit.com/submit?url=${host}/${shortId}/${name}&title=${name}`} href={`https://www.reddit.com/submit?url=${assetUrl}&title=${name}`}
> >
reddit reddit
</a> </a>
<a <a
className='link--primary' className='link--primary'
target='_blank' target='_blank'
href={`https://sharetomastodon.github.io/?title=${name}&url=${host}/${shortId}/${name}`} href={`https://sharetomastodon.github.io/?title=${name}&url=${assetUrl}`}
> >
mastodon mastodon
</a> </a>
<a <a
className='link--primary' className='link--primary'
target='_blank' target='_blank'
href={`https://share.diasporafoundation.org/?title=${name}&url=${host}/${shortId}/${name}`} href={`https://share.diasporafoundation.org/?title=${name}&url=${assetUrl}`}
> >
diaspora diaspora
</a> </a>

View file

@ -6,14 +6,20 @@ import Row from '@components/Row';
import SpaceBetween from '@components/SpaceBetween'; import SpaceBetween from '@components/SpaceBetween';
import AssetShareButtons from '@components/AssetShareButtons'; import AssetShareButtons from '@components/AssetShareButtons';
import ClickToCopy from '@components/ClickToCopy'; import ClickToCopy from '@components/ClickToCopy';
import createCanonicalLink from '../../utils/createCanonicalLink';
import siteConfig from '@config/siteConfig.json';
const { details: { host } } = siteConfig;
import createCanonicalLink from '../../../../utils/createCanonicalLink';
class AssetInfo extends React.Component { class AssetInfo extends React.Component {
render () { render () {
const { asset } = this.props; const { asset } = this.props;
const { shortId, claimData: { channelName, channelShortId, certificateId, description, name, claimId, fileExt, contentType, thumbnail, host } } = asset; const { shortId, claimData: { channelName, channelShortId, certificateId, description, name, claimId, fileExt, contentType, thumbnail, host } } = asset;
const assetCanonicalUrl = createCanonicalLink({asset}); const assetCanonicalUrl = `${host}${createCanonicalLink({
asset,
absolute: true,
})}`;
let channelCanonicalUrl; let channelCanonicalUrl;
if (channelName) { if (channelName) {
@ -21,7 +27,7 @@ class AssetInfo extends React.Component {
name: channelName, name: channelName,
shortId: channelShortId, shortId: channelShortId,
}; };
channelCanonicalUrl = createCanonicalLink({channel}); channelCanonicalUrl = `${createCanonicalLink({channel})}`;
} }
return ( return (
<div> <div>
@ -62,9 +68,8 @@ class AssetInfo extends React.Component {
} }
content={ content={
<AssetShareButtons <AssetShareButtons
host={host}
name={name} name={name}
shortId={shortId} assetUrl={assetCanonicalUrl}
/> />
} }
/> />
@ -78,7 +83,7 @@ class AssetInfo extends React.Component {
content={ content={
<ClickToCopy <ClickToCopy
id={'short-link'} id={'short-link'}
value={`${host}/${shortId}/${name}`} value={assetCanonicalUrl}
/> />
} }
/> />
@ -94,12 +99,12 @@ class AssetInfo extends React.Component {
{(contentType === 'video/mp4') ? ( {(contentType === 'video/mp4') ? (
<ClickToCopy <ClickToCopy
id={'embed-text-video'} id={'embed-text-video'}
value={`<iframe src="${host}/video-embed/${name}/${claimId}" allowfullscreen="true" style="border:0" /></iframe>`} value={`<iframe src="${host}/video-embed${assetCanonicalUrl}" allowfullscreen="true" style="border:0" /></iframe>`}
/> />
) : ( ) : (
<ClickToCopy <ClickToCopy
id={'embed-text-image'} id={'embed-text-image'}
value={`<img src="${host}/${claimId}/${name}.${fileExt}"/>`} value={`<img src="${assetCanonicalUrl}.${fileExt}"/>`}
/> />
)} )}
</div> </div>
@ -111,13 +116,13 @@ class AssetInfo extends React.Component {
<SpaceBetween> <SpaceBetween>
<a <a
className='link--primary' className='link--primary'
href={`${host}/${claimId}/${name}.${fileExt}`} href={`${assetCanonicalUrl}.${fileExt}`}
> >
Direct Link Direct Link
</a> </a>
<a <a
className={'link--primary'} className={'link--primary'}
href={`${host}/${claimId}/${name}.${fileExt}`} href={`${assetCanonicalUrl}.${fileExt}`}
download={name} download={name}
> >
Download Download

View file

@ -2,12 +2,12 @@ import React from 'react';
import Helmet from 'react-helmet'; import Helmet from 'react-helmet';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import siteConfig from '@config/siteConfig.json';
import createPageTitle from '../../utils/createPageTitle'; import createPageTitle from '../../utils/createPageTitle';
import createMetaTags from '../../utils/createMetaTags'; import createMetaTags from '../../utils/createMetaTags';
import oEmbed from '../../utils/oEmbed.js'; import oEmbed from '../../utils/oEmbed.js';
import createCanonicalLink from '../../utils/createCanonicalLink'; import createCanonicalLink from '../../../../utils/createCanonicalLink';
import siteConfig from '@config/siteConfig.json';
const { details: { host } } = siteConfig; const { details: { host } } = siteConfig;
class SEO extends React.Component { class SEO extends React.Component {
@ -21,12 +21,11 @@ class SEO extends React.Component {
asset, asset,
channel, channel,
}); });
const canonicalLink = createCanonicalLink({ const canonicalLink = `${host}${createCanonicalLink({
asset, asset,
channel, channel,
page: pageUri, page: pageUri,
absolute: true, })}`;
});
// render results // render results
return ( return (
<Helmet <Helmet

View file

@ -1,6 +1,7 @@
import siteConfig from '@config/siteConfig.json'; import siteConfig from '@config/siteConfig.json';
import determineContentTypeFromExtension from './determineContentTypeFromExtension'; import determineContentTypeFromExtension from './determineContentTypeFromExtension';
import createMetaTagsArray from './createMetaTagsArray'; import createMetaTagsArray from './createMetaTagsArray';
import createCanonicalLink from '../../../utils/createCanonicalLink';
const { const {
details: { details: {
@ -37,8 +38,10 @@ const determineMediaType = (contentType) => {
const createAssetMetaTags = (asset) => { const createAssetMetaTags = (asset) => {
const { claimData } = asset; const { claimData } = asset;
const { contentType } = claimData; const { contentType } = claimData;
const showUrl = `${host}/${claimData.claimId}/${claimData.name}`; const canonicalLink = createCanonicalLink({asset});
const serveUrl = `${host}/${claimData.claimId}/${claimData.name}.${claimData.fileExt}`; const showUrl = `${host}${canonicalLink}`;
const serveUrl = `${showUrl}.${claimData.fileExt}`;
const ogTitle = claimData.title || claimData.name; const ogTitle = claimData.title || claimData.name;
const ogDescription = claimData.description || defaultDescription; const ogDescription = claimData.description || defaultDescription;
const ogThumbnailContentType = determineContentTypeFromExtension(claimData.thumbnail); const ogThumbnailContentType = determineContentTypeFromExtension(claimData.thumbnail);
@ -55,7 +58,7 @@ const createAssetMetaTags = (asset) => {
'fb:app_id' : '1371961932852223', 'fb:app_id' : '1371961932852223',
}; };
if (determineMediaType(contentType) === VIDEO) { if (determineMediaType(contentType) === VIDEO) {
const videoEmbedUrl = `${host}/video-embed/${claimData.name}/${claimData.claimId}`; const videoEmbedUrl = `${host}/video-embed/${canonicalLink}`;
// card type tags // card type tags
metaTags['og:type'] = 'video.other'; metaTags['og:type'] = 'video.other';
metaTags['twitter:card'] = 'player'; metaTags['twitter:card'] = 'player';