@@ -8,32 +8,38 @@ import clsx from "clsx";
88import { PageTransition } from "./pageTransition" ;
99import {
1010 DynamicMarkdownSection ,
11- LanguageEntry ,
11+ LangId ,
1212 MarkdownSection ,
13- PageEntry ,
1413 PagePath ,
14+ PageSlug ,
1515 SectionId ,
1616} from "@/lib/docs" ;
1717import { Heading } from "@/markdown/heading" ;
1818import Link from "next/link" ;
1919import { useChatId } from "@/(docs)/chatAreaState" ;
2020import { ChatWithMessages } from "@/lib/chatHistory" ;
21+ import { usePagesListForLang } from "@/pagesListContext" ;
2122
2223interface PageContentProps {
2324 splitMdContent : MarkdownSection [ ] ;
24- langEntry : LanguageEntry ;
25- pageEntry : PageEntry ;
26- prevPage ?: PageEntry ;
27- nextPage ?: PageEntry ;
25+ langId : LangId ;
26+ pageSlug : PageSlug ;
2827 path : PagePath ;
2928 chatHistories : ChatWithMessages [ ] ;
3029}
3130export function PageContent ( props : PageContentProps ) {
3231 const { setSidebarMdContent } = useSidebarMdContext ( ) ;
33- const { splitMdContent, pageEntry, path, chatHistories } = props ;
32+ const { splitMdContent, langId, pageSlug, path, chatHistories } = props ;
33+
34+ const langEntry = usePagesListForLang ( langId ) ;
35+ const pageEntryIndex =
36+ langEntry ?. pages . findIndex ( ( p ) => p . slug === pageSlug ) ?? - 1 ;
37+ const pageEntry = langEntry ?. pages [ pageEntryIndex ] ;
38+ const prevPage = langEntry ?. pages [ pageEntryIndex - 1 ] ;
39+ const nextPage = langEntry ?. pages [ pageEntryIndex + 1 ] ;
3440
3541 const [ sectionInView , setSectionInView ] = useState < boolean [ ] > ( [ ] ) ;
36- const sectionRefs = useRef < Array < HTMLDivElement | null > > ( [ ] ) ;
42+ const sectionRefs = useRef < Array < HTMLElement | null > > ( [ ] ) ;
3743 useEffect ( ( ) => {
3844 const handleScroll = ( ) => {
3945 setSectionInView ( ( sectionInView ) => {
@@ -143,12 +149,12 @@ export function PageContent(props: PageContentProps) {
143149 } }
144150 >
145151 < Heading className = "max-w-docs" level = { 1 } >
146- 第{ pageEntry . index } 章: { pageEntry . title }
152+ 第{ pageEntry ? .index } 章: { pageEntry ? .title }
147153 </ Heading >
148154 < div />
149155 { dynamicMdContent . map ( ( section , index ) => (
150156 < Fragment key = { section . id } >
151- < div
157+ < section
152158 className = "min-w-1/2 max-w-docs text-justify"
153159 id = { section . id } // 目次からaタグで飛ぶために必要
154160 ref = { ( el ) => {
@@ -159,8 +165,9 @@ export function PageContent(props: PageContentProps) {
159165 < StyledMarkdown
160166 content = { section . replacedContent }
161167 replacedRange = { section . replacedRange }
168+ interactive
162169 />
163- </ div >
170+ </ section >
164171 < div >
165172 < ChatListForSection
166173 sectionId = { section . id }
@@ -172,8 +179,8 @@ export function PageContent(props: PageContentProps) {
172179 ) ) }
173180 < PageTransition
174181 lang = { path . lang }
175- prevPage = { props . prevPage }
176- nextPage = { props . nextPage }
182+ prevPage = { prevPage }
183+ nextPage = { nextPage }
177184 />
178185 < div />
179186 </ div >
@@ -183,7 +190,7 @@ export function PageContent(props: PageContentProps) {
183190 < div className = "fixed bottom-4 right-4 left-4 has-sidebar:left-[calc(var(--container-sidebar)+1rem)] z-40" >
184191 < ChatForm
185192 path = { path }
186- langName = { props . langEntry . name }
193+ langName = { langEntry ? .name ?? "" }
187194 sectionContent = { dynamicMdContent }
188195 close = { ( ) => setIsFormVisible ( false ) }
189196 />
0 commit comments