@@ -6,27 +6,12 @@ import NextSeo from 'next-seo'
66import { PAGE_SIZE , SITE_URL } from '@config'
77import initRootStore from '@stores/init'
88
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-
249import {
10+ isServerSide ,
2511 getJwtToken ,
2612 makeGQClient ,
2713 queryStringToJSON ,
28- getMainPath ,
29- getSubPath ,
14+ parseURL ,
3015 akaTranslate ,
3116 extractThreadFromPath ,
3217 buildLog ,
@@ -40,6 +25,21 @@ import {
4025 parseTheme ,
4126} from '@utils'
4227
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+
4343import { P } from '@schemas'
4444
4545/* eslint-disable-next-line */
@@ -59,10 +59,8 @@ async function fetchData(props, opt) {
5959 const { asPath } = props
6060 // schema
6161
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 )
6664 const thread = extractThreadFromPath ( props )
6765
6866 let filter = addTopicIfNeed (
@@ -107,8 +105,9 @@ async function fetchData(props, opt) {
107105
108106export default class CommunityPage extends React . Component {
109107 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 )
112111 const thread = extractThreadFromPath ( props )
113112
114113 let resp
@@ -120,7 +119,7 @@ export default class CommunityPage extends React.Component {
120119 } else {
121120 return {
122121 statusCode : 404 ,
123- target : mainPath ,
122+ target : communityPath ,
124123 viewing : { community : { } } ,
125124 route : { } ,
126125 }
@@ -157,7 +156,12 @@ export default class CommunityPage extends React.Component {
157156 repo : { } ,
158157 user : { } ,
159158 } ,
160- route : { mainPath : community . raw , subPath } ,
159+ route : {
160+ communityPath : community . raw ,
161+ mainPath : community . raw ,
162+ threadPath,
163+ subPath : threadPath ,
164+ } ,
161165 tagsBar : { tags : partialTags } ,
162166 } ,
163167 contentsThread
@@ -180,7 +184,7 @@ export default class CommunityPage extends React.Component {
180184 viewing : { community } ,
181185 route,
182186 } = this . props
183- const { mainPath , subPath } = route
187+ const { communityPath , threadPath } = route
184188
185189 const seoTitle =
186190 community . raw === 'home'
@@ -201,7 +205,7 @@ export default class CommunityPage extends React.Component {
201205 < React . Fragment >
202206 < NextSeo
203207 config = { {
204- url : `${ SITE_URL } /${ mainPath } /${ subPath } ` ,
208+ url : `${ SITE_URL } /${ communityPath } /${ threadPath } ` ,
205209 title : seoTitle ,
206210 description : `${ community . desc } ` ,
207211 } }
0 commit comments