File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -108,8 +108,8 @@ export default function Term(props: JSX.IntrinsicElements["q"] & ExtraProps) {
108108 ) ;
109109
110110 // ./1, ./1-foo, ./next, ./prev →同じ言語のドキュメントへのリンクで、「第n章」
111- const pageIndexMatch = termText . match ( / ^ .\/ ( \d + ) $ / ) ;
112- const pageSlugMatch = termText . match ( / ^ .\/ ( [ 0 - 9 a - z A - Z _ - ] + ) $ / ) ;
111+ const pageIndexMatch = termText . match ( / ^ \ .\/ ( \d + ) $ / ) ;
112+ const pageSlugMatch = termText . match ( / ^ \ .\/ ( [ 0 - 9 a - z A - Z _ - ] + ) $ / ) ;
113113 if (
114114 pageIndexMatch &&
115115 langEntry &&
@@ -125,12 +125,13 @@ export default function Term(props: JSX.IntrinsicElements["q"] & ExtraProps) {
125125 langEntry . pages . find ( ( p ) => p . slug === pageSlugMatch [ 1 ] ) !
126126 ) ;
127127 }
128- const currentPageIndex = langEntry ?. pages . findIndex ( ( p ) => p . slug === page ) ;
128+ const currentPageIndex =
129+ langEntry ?. pages . findIndex ( ( p ) => p . slug === page ) ?? - 1 ;
129130 if (
130131 pageSlugMatch &&
131132 langEntry &&
132133 pageSlugMatch [ 1 ] === "prev" &&
133- currentPageIndex !== undefined
134+ currentPageIndex > 0
134135 ) {
135136 // ./prev → 前のページ
136137 return internalLink ( langEntry . pages [ currentPageIndex - 1 ] ) ;
@@ -139,7 +140,8 @@ export default function Term(props: JSX.IntrinsicElements["q"] & ExtraProps) {
139140 pageSlugMatch &&
140141 langEntry &&
141142 pageSlugMatch [ 1 ] === "next" &&
142- currentPageIndex !== undefined
143+ currentPageIndex >= 0 &&
144+ currentPageIndex < langEntry . pages . length - 1
143145 ) {
144146 // ./next → 次のページ
145147 return internalLink ( langEntry . pages [ currentPageIndex + 1 ] ) ;
You can’t perform that action at this time.
0 commit comments