-
Notifications
You must be signed in to change notification settings - Fork 1
各章の目次表示 #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
各章の目次表示 #19
Changes from 3 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7099360
各章の目次表示
Tatsu723 7bb5828
(未使用の関数削除)
Tatsu723 a1fa061
(未使用変数iの削除)
Tatsu723 78b6a81
splitMarkdownClientの削除
Tatsu723 d2abe89
fetcherの型修正+list-disc,list-decimalの削除
Tatsu723 a5f41d2
isLoading及びerrorにおける処理変更
Tatsu723 a11eea7
error再修正
Tatsu723 685b915
error再々修正
Tatsu723 9d7a974
各セクションにジャンプする機能追加
Tatsu723 dd903f8
ローディング処理変更+インデント変更
Tatsu723 7f38b14
インデント方法の修正
Tatsu723 4e45fab
リストの記述簡略化
Tatsu723 6899f4e
level4以下への対応
Tatsu723 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import { MarkdownSection } from "./splitMarkdown"; | ||
|
|
||
| export function splitMarkdownClient(content: string): MarkdownSection[] { | ||
| const lines = content.split("\n"); | ||
| const sections: MarkdownSection[] = []; | ||
| let current: MarkdownSection | null = null; | ||
|
|
||
| for (const line of lines) { | ||
| const match = line.match(/^(#{1,6})\s+(.*)/); // 見出しを検出 | ||
| if (match) { | ||
| if (current) sections.push(current); // 前のセクションを保存 | ||
| current = { | ||
| level: match[1].length, // 見出しレベル(# の数) | ||
| title: match[2].trim(), // 見出しタイトル | ||
| content: "", // 内容は後続行で追加 | ||
| }; | ||
| } else if (current) { | ||
| current.content += line + "\n"; // セクション内容に追加 | ||
| } | ||
| } | ||
| if (current) sections.push(current); // 最後のセクションを保存 | ||
| return sections.map((s) => ({ ...s, content: s.content.trim() })); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,42 +1,63 @@ | ||
| "use client"; | ||
| import Link from "next/link"; | ||
| import { usePathname } from "next/navigation"; | ||
| import useSWR from 'swr' | ||
| import { splitMarkdownClient } from "./[docs_id]/splitMarkdownClient"; | ||
|
|
||
|
|
||
|
|
||
| export function Sidebar() { | ||
| const fetcher = (url: string | URL | Request<unknown, CfProperties<unknown>>) => fetch(url).then((r) => r.text()) | ||
| const pathname = usePathname(); | ||
| const docs_id = pathname.replace(/^\//, ""); | ||
| const { data, error, isLoading } = useSWR( | ||
| `/docs/${docs_id}.md`, | ||
| fetcher | ||
| ) | ||
|
|
||
| if (isLoading) return <div>Loading...</div> | ||
| if (error) return <div>Error: {error.message}</div> | ||
na-trium-144 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| const pages = [ | ||
| { id: "python-1", title: "1. 環境構築と基本思想" }, | ||
| { id: "python-2", title: "2. 基本構文とデータ型" }, | ||
| { id: "python-3", title: "3. リスト、タプル、辞書、セット" }, | ||
| { id: "python-4", title: "4. 制御構文と関数" }, | ||
| { id: "python-5", title: "5. モジュールとパッケージ" }, | ||
| { id: "python-6", title: "6. オブジェクト指向プログラミング" }, | ||
| { id: "python-7", title: "7. ファイルの入出力とコンテキストマネージャ" }, | ||
| { id: "python-8", title: "8. 例外処理" }, | ||
| { id: "python-9", title: "9. ジェネレータとデコレータ" }, | ||
| ]; | ||
|
|
||
|
|
||
| const splitmdcontent = splitMarkdownClient(data ?? "") | ||
| return ( | ||
| <div className="bg-base-200 min-h-full w-80 p-4"> | ||
| {/* todo: 背景色ほんとにこれでいい? */} | ||
| <h2 className="hidden lg:block text-xl font-bold mb-4"> | ||
| {/* サイドバーが常時表示されている場合のみ */} | ||
| Navbar Title | ||
| </h2> | ||
|
|
||
| <ol className="menu w-full list-decimal list-outside"> | ||
| <li> | ||
| <Link href="/python-1">1. 環境構築と基本思想</Link> | ||
| </li> | ||
| <li> | ||
| <Link href="/python-2">2. 基本構文とデータ型</Link> | ||
| </li> | ||
| <li> | ||
| <Link href="/python-3">3. リスト、タプル、辞書、セット</Link> | ||
| </li> | ||
| <li> | ||
| <Link href="/python-4">4. 制御構文と関数</Link> | ||
| </li> | ||
| <li> | ||
| <Link href="/python-5">5. モジュールとパッケージ</Link> | ||
| </li> | ||
| <li> | ||
| <Link href="/python-6">6. オブジェクト指向プログラミング</Link> | ||
| </li> | ||
| <li> | ||
| <Link href="/python-7">7. ファイルの入出力とコンテキストマネージャ</Link> | ||
| </li> | ||
| <li> | ||
| <Link href="/python-8">8. 例外処理</Link> | ||
| </li> | ||
| <li> | ||
| <Link href="/python-9">9. ジェネレータとデコレータ</Link> | ||
| </li> | ||
| {pages.map((page) => ( | ||
| <li key={page.id}> | ||
| <Link href={`/${page.id}`}>{page.title}</Link> | ||
| {page.id === docs_id && ( | ||
| <ul className="ml-4 mt-2 list-disc text-sm"> | ||
na-trium-144 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| {splitmdcontent | ||
| .filter(section => section.level !== 1) | ||
| .map((section, idx) => ( | ||
| <li key={idx}>{section.title}</li> | ||
na-trium-144 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ))} | ||
| </ul> | ||
| )} | ||
|
|
||
| </li> | ||
| ))} | ||
| </ol> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.