@@ -6,27 +6,12 @@ import NextSeo from 'next-seo'
6
6
import { PAGE_SIZE , SITE_URL } from '@config'
7
7
import initRootStore from '@stores/init'
8
8
9
- import AnalysisService from '@services/Analysis'
10
- import GlobalLayout from '@containers/GlobalLayout'
11
- import ThemeWrapper from '@containers/ThemeWrapper'
12
- import MultiLanguage from '@containers/MultiLanguage'
13
- import Sidebar from '@containers/Sidebar'
14
- import Preview from '@containers/Preview'
15
- import Doraemon from '@containers/Doraemon'
16
- import Route from '@containers/Route'
17
- import Header from '@containers/Header'
18
- import CommunityBanner from '@containers/CommunityBanner'
19
- import CommunityContent from '@containers/CommunityContent'
20
- import Footer from '@containers/Footer'
21
- import ErrorBox from '@containers/ErrorBox'
22
- import ErrorPage from '@components/ErrorPage'
23
-
24
9
import {
10
+ isServerSide ,
25
11
getJwtToken ,
26
12
makeGQClient ,
27
13
queryStringToJSON ,
28
- getMainPath ,
29
- getSubPath ,
14
+ parseURL ,
30
15
akaTranslate ,
31
16
extractThreadFromPath ,
32
17
buildLog ,
@@ -40,6 +25,21 @@ import {
40
25
parseTheme ,
41
26
} from '@utils'
42
27
28
+ import AnalysisService from '@services/Analysis'
29
+ import GlobalLayout from '@containers/GlobalLayout'
30
+ import ThemeWrapper from '@containers/ThemeWrapper'
31
+ import MultiLanguage from '@containers/MultiLanguage'
32
+ import Sidebar from '@containers/Sidebar'
33
+ import Preview from '@containers/Preview'
34
+ import Doraemon from '@containers/Doraemon'
35
+ import Route from '@containers/Route'
36
+ import Header from '@containers/Header'
37
+ import CommunityBanner from '@containers/CommunityBanner'
38
+ import CommunityContent from '@containers/CommunityContent'
39
+ import Footer from '@containers/Footer'
40
+ import ErrorBox from '@containers/ErrorBox'
41
+ import ErrorPage from '@components/ErrorPage'
42
+
43
43
import { P } from '@schemas'
44
44
45
45
/* eslint-disable-next-line */
@@ -59,10 +59,8 @@ async function fetchData(props, opt) {
59
59
const { asPath} = props
60
60
// schema
61
61
62
- // utils: filter, tags staff
63
- const mainPath = getMainPath ( props )
64
- const community = akaTranslate ( mainPath )
65
- const topic = getSubPath ( props )
62
+ const { communityPath, threadPath :topic } = parseURL ( props )
63
+ const community = akaTranslate ( communityPath )
66
64
const thread = extractThreadFromPath ( props )
67
65
68
66
let filter = addTopicIfNeed (
@@ -107,8 +105,9 @@ async function fetchData(props, opt) {
107
105
108
106
export default class CommunityPage extends React . Component {
109
107
static async getInitialProps ( props ) {
110
- const mainPath = getMainPath ( props )
111
- const subPath = getSubPath ( props )
108
+ if ( ! isServerSide ) return { }
109
+
110
+ const { communityPath, threadPath} = parseURL ( props )
112
111
const thread = extractThreadFromPath ( props )
113
112
114
113
let resp
@@ -120,7 +119,7 @@ export default class CommunityPage extends React.Component {
120
119
} else {
121
120
return {
122
121
statusCode :404 ,
123
- target :mainPath ,
122
+ target :communityPath ,
124
123
viewing :{ community :{ } } ,
125
124
route :{ } ,
126
125
}
@@ -157,7 +156,12 @@ export default class CommunityPage extends React.Component {
157
156
repo :{ } ,
158
157
user :{ } ,
159
158
} ,
160
- route :{ mainPath :community . raw , subPath} ,
159
+ route :{
160
+ communityPath :community . raw ,
161
+ mainPath :community . raw ,
162
+ threadPath,
163
+ subPath :threadPath ,
164
+ } ,
161
165
tagsBar :{ tags :partialTags } ,
162
166
} ,
163
167
contentsThread
@@ -180,7 +184,7 @@ export default class CommunityPage extends React.Component {
180
184
viewing :{ community} ,
181
185
route,
182
186
} = this . props
183
- const { mainPath , subPath } = route
187
+ const { communityPath , threadPath } = route
184
188
185
189
const seoTitle =
186
190
community . raw === 'home'
@@ -201,7 +205,7 @@ export default class CommunityPage extends React.Component {
201
205
< React . Fragment >
202
206
< NextSeo
203
207
config = { {
204
- url :`${ SITE_URL } /${ mainPath } /${ subPath } ` ,
208
+ url :`${ SITE_URL } /${ communityPath } /${ threadPath } ` ,
205
209
title :seoTitle ,
206
210
description :`${ community . desc } ` ,
207
211
} }