Skip to content

Commit 86f216c

Browse files
committed
ページリストを別ファイルに
1 parent 4c53200 commit 86f216c

File tree

2 files changed

+31
-30
lines changed

2 files changed

+31
-30
lines changed

app/pagesList.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// docs_id = `${group.id}-${page.id}`
2+
export const pagesList = [
3+
{
4+
id: "python",
5+
lang: "Python",
6+
pages: [
7+
{ id: 1, title: "環境構築と基本思想" },
8+
{ id: 2, title: "基本構文とデータ型" },
9+
{ id: 3, title: "リスト、タプル、辞書、セット" },
10+
{ id: 4, title: "制御構文と関数" },
11+
{ id: 5, title: "モジュールとパッケージ" },
12+
{ id: 6, title: "オブジェクト指向プログラミング" },
13+
{
14+
id: 7,
15+
title: "ファイルの入出力とコンテキストマネージャ",
16+
},
17+
{ id: 8, title: "例外処理" },
18+
{ id: 9, title: "ジェネレータとデコレータ" },
19+
],
20+
},
21+
{
22+
id: "cpp",
23+
lang: "C++",
24+
pages: [
25+
{ id: 2, title: "型システムとメモリ" },
26+
{ id: 3, title: "関数と参照" },
27+
],
28+
},
29+
] as const;

app/sidebar.tsx

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Link from "next/link";
33
import { usePathname } from "next/navigation";
44
import useSWR, { Fetcher } from "swr";
55
import { splitMarkdown } from "./[docs_id]/splitMarkdown";
6+
import { pagesList } from "./pagesList";
67

78
const fetcher: Fetcher<string, string> = (url) =>
89
fetch(url).then((r) => r.text());
@@ -12,35 +13,6 @@ export function Sidebar() {
1213
const docs_id = pathname.replace(/^\//, "");
1314
const { data, error, isLoading } = useSWR(`/docs/${docs_id}.md`, fetcher);
1415

15-
const pages = [
16-
{
17-
id: "python",
18-
lang: "Python",
19-
pages: [
20-
{ id: 1, title: "環境構築と基本思想" },
21-
{ id: 2, title: "基本構文とデータ型" },
22-
{ id: 3, title: "リスト、タプル、辞書、セット" },
23-
{ id: 4, title: "制御構文と関数" },
24-
{ id: 5, title: "モジュールとパッケージ" },
25-
{ id: 6, title: "オブジェクト指向プログラミング" },
26-
{
27-
id: 7,
28-
title: "ファイルの入出力とコンテキストマネージャ",
29-
},
30-
{ id: 8, title: "例外処理" },
31-
{ id: 9, title: "ジェネレータとデコレータ" },
32-
],
33-
},
34-
{
35-
id: "cpp",
36-
lang: "C++",
37-
pages: [
38-
{ id: 2, title: "型システムとメモリ" },
39-
{ id: 3, title: "関数と参照" },
40-
],
41-
},
42-
];
43-
4416
if (error) console.error("Sidebar fetch error:", error);
4517

4618
const splitmdcontent = splitMarkdown(data ?? "");
@@ -53,7 +25,7 @@ export function Sidebar() {
5325
</h2>
5426

5527
<ul className="menu w-full">
56-
{pages.map((group) => (
28+
{pagesList.map((group) => (
5729
<li key={group.id}>
5830
<details open={docs_id.startsWith(`${group.id}-`)}>
5931
<summary>{group.lang}</summary>

0 commit comments

Comments
 (0)