Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions app/(docs)/@docs/[lang]/[pageId]/pageContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { useRouter } from "next/navigation";
import { revalidateChatAction } from "@/actions/revalidateChat";
import { RegenerateStreamEvent } from "@/api/chat/regenerate-section/route";
import { captureException } from "@sentry/nextjs";
import { CurrentSectionContextProvider } from "@/markdown/term";

interface PageContentProps {
splitMdContent: SectionWithDiff[];
Expand Down Expand Up @@ -120,12 +121,14 @@ export function PageContent(props: PageContentProps) {
path={path}
/>
)}
{/* ドキュメントのコンテンツ */}
<StyledMarkdown
content={section.replacedContent}
replacedRange={section.replacedRange}
interactive
/>
<CurrentSectionContextProvider sectionId={section.id}>
{/* ドキュメントのコンテンツ */}
<StyledMarkdown
content={section.replacedContent}
replacedRange={section.replacedRange}
interactive
/>
</CurrentSectionContextProvider>
</section>
<div>
<ChatListForSection
Expand Down
29 changes: 28 additions & 1 deletion app/markdown/term.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
import { createContext, JSX, ReactNode, useContext, useState } from "react";
import { ExtraProps } from "react-markdown";
import { onlyText } from "react-children-utilities";
import { LangId, PageEntry, PageSlug, TermDefinition } from "@/lib/docs";
import {
LangId,
PageEntry,
PageSlug,
SectionId,
TermDefinition,
} from "@/lib/docs";
import Link from "next/link";
import { StyledMarkdown } from "./markdown";
import {
Expand Down Expand Up @@ -46,6 +52,21 @@ export function TermDefinitionProvider({
);
}

const CurrentSectionContext = createContext<SectionId | null>(null);
export function CurrentSectionContextProvider({
sectionId,
children,
}: {
sectionId: SectionId;
children: ReactNode;
}) {
return (
<CurrentSectionContext.Provider value={sectionId}>
{children}
</CurrentSectionContext.Provider>
);
}

/**
* https://github.com/ut-code/utcode-learn/blob/main/src/components/Term/index.tsx をもとに独自実装
* Copyright (c) 2023 ut.code();
Expand All @@ -55,6 +76,7 @@ export default function Term(props: JSX.IntrinsicElements["q"] & ExtraProps) {
// @docs/lang/pageId/page.tsx で取得したものをcontextに渡してそれを取得する
const { lang, page, termDefinitions } =
useContext(TermDefinitionContext) ?? {};
const currentSectionId = useContext(CurrentSectionContext);

const langEntry = usePagesListForLang(lang);

Expand Down Expand Up @@ -159,6 +181,11 @@ export default function Term(props: JSX.IntrinsicElements["q"] & ExtraProps) {
);
}

if (currentSectionId === term.id) {
// このセクション自身へのリンクは表示しない
return props.children;
}

const pageEntry = langEntry?.pages.find((p) => p.slug === term.page);

return (
Expand Down
Loading