-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrapPageElement.js
66 lines (57 loc) · 1.47 KB
/
wrapPageElement.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import React from 'react';
import PropTypes from 'prop-types';
import uniqid from 'uniqid';
import Layout from './src/components/Layout';
function wrapPageElement({ element, props }) {
const { pageContext } = props;
const locale = pageContext && pageContext.locale ? pageContext.locale : 'en';
const id =
pageContext && pageContext.id
? Buffer.from(pageContext.id).toString('base64')
: uniqid();
let variants = null;
if (pageContext && pageContext._allSlugLocales) {
variants = {};
pageContext._allSlugLocales.forEach(slugLocale => {
variants[slugLocale.locale] = {
link:
slugLocale.locale === 'en'
? `/${slugLocale.value}/`
: `/${slugLocale.locale}/${slugLocale.value}/`,
};
});
}
return (
<Layout
locale={locale}
id={id}
variants={variants}
jaFont={pageContext.jaFont ? pageContext.jaFont : false}
{...props}
>
{element}
</Layout>
);
}
wrapPageElement.propTypes = {
element: PropTypes.node.isRequired,
props: PropTypes.shape({
pageContext: PropTypes.shape({
locale: PropTypes.string.isRequired,
id: PropTypes.string.isRequired,
home: PropTypes.bool,
}).isRequired,
}),
pageContext: PropTypes.shape({
locale: PropTypes.string.isRequired,
id: PropTypes.string.isRequired,
_allSlugLocales: PropTypes.arrayOf(
PropTypes.shape({
locale: PropTypes.string.isRequired,
value: PropTypes.string.isRequired,
})
),
jaFont: PropTypes.bool,
}).isRequired,
};
export default wrapPageElement;