-
Notifications
You must be signed in to change notification settings - Fork 7
enable opening workshops and directories in github #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| export const REPO_OWNER = 'acmucsd' | ||
| export const REPO_NAME = 'acm-ai-workshops' | ||
| export const DEFAULT_BRANCH = 'main' | ||
|
|
||
| export const getGithubSlug = (fsPath: string[]) => `${REPO_OWNER}/${REPO_NAME}/blob/${DEFAULT_BRANCH}/${fsPath.map(encodeURIComponent).join('/')}` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import { useMemo } from "react" | ||
| import Link from "next/link" | ||
|
|
||
| import { getGithubSlug } from "@/helpers/github" | ||
|
|
||
| import s from "../styles.module.scss" | ||
|
|
||
| const getColabUrl = (fsPath: string[]) => `https://colab.research.google.com/github/${getGithubSlug(fsPath)}` | ||
|
|
||
| interface OpenInColabProps { | ||
| fsPath: string[] | ||
| } | ||
|
|
||
| export default function OpenInColab ({ fsPath }: OpenInColabProps) { | ||
| const colabUrl = useMemo(() => getColabUrl(fsPath), [fsPath]) | ||
|
|
||
| return ( | ||
| <Link href={colabUrl}><a className={s.link}> | ||
| <span className={s.label}>Open in Colab</span> | ||
| {ExternalLinkSvg} | ||
| </a></Link> | ||
| ) | ||
| } | ||
|
|
||
| const ExternalLinkSvg = ( | ||
| <svg className={s.svg} width="1em" height="1em" viewBox="0 0 48 48" fill="currentColor"> | ||
| <path d="M36 24c-1.2 0-2 0.8-2 2v12c0 1.2-0.8 2-2 2h-22c-1.2 | ||
| 0-2-0.8-2-2v-22c0-1.2 0.8-2 2-2h12c1.2 0 2-0.8 2-2s-0.8-2-2-2h-12c-3.4 | ||
| 0-6 2.6-6 6v22c0 3.4 2.6 6 6 6h22c3.4 0 6-2.6 | ||
| 6-6v-12c0-1.2-0.8-2-2-2z" /> | ||
| <path d="M43.8 5.2c-0.2-0.4-0.6-0.8-1-1-0.2-0.2-0.6-0.2-0.8-0.2h-12c-1.2 | ||
| 0-2 0.8-2 2s0.8 2 2 2h7.2l-18.6 18.6c-0.8 0.8-0.8 2 0 2.8 0.4 0.4 0.8 | ||
| 0.6 1.4 0.6s1-0.2 1.4-0.6l18.6-18.6v7.2c0 1.2 0.8 2 2 2s2-0.8 | ||
| 2-2v-12c0-0.2 0-0.6-0.2-0.8z" /> | ||
| </svg> | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import { useMemo } from "react" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. small nit but we could turn open in X a component in itself. Basically accepts a url generator and icon. But i think we're only ever gonna do github and colab really so it's probably fine. |
||
| import Link from "next/link" | ||
|
|
||
| import { getGithubSlug } from "@/helpers/github" | ||
|
|
||
| import s from "../styles.module.scss" | ||
|
|
||
| const getGithubUrl = (fsPath: string[]) => `https://github.com/${getGithubSlug(fsPath)}` | ||
|
|
||
| interface OpenInGithubProps { | ||
| fsPath: string[] | ||
| } | ||
|
|
||
| export default function OpenInGithub ({ fsPath }: OpenInGithubProps) { | ||
| const githubUrl = useMemo(() => getGithubUrl(fsPath), [fsPath]) | ||
|
|
||
| return ( | ||
| <Link href={githubUrl}><a className={s.link}> | ||
| {GithubSvg} | ||
| <span className={s.label}>Open in GitHub</span> | ||
| </a></Link> | ||
| ) | ||
| } | ||
|
|
||
| // TODO: we use github svg here (because we want to animate changing its color) but use img with svg source in header. the way we use it should be standardized | ||
| const GithubSvg = ( | ||
| <svg className={s.svg} width="1em" height="1em" viewBox="0 0 16 16" fill="currentColor"> | ||
| <path | ||
| fillRule="evenodd" | ||
| d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 | ||
| 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 | ||
| 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 | ||
| 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 | ||
| 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 | ||
| 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 | ||
| 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z" | ||
| /> | ||
| </svg> | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import s from "./styles.module.scss" | ||
| import OpenInColab from "./OpenInColab" | ||
| import OpenInGithub from "./OpenInGithub" | ||
|
|
||
| interface OpenElsewhereLinksProps { | ||
| fsPath: string[] | ||
| } | ||
|
|
||
| export default function OpenElsewhereLinks ({ fsPath }: OpenElsewhereLinksProps) { | ||
| return ( | ||
| <div className={s.links}> | ||
| <OpenInColab fsPath={fsPath} /> | ||
| <OpenInGithub fsPath={fsPath} /> | ||
| </div> | ||
| ) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| @use "@/styles/colors"; | ||
|
|
||
| .links { | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: space-between; | ||
| gap: 0.5rem 2rem; | ||
| flex-wrap: wrap; | ||
| } | ||
|
|
||
| .link { | ||
| padding: 0.5rem; | ||
| font-weight: 600; | ||
| display: flex; | ||
| align-items: center; | ||
| gap: 0.25em; | ||
|
|
||
| transition: color 400ms ease; | ||
| &:hover { | ||
| color: colors.$red; | ||
|
|
||
| & .svg { | ||
| fill: colors.$red; | ||
| } | ||
| } | ||
|
|
||
| .label, .svg { | ||
| flex: 0 0 auto; | ||
| } | ||
|
|
||
| .svg { | ||
| width: 1em; | ||
| height: 1em; | ||
|
|
||
| fill: currentColor; | ||
| transition: fill 400ms ease; | ||
| } | ||
| } |
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fr units 😳