Files
freeCodeCamp/client/utils/gatsby/layoutSelector.js

55 lines
1.5 KiB
JavaScript
Raw Normal View History

2019-02-28 15:44:35 +00:00
import React from 'react';
import PropTypes from 'prop-types';
import {
CertificationLayout,
DefaultLayout
2019-02-28 15:44:35 +00:00
} from '../../src/components/layouts';
import FourOhFourPage from '../../src/pages/404';
2019-02-28 15:44:35 +00:00
export default function layoutSelector({ element, props }) {
const {
location: { pathname }
} = props;
if (element.type === FourOhFourPage) {
return <DefaultLayout pathname={pathname}>{element}</DefaultLayout>;
}
2019-02-28 15:44:35 +00:00
if (/^\/certification(\/.*)*/.test(pathname)) {
return (
<CertificationLayout pathname={pathname}>{element}</CertificationLayout>
);
2019-02-28 15:44:35 +00:00
}
if (/^\/guide(\/.*)*/.test(pathname)) {
console.log('Hitting guide for some reason. Need a redirect.');
2019-02-28 15:44:35 +00:00
}
const splitPath = pathname.split('/');
const splitPathThree = splitPath.length > 2 ? splitPath[3] : '';
const isNotSuperBlockIntro =
splitPath.length > 3 && splitPathThree.length > 1;
if (/^\/learn(\/.*)*/.test(pathname) && isNotSuperBlockIntro) {
2019-02-28 15:44:35 +00:00
return (
<DefaultLayout pathname={pathname} showFooter={false}>
{element}
</DefaultLayout>
);
}
if (/^\/donation(\/.*)*|^\/$|^\/donate(\/.*)*/.test(pathname)) {
return (
<DefaultLayout pathname={pathname} useTheme={false}>
{element}
</DefaultLayout>
);
}
2019-02-28 15:44:35 +00:00
return <DefaultLayout pathname={pathname}>{element}</DefaultLayout>;
}
layoutSelector.propTypes = {
element: PropTypes.any,
location: PropTypes.objectOf({ pathname: PropTypes.string }),
props: PropTypes.any
};