Skip to content

Commit 4ef3af1

Browse files
committed
fix: ensure colab url uses blob
1 parent 448ee25 commit 4ef3af1

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

website/src/layout/components/OpenElsewhereLinks/OpenInColab/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { getGithubSlug } from "../utils/github"
55

66
import s from "../styles.module.scss"
77

8-
const getColabUrl = (fsPath: string[]) => `https://colab.research.google.com/github/${getGithubSlug(fsPath)}`
8+
const getColabUrl = (fsPath: string[]) => `https://colab.research.google.com/github/${getGithubSlug(fsPath, { blob: true })}`
99

1010
interface OpenInColabProps {
1111
fsPath: string[]

website/src/layout/components/OpenElsewhereLinks/utils/github.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,12 @@ export const REPO_OWNER = 'acmucsd'
22
export const REPO_NAME = 'acm-ai-workshops'
33
export const DEFAULT_BRANCH = 'main'
44

5-
export const getGithubSlug = (fsPath: string[]) => `${REPO_OWNER}/${REPO_NAME}/tree/${DEFAULT_BRANCH}/${fsPath.map(encodeURIComponent).join('/')}`
5+
// GitHub uses `blob` for files and `tree` for directories
6+
// `/tree/file` auto redirects to `/blob/file` but not vice versa so we want to use `tree` by default
7+
// but Colab expects a well-formed `blob`
8+
export const getGithubSlug = (
9+
fsPath: string[],
10+
{ blob = false }: { blob?: boolean } = {},
11+
) => (
12+
`${REPO_OWNER}/${REPO_NAME}/${blob ? 'blob' : 'tree'}/${DEFAULT_BRANCH}/${fsPath.map(encodeURIComponent).join('/')}`
13+
)

0 commit comments

Comments
 (0)