Merge pull request #940 from sharetribe/referrer-policy-updates

Referrer policy updates
This commit is contained in:
Vesa Luusua 2018-10-17 14:23:22 +03:00 committed by GitHub
commit 1aef211728
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 7 deletions

View file

@ -13,7 +13,8 @@ way to update this template, but currently, we follow a pattern:
---
## Upcoming version 2018-10-XX
* [add] Add referrer policy due tokens in URL on PasswordResetPage and EmailVerificationPage.
[#940](https://github.com/sharetribe/flex-template-web/pull/940)
* [add] Added initial documentation about our Redux setup.
[#939](https://github.com/sharetribe/flex-template-web/pull/939)
* [add] Added a small comment to documentation about the current state of code-splitting.

View file

@ -67,6 +67,7 @@ class PageComponent extends Component {
location,
intl,
scrollingDisabled,
referrer,
author,
contentType,
description,
@ -84,8 +85,11 @@ class PageComponent extends Component {
[css.scrollingDisabled]: scrollingDisabled,
});
const referrerMeta = referrer ? <meta name="referrer" content={referrer} /> : null;
const canonicalRootURL = config.canonicalRootURL;
const canonicalPath = canonicalRoutePath(routeConfiguration(), location);
const shouldReturnPathOnly = referrer && referrer !== 'unsafe-url';
const canonicalPath = canonicalRoutePath(routeConfiguration(), location, shouldReturnPathOnly);
const canonicalUrl = `${canonicalRootURL}${canonicalPath}`;
const siteTitle = config.siteTitle;
@ -186,6 +190,7 @@ class PageComponent extends Component {
}}
>
<title>{title}</title>
{referrerMeta}
<link rel="canonical" href={canonicalUrl} />
<meta httpEquiv="Content-Type" content="text/html; charset=UTF-8" />
<meta httpEquiv="Content-Language" content={intl.locale} />
@ -219,6 +224,7 @@ PageComponent.defaultProps = {
facebookImages: null,
twitterImages: null,
published: null,
referrer: null,
schema: null,
tags: null,
twitterHandle: null,
@ -231,6 +237,9 @@ PageComponent.propTypes = {
children: any,
scrollingDisabled: bool.isRequired,
// Handle referrer policy
referrer: string,
// SEO related props
author: string,
contentType: string, // og:type

View file

@ -60,7 +60,7 @@ export const EmailVerificationPageComponent = props => {
const initialValues = { verificationToken: parseVerificationToken(location) };
return (
<Page title={title} scrollingDisabled={scrollingDisabled}>
<Page title={title} scrollingDisabled={scrollingDisabled} referrer="origin">
<LayoutSingleColumn>
<LayoutWrapperTopbar>
<TopbarContainer />

View file

@ -121,7 +121,7 @@ export class PasswordResetPageComponent extends Component {
}
return (
<Page title={title} scrollingDisabled={scrollingDisabled}>
<Page title={title} scrollingDisabled={scrollingDisabled} referrer="origin">
<LayoutSingleColumn>
<LayoutWrapperTopbar>
<TopbarContainer />

View file

@ -99,7 +99,7 @@ export const findRouteByRouteName = (nameToFind, routes) => {
* @return {String} Canonical URL of the given location
*
*/
export const canonicalRoutePath = (routes, location) => {
export const canonicalRoutePath = (routes, location, pathOnly = false) => {
const { pathname, search, hash } = location;
const matches = matchPathname(pathname, routes);
@ -116,8 +116,8 @@ export const canonicalRoutePath = (routes, location) => {
throw new Error('Expected ListingPage route to have 4 parts');
}
const canonicalListingPathname = `/${parts[1]}/${parts[3]}`;
return `${canonicalListingPathname}${search}${hash}`;
return pathOnly ? canonicalListingPathname : `${canonicalListingPathname}${search}${hash}`;
}
return `${pathname}${search}${hash}`;
return pathOnly ? pathname : `${pathname}${search}${hash}`;
};