-
Notifications
You must be signed in to change notification settings - Fork 90
/
static.config.js
128 lines (122 loc) · 3.76 KB
/
static.config.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import React, { Component } from 'react'
import JssProvider from 'react-jss/lib/JssProvider'
import { SheetsRegistry } from 'jss'
import {
MuiThemeProvider,
createGenerateClassName
} from '@material-ui/core/styles'
import fs from 'fs'
import theme from './src/theme'
import config from './src/config/config'
const docRepo = config.docRepo
export default {
getSiteData: () => ({
title: '好奇猫'
}),
getRoutes: async () => {
const courses = JSON.parse(fs.readFileSync(`${docRepo}/index.json`, 'utf8'))
return [
{
path: '/',
component: 'src/containers/HomeContainer',
getData: () => ({ courses })
},
{
path: '/profile',
component: 'src/containers/ProfileContainer',
getData: () => ({ courses: courses.published })
},
...[...courses.published, ...courses.unpublished].map(course => {
const toc = JSON.parse(
fs.readFileSync(`${docRepo}${course.link}/doc/index.json`),
'utf8'
)
const posts = toc.content
.reduce((sum, part) => {
return sum.concat(part.section)
}, [])
.filter(post => post.link !== '#')
const data = { cid: course.link.slice(1), toc, posts }
if (course.alias) {
data.courseAlias = course.alias
}
return {
path: course.link,
component: 'src/containers/CourseContainer',
getData: () => data,
children: posts.map(post => {
const markdown = fs.readFileSync(
`${docRepo}${course.link}/doc/${post.link}.md`,
'utf8'
)
const data = {
cid: course.link.slice(1),
title: course.title,
post,
posts,
markdown,
price: toc.price
}
if (course.alias) {
data.courseAlias = course.alias
}
return {
path: post.link,
component: `src/containers/EpisodeContainer`,
getData: () => data
}
})
}
}),
{ path: '/login', component: 'src/containers/LoginContainer' },
{ path: '/signup', component: 'src/containers/SignupContainer' },
{ path: '/steps', component: 'src/containers/StepsContainer' },
{ path: '/vip', component: 'src/containers/VipContainer' },
{ is404: true, component: 'src/containers/404' }
]
},
renderToHtml: (render, Comp, meta) => {
// Create a sheetsRegistry instance.
const sheetsRegistry = new SheetsRegistry()
const generateClassName = createGenerateClassName()
const html = render(
<JssProvider
registry={sheetsRegistry}
generateClassName={generateClassName}
>
<MuiThemeProvider theme={theme} sheetsManager={new Map()}>
<Comp />
</MuiThemeProvider>
</JssProvider>
)
meta.jssStyles = sheetsRegistry.toString()
return html
},
Document: class CustomHtml extends Component {
render() {
const { Html, Head, Body, children, renderMeta } = this.props
return (
<Html>
<Head>
<meta charSet="UTF-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1"
/>
<title>好奇猫</title>
<link rel="shortcut icon" type="image/png" href="/favicon.png" />
<meta name="description" content="好奇猫" />
<meta
name="keywords"
content="full-stack react nodejs expressjs git btc"
/>
</Head>
<Body>
{children}
<style id="jss-server-side">{renderMeta.jssStyles}</style>
</Body>
</Html>
)
}
}
}