@@ -17,18 +17,20 @@ import {
1717 getPostTopMenu ,
1818 isPostSource ,
1919 TopLevelMenu ,
20- } from '../../utils/posts'
20+ getPostURL ,
21+ } from '../../utils'
2122import { HelpDocHeader } from '../../components/HelpDocHeader'
2223import styles from './index.module.scss'
2324import { Sidebar } from './Sidebar'
2425import { TOC } from './TOC'
2526
2627interface PageProps {
2728 post : Post
29+ menusWithPosts : TopLevelMenu [ ]
2830 menuWithPosts : TopLevelMenu
2931}
3032
31- const PostPage : NextPage < PageProps > = ( { post, menuWithPosts } ) => {
33+ const PostPage : NextPage < PageProps > = ( { post, menusWithPosts , menuWithPosts } ) => {
3234 const components : ComponentProps < typeof ReactMarkdown > [ 'components' ] = useMemo (
3335 ( ) => ( {
3436 h1 : wrapHeadingWithTOCItem ( 'h1' ) ,
@@ -44,6 +46,10 @@ const PostPage: NextPage<PageProps> = ({ post, menuWithPosts }) => {
4446 [ ] ,
4547 )
4648
49+ const submenuName = menuWithPosts . children ?. find ( menu =>
50+ menu . posts ?. find ( _post => post . source === _post . source && post . number === _post . number ) ,
51+ ) ?. name
52+
4753 return (
4854 < div className = { styles . page } >
4955 < HelpDocHeader className = { styles . header } />
@@ -54,9 +60,14 @@ const PostPage: NextPage<PageProps> = ({ post, menuWithPosts }) => {
5460 < div className = { styles . navbar } >
5561 { /* TODO: feature needs to be implemented */ }
5662 < Link href = "/" > Home</ Link >
57- < Link href = "/" > { `Beginner's Guide` } </ Link >
58- < Link href = "/" > FAQ</ Link >
59- < Link href = "/" > Announcement</ Link >
63+ { menusWithPosts . map (
64+ menu =>
65+ menu . posts ?. [ 0 ] && (
66+ < Link key = { menu . name } href = { getPostURL ( menu . posts [ 0 ] ) } >
67+ { menu . name }
68+ </ Link >
69+ ) ,
70+ ) }
6071 </ div >
6172
6273 < TOCContextProvider >
@@ -65,13 +76,7 @@ const PostPage: NextPage<PageProps> = ({ post, menuWithPosts }) => {
6576 < div className = { styles . breadcrumbs } >
6677 { /* TODO: feature needs to be implemented */ }
6778 < div className = { styles . item } > { menuWithPosts . name } </ div >
68- < div className = { styles . item } >
69- {
70- menuWithPosts . children ?. find ( menu =>
71- menu . posts ?. find ( _post => post . source === _post . source && post . number === _post . number ) ,
72- ) ?. name
73- }
74- </ div >
79+ { submenuName && < div className = { styles . item } > { submenuName } </ div > }
7580 < div className = { styles . item } > { post . title } </ div >
7681 </ div >
7782
@@ -117,15 +122,17 @@ export const getStaticProps: GetStaticProps<PageProps, { slug?: string[] }> = as
117122 if ( ! post ) return { notFound : true }
118123 const menu = getPostTopMenu ( post )
119124 if ( ! menu ) return { notFound : true }
120- const menusWithPosts = await getMenusWithPosts ( menu )
121- if ( ! menusWithPosts [ 0 ] ) return { notFound : true }
125+ const menusWithPosts = await getMenusWithPosts ( )
126+ const menuWithPosts = menusWithPosts . find ( ( { name } ) => name === menu . name )
127+ if ( ! menuWithPosts ) return { notFound : true }
122128
123129 const lng = await serverSideTranslations ( locale ?? 'en' , [ 'common' , 'posts' ] )
124130
125131 const props : PageProps = {
126132 ...lng ,
127133 post,
128- menuWithPosts : menusWithPosts [ 0 ] ,
134+ menusWithPosts,
135+ menuWithPosts,
129136 }
130137
131138 return { props }
0 commit comments