Skip to content

Commit 56abb14

Browse files
authored
Merge pull request #232 from ut-code/utcodelearn-term
#224 copilotレビュー反映
2 parents c18dab0 + cef8321 commit 56abb14

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

app/markdown/term.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff 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-9a-zA-Z_-]+)$/);
111+
const pageIndexMatch = termText.match(/^\.\/(\d+)$/);
112+
const pageSlugMatch = termText.match(/^\.\/([0-9a-zA-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]);

0 commit comments

Comments
 (0)