-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhome.js
40 lines (37 loc) · 947 Bytes
/
home.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
import { useEffect } from 'react';
import { marked } from 'marked';
const handleRoute = location => {
if (location === '/') {
return './home.md';
} else if (location === '/buildless-blog/') {
window.location.href = `${window.location.href}/home`;
return;
} else {
return `.${location}.md`;
}
}
export default () => {
const contentFile = handleRoute(location.pathname);
useEffect(() =>
fetch(contentFile).then(res =>
res.status !== 200 ? 'not found' : res.text()
).then(content =>
document.getElementById('content').innerHTML = marked(content)), []);
return html`
<div id="content"></div>
<style>
@media (prefers-color-scheme: dark) {
html {
background: black;
color: white;
}
}
@media (prefers-color-scheme: light) {
html {
background: white;
color: black;
}
}
</style>
`;
}