File tree Expand file tree Collapse file tree 2 files changed +10
-2
lines changed
website/src/layout/components/OpenElsewhereLinks Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ import { getGithubSlug } from "../utils/github"
55
66import 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
1010interface OpenInColabProps {
1111 fsPath : string [ ]
Original file line number Diff line number Diff line change @@ -2,4 +2,12 @@ export const REPO_OWNER = 'acmucsd'
22export const REPO_NAME = 'acm-ai-workshops'
33export 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+ )
You can’t perform that action at this time.
0 commit comments