Skip to content

Commit 8600310

Browse files
committed
コメントを追加
1 parent 934aa8c commit 8600310

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

src/components/OpenInColab/OpenInColab.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ import React from "react";
22
import usePathname from "../usePathname";
33
import styles from "./styles.module.css";
44

5+
/**
6+
* OpenInColabへのリンクをつくるコンポーネント
7+
* @param param0 現在ファイルからのipynbへの相対パス
8+
* @returns OpenInColabへのリンク
9+
*/
10+
511
export default function OpenInColab({ path }) {
612
const pathname = usePathname();
713
return (

src/components/ViewSource/ViewSource.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,30 @@ import CodeBlock from "@theme/CodeBlock";
33
import usePathname from "../usePathname";
44
import OpenInColab from "../OpenInColab/OpenInColab";
55

6+
/**
7+
* ipynbファイルからソースコードと出力、OpenInColabへのリンクを生成
8+
* @param param0 現在ファイルからのipynbへの相対パス
9+
* @param param1 Pythonの出力を表示するか
10+
* @returns ソースコードと出力、OpenInColabへのリンク
11+
*/
12+
613
export default function ViewSource({ path, nooutput = false }) {
714
const pathname = usePathname();
815
const [sources, setSources] = useState<string[]>([]);
916
const [outputs, setOutputs] = useState<string[]>([]);
1017
useEffect(() => {
1118
async function tmp() {
19+
// 該当のipynbファイルをjson形式でとってくる
1220
const content = await import(
1321
`/docs/${pathname.slice(6)}${path.slice(0, -6)}.json`
1422
);
23+
// ソースコードを取り出す
1524
setSources(
1625
content.cells
1726
.filter((cell) => cell.cell_type === "code")
1827
.map((cell) => cell.source.join(""))
1928
);
29+
// outputを取り出す
2030
setOutputs(
2131
content.cells
2232
.filter((cell) => cell.cell_type === "code")
@@ -39,7 +49,9 @@ export default function ViewSource({ path, nooutput = false }) {
3949
<>
4050
{sources.map((source, i) => (
4151
<React.Fragment key={i}>
52+
{/* ソースコード */}
4253
<CodeBlock language="python">{source}</CodeBlock>
54+
{/* output */}
4355
{!nooutput && (
4456
<CodeBlock language="plaintext">{outputs[i]}</CodeBlock>
4557
)}

src/components/usePathname.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { useLocation } from "@docusaurus/router";
22
import config from "@generated/docusaurus.config";
33

4+
/**
5+
* ファイルの絶対パスを表示
6+
* @returns ファイルの絶対パス
7+
*/
8+
49
export default function usePathname() {
510
const pathname = useLocation().pathname.slice(config.baseUrl.length - 1);
611
return pathname;

0 commit comments

Comments
 (0)