-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcosmos.decorator.js
49 lines (42 loc) · 1.09 KB
/
cosmos.decorator.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
import React from 'react';
import PropTypes from 'prop-types';
import {ThemeProvider} from 'theme-ui';
import {QueryClient, QueryClientProvider} from 'react-query';
import theme from './cosmos/theme';
function pageLookup(href) {
// This depends on the fact that no sub-subdirectory of pages contains an index file
if (href.includes('/')) {
const root = href
.split('/')
.pop()
.reduce((url, element) => {
return url.concat('/', element);
});
return `/${root}/[slug]`;
}
switch (href) {
case '':
case 'sermons':
case 'search':
case 'all-sermons':
return `/${href}`;
default:
return '/[slug]';
}
}
const Link = ({href, ...rest}) => {
return <a href={pageLookup(href)} {...rest} />;
};
Link.propTypes = {
href: PropTypes.string.isRequired
};
const components = {a: Link};
const decorator = (props) => {
const client = new QueryClient();
return (
<QueryClientProvider client={client}>
<ThemeProvider theme={theme} components={components} {...props} />
</QueryClientProvider>
);
};
export default decorator;