@@ -87,6 +87,7 @@ const Wiki = ({ page, allPages, token, userRole, slug }) => {
8787 slug : page . slug === "/" ? "/" : form . get ( "slug" ) ,
8888 title : form . get ( "title" ) ,
8989 body : form . get ( "body" ) ,
90+ public : ! ! form . get ( "public" ) ,
9091 } ) ,
9192 }
9293 ) ;
@@ -169,15 +170,35 @@ const Wiki = ({ page, allPages, token, userRole, slug }) => {
169170 { ! editing ? (
170171 < Box
171172 display = "grid"
172- gridTemplateColumns = { [ "1fr" , "200px auto" ] }
173+ gridTemplateColumns = { [ "1fr" , "auto 200px " ] }
173174 gridGap = { 5 }
175+ alignItems = "start"
174176 >
177+ < MarkdownBody >
178+ < ReactMarkdown
179+ remarkPlugins = { [ remarkGfm ] }
180+ components = { {
181+ a ( { href, ...props } ) {
182+ return href . startsWith ( "http" ) ? (
183+ < a href = { href } target = "_blank" { ...props } />
184+ ) : (
185+ < Link href = { href } passHref >
186+ < a { ...props } />
187+ </ Link >
188+ ) ;
189+ } ,
190+ } }
191+ >
192+ { page . body }
193+ </ ReactMarkdown >
194+ </ MarkdownBody >
175195 < Box
176196 bg = "sidebar"
177197 border = "1px solid"
178198 borderColor = "border"
179199 borderRadius = { 1 }
180- p = { 3 }
200+ p = { 4 }
201+ _css = { { order : [ - 1 , "unset" ] } }
181202 >
182203 < Text
183204 fontWeight = { 600 }
@@ -188,35 +209,13 @@ const Wiki = ({ page, allPages, token, userRole, slug }) => {
188209 Pages
189210 </ Text >
190211 { allPages . sort ( sortSlug ) . map ( ( p ) => (
191- < Link
192- key = { `page-${ p . slug } ` }
193- href = { `/wiki/${ p . slug } ` }
194- passHref
195- >
212+ < Link key = { `page-${ p . slug } ` } href = { `/wiki${ p . slug } ` } passHref >
196213 < Text as = "a" display = "block" >
197214 { p . title }
198215 </ Text >
199216 </ Link >
200217 ) ) }
201218 </ Box >
202- < MarkdownBody >
203- < ReactMarkdown
204- remarkPlugins = { [ remarkGfm ] }
205- components = { {
206- a ( { href, ...props } ) {
207- return href . startsWith ( "http" ) ? (
208- < a href = { href } target = "_blank" { ...props } />
209- ) : (
210- < Link href = { href } passHref >
211- < a { ...props } />
212- </ Link >
213- ) ;
214- } ,
215- } }
216- >
217- { page . body }
218- </ ReactMarkdown >
219- </ MarkdownBody >
220219 </ Box >
221220 ) : (
222221 < form onSubmit = { handleEdit } >
@@ -263,8 +262,8 @@ const Wiki = ({ page, allPages, token, userRole, slug }) => {
263262} ;
264263
265264export const getServerSideProps = withAuthServerSideProps (
266- async ( { token, fetchHeaders, query : { slug } } ) => {
267- if ( ! token ) return { props : { } } ;
265+ async ( { token, fetchHeaders, isPublicAccess , query : { slug } } ) => {
266+ if ( ! token && ! isPublicAccess ) return { props : { } } ;
268267
269268 const parsedSlug = slug ?. length ? slug . join ( "/" ) : "" ;
270269
@@ -273,7 +272,7 @@ export const getServerSideProps = withAuthServerSideProps(
273272 serverRuntimeConfig : { SQ_JWT_SECRET } ,
274273 } = getConfig ( ) ;
275274
276- const { role } = jwt . verify ( token , SQ_JWT_SECRET ) ;
275+ const { role } = token ? jwt . verify ( token , SQ_JWT_SECRET ) : { role : null } ;
277276
278277 try {
279278 const wikiRes = await fetch ( `${ SQ_API_URL } /wiki/${ parsedSlug } ` , {
@@ -293,7 +292,8 @@ export const getServerSideProps = withAuthServerSideProps(
293292 if ( e === "banned" ) throw "banned" ;
294293 return { props : { token, userRole : role , slug : parsedSlug } } ;
295294 }
296- }
295+ } ,
296+ true
297297) ;
298298
299299export default Wiki ;
0 commit comments