Skip to content

Commit 460f6d9

Browse files
committed
CodeSandbox へのリンクにコミットSHAを使用する
1 parent 9195283 commit 460f6d9

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

.github/workflows/deploy.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ jobs:
1414
with:
1515
fetch-depth: 0
1616
- run: npm ci && npm run build
17+
env:
18+
COMMIT_REF: ${{ github.sha }}
1719
- uses: actions/upload-pages-artifact@v2
1820
with:
1921
path: build

src/components/ViewSource/index.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import clsx from "clsx";
33
import { BiLinkExternal } from "react-icons/bi";
44
import { SiGithub } from "react-icons/si";
55
import styles from "./styles.module.css";
6+
import { COMMIT_REF } from "../../env";
67

78
/**
89
* @param {Object} props
@@ -23,7 +24,7 @@ export default function ViewSource({ url, path, noCodeSandbox }) {
2324
className={clsx("button button--secondary", styles.button)}
2425
target="_blank"
2526
rel="noopener"
26-
href={`https://github.com/ut-code/utcode-learn/tree/master/${relativePath}`}
27+
href={`https://github.com/ut-code/utcode-learn/tree/${COMMIT_REF}/${relativePath}`}
2728
>
2829
<SiGithub className={styles.icon} />
2930
GitHub で表示
@@ -33,7 +34,7 @@ export default function ViewSource({ url, path, noCodeSandbox }) {
3334
className={clsx("button button--primary", styles.button)}
3435
target="_blank"
3536
rel="noopener"
36-
href={`https://githubbox.com/ut-code/utcode-learn/tree/master/${relativePath}`}
37+
href={`https://githubbox.com/ut-code/utcode-learn/tree/${COMMIT_REF}/${relativePath}`}
3738
>
3839
このプログラムを実行する
3940
<BiLinkExternal className={styles.icon} />

src/env.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const COMMIT_REF = process.env.COMMIT_REF ?? "HEAD";

0 commit comments

Comments
 (0)