-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.jsx
51 lines (49 loc) · 1.52 KB
/
index.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import clsx from "clsx";
import { BiLinkExternal } from "react-icons/bi";
import { SiGithub } from "react-icons/si";
import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
import styles from "./styles.module.css";
const repositoryRootPathLength =
import.meta.url.split("/").slice(0, -4).join("/").length + 1;
/**
* @param {Object} props
* @param {string} props.url
* @param {boolean} props.path
* @param {boolean} props.noCodeSandbox
*/
export default function ViewSource({ url, path, noCodeSandbox }) {
const basePath = url.slice(repositoryRootPathLength);
const commitRef = useDocusaurusContext()?.siteConfig.customFields.commitRef;
const gitHubUrl = new URL(
path,
`https://github.com/ut-code/utcode-learn/tree/${commitRef}/${basePath}`,
);
const codeSandboxUrl = new URL(
path,
`https://githubbox.com/ut-code/utcode-learn/tree/${commitRef}/${basePath}`,
);
return (
<div className={styles.root}>
<a
className={clsx("button button--secondary", styles.button)}
target="_blank"
rel="noopener"
href={gitHubUrl.toString()}
>
<SiGithub className={styles.icon} />
GitHub で表示
</a>
{!noCodeSandbox && (
<a
className={clsx("button button--primary", styles.button)}
target="_blank"
rel="noopener"
href={codeSandboxUrl.toString()}
>
このプログラムを実行する
<BiLinkExternal className={styles.icon} />
</a>
)}
</div>
);
}