Skip to content

Commit dd34b4b

Browse files
Copilotna-trium-144
andcommitted
Remove content from MarkdownSection, use rawContent directly in pageContent
Co-authored-by: na-trium-144 <100704180+na-trium-144@users.noreply.github.com>
1 parent e50a9f9 commit dd34b4b

File tree

4 files changed

+9
-24
lines changed

4 files changed

+9
-24
lines changed

app/[docs_id]/page.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,9 @@ export async function generateMetadata({
4545
// 先頭の 第n章: を除いたものをタイトルとする
4646
const title = splitMdContent[0]?.title?.split(" ").slice(1).join(" ");
4747

48-
const description = splitMdContent[0].content;
48+
const description = splitMdContent[0].rawContent;
4949

50-
const lang_id = docs_id.split("-")[0];
51-
const chapter = docs_id.split("-")[1];
50+
const [lang_id, chapter] = docs_id.split("-");
5251
const pagesList = await getPagesList();
5352
const langName = pagesList.find((l) => l.id === lang_id)?.name ?? lang_id;
5453

@@ -64,8 +63,8 @@ export default async function Page({
6463
params: Promise<{ docs_id: string }>;
6564
}) {
6665
const { docs_id } = await params;
67-
const lang_id = docs_id.split("-")[0];
68-
const page_num = parseInt(docs_id.split("-")[1]);
66+
const [lang_id, page_num_str] = docs_id.split("-");
67+
const page_num = parseInt(page_num_str);
6968
const pagesList = await getPagesList();
7069
if (
7170
!pagesList

app/[docs_id]/pageContent.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { Fragment, useEffect, useRef, useState } from "react";
44
import { MarkdownSection } from "./splitMarkdown";
55
import { ChatForm } from "./chatForm";
6-
import { Heading, StyledMarkdown } from "./markdown";
6+
import { StyledMarkdown } from "./markdown";
77
import { useChatHistoryContext } from "./chatHistory";
88
import { useSidebarMdContext } from "../sidebar";
99
import clsx from "clsx";
@@ -99,8 +99,7 @@ export function PageContent(props: PageContentProps) {
9999
}}
100100
>
101101
{/* ドキュメントのコンテンツ */}
102-
<Heading level={section.level}>{section.title}</Heading>
103-
<StyledMarkdown content={section.content} />
102+
<StyledMarkdown content={section.rawContent} />
104103
</div>
105104
<div>
106105
{/* 右側に表示するチャット履歴欄 */}

app/[docs_id]/splitMarkdown.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ export interface MarkdownSection {
66
id: string;
77
level: number;
88
title: string;
9-
content: string;
109
rawContent: string; // 見出しも含めたもとのmarkdownの内容
1110
}
1211
/**
@@ -34,10 +33,6 @@ export function splitMarkdown(content: string): MarkdownSection[] {
3433
sections.push({
3534
id: "",
3635
title: splitContent[startLine - 1].replace(/#+\s*/, "").trim(),
37-
content: splitContent
38-
.slice(startLine - 1 + 1, endLine ? endLine - 1 : undefined)
39-
.join("\n")
40-
.trim(),
4136
level: headingNodes.at(i)!.depth,
4237
rawContent: splitContent
4338
.slice(startLine - 1, endLine ? endLine - 1 : undefined)

app/[lang]/[pageId]/page.tsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,14 @@ async function getMarkdownSections(
8686
id: `${lang}-${pageId}-intro`,
8787
level: 1,
8888
title: pageTitle,
89-
content: raw.trim(),
9089
rawContent: raw.trim(),
9190
});
9291
} else {
9392
const { id, title, level, body } = parseFrontmatter(raw);
94-
// bodyには見出し行が含まれるので、contentとしては見出しを除いた本文のみを渡す
95-
const content = body.replace(/^#{1,6} [^\n]*\n?/, "").trim();
9693
sections.push({
9794
id,
9895
level,
9996
title,
100-
content,
10197
rawContent: body.trim(),
10298
});
10399
}
@@ -114,7 +110,7 @@ export async function generateMetadata({
114110
const pagesList = await getPagesList();
115111
const langEntry = pagesList.find((l) => l.id === lang);
116112
const pageIndex = langEntry?.pages.findIndex((p) => p.slug === pageId) ?? -1;
117-
const pageEntry = pageIndex >= 0 ? langEntry?.pages[pageIndex] : undefined;
113+
const pageEntry = pageIndex >= 0 ? langEntry!.pages[pageIndex] : undefined;
118114
if (!langEntry || !pageEntry) notFound();
119115

120116
return {
@@ -136,12 +132,8 @@ export default async function Page({
136132
const docsId = `${lang}/${pageId}`;
137133
const sections = await getMarkdownSections(lang, pageId, pageEntry!.name);
138134

139-
// AI用のドキュメント全文(見出し付きで結合)
140-
const documentContent = sections
141-
.map((s) =>
142-
s.level > 0 ? `${"#".repeat(s.level)} ${s.title}\n\n${s.content}` : s.content
143-
)
144-
.join("\n\n");
135+
// AI用のドキュメント全文(rawContentを結合)
136+
const documentContent = sections.map((s) => s.rawContent).join("\n\n");
145137

146138
const context = await initContext();
147139
const initialChatHistories = await getChatFromCache(docsId, context);

0 commit comments

Comments
 (0)