1
0
mirror of https://github.com/kremalicious/portfolio.git synced 2024-06-23 01:36:39 +02:00
portfolio/src/components/atoms/HostnameCheck.jsx

46 lines
1.3 KiB
React
Raw Normal View History

2018-12-08 20:27:45 +01:00
import React, { PureComponent } from 'react'
2019-04-14 16:58:20 +02:00
import PropTypes from 'prop-types'
2020-04-11 23:40:25 +02:00
import { Helmet } from 'react-helmet'
2021-03-12 23:47:28 +01:00
import { hostnameInfo } from './HostnameCheck.module.css'
2018-12-08 20:27:45 +01:00
2019-04-14 16:58:20 +02:00
export default class HostnameCheck extends PureComponent {
static propTypes = {
allowedHosts: PropTypes.array.isRequired
}
2018-12-08 20:27:45 +01:00
checkAllowedHost = () => {
if (typeof window !== 'undefined' && window.location) {
2019-04-14 16:58:20 +02:00
return this.props.allowedHosts.includes(window.location.hostname)
2018-12-08 20:27:45 +01:00
}
}
state = {
// default to true so SSR builds never show the banner
2018-12-08 20:27:45 +01:00
isAllowedHost: true
}
componentDidMount() {
const isAllowedHost = this.checkAllowedHost()
this.setState({ isAllowedHost })
}
render() {
// return nothing if we're on an allowed host
2018-12-08 20:27:45 +01:00
if (this.state.isAllowedHost) return null
return (
<>
<Helmet>
<meta name="robots" content="noindex,nofollow" />
</Helmet>
2021-03-12 23:47:28 +01:00
<aside className={hostnameInfo}>
<p>{`Hi there 👋. Please note that only the code and documentation of this
site are open source. But my logo and the combination of typography,
colors, and layout making up my brand identity are not. Don't just
clone, do a remix.`}</p>
2018-12-08 20:27:45 +01:00
</aside>
</>
)
}
}