fix(learn): prevent indexing learn pages on search engines (#38260)

Co-authored-by: mrugesh <1884376+raisedadead@users.noreply.github.com>
Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
This commit is contained in:
Hassaan Pasha
2020-03-03 20:27:53 +05:00
committed by GitHub
parent ac922ac04e
commit 5294936667
2 changed files with 13 additions and 2 deletions

View File

@ -1,4 +1,5 @@
const path = require('path'); const path = require('path');
const config = require('./config/env');
const { const {
buildChallenges, buildChallenges,
@ -11,7 +12,7 @@ const curriculumIntroRoot = path.resolve(__dirname, './src/pages');
module.exports = { module.exports = {
siteMetadata: { siteMetadata: {
title: 'freeCodeCamp', title: 'freeCodeCamp',
siteUrl: 'https://www.freecodecamp.org' siteUrl: config.homeLocation
}, },
plugins: [ plugins: [
'gatsby-plugin-react-helmet', 'gatsby-plugin-react-helmet',

View File

@ -2,7 +2,7 @@ import React, { Fragment, Component } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { createSelector } from 'reselect'; import { createSelector } from 'reselect';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { Helmet } from 'react-helmet';
import { Loader } from '../../components/helpers'; import { Loader } from '../../components/helpers';
import { import {
userSelector, userSelector,
@ -41,6 +41,13 @@ class LearnLayout extends Component {
this.props.tryToShowDonationModal(); this.props.tryToShowDonationModal();
} }
componentWillUnmount() {
const metaTag = document.querySelector(`meta[name="robots"]`);
if (metaTag) {
metaTag.remove();
}
}
render() { render() {
const { const {
fetchState: { pending, complete }, fetchState: { pending, complete },
@ -59,6 +66,9 @@ class LearnLayout extends Component {
return ( return (
<Fragment> <Fragment>
<Helmet>
<meta content='noindex' name='robots' />
</Helmet>
<main id='learn-app-wrapper'>{children}</main> <main id='learn-app-wrapper'>{children}</main>
<DonateModal /> <DonateModal />
</Fragment> </Fragment>