forked from achievethecore/atc-coherence-map
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reactmeta.js
31 lines (28 loc) · 1.1 KB
/
reactmeta.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
var Component = require('react').Component;
export class ReactMeta extends Component {
static propTypes = {
title: React.PropTypes.string,
desc: React.PropTypes.string
}
componentWillMount() {
this.setTitle();
}
componentDidUpdate() {
this.setTitle();
}
setTitle() {
if (!this.props.title) document.title = 'Coherence Map';
else document.title = `${this.props.title} - Coherence Map`;
const desc = document.querySelector('meta[name="description"]');
if (!this.props.desc) desc.setAttribute('content', 'The Coherence Map shows the connections between Common Core State Standards for Mathematics.');
else desc.setAttribute('content', this.props.desc.replace(/<.*?>/g, ''));
let canonical = document.querySelector("link[rel='canonical']");
if (!canonical) {
canonical = document.createElement('link')
canonical.setAttribute('rel', 'canonical');
document.head.appendChild(canonical);
}
document.querySelector("link[rel='canonical']").setAttribute('href', 'https://achievethecore.org' + window.location.pathname);
}
render() { return null; }
}