Skip to content

Commit

Permalink
📽accept project not site
Browse files Browse the repository at this point in the history
  • Loading branch information
stevejpurves committed Nov 27, 2023
1 parent 8684496 commit d2709ed
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions packages/jupyter/src/providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,17 @@ import type { SiteManifest } from 'myst-config';
import type { RepoProviderSpec } from 'thebe-core';

function makeThebeOptions(
siteManifest: SiteManifest | undefined,
project: Required<SiteManifest>['projects'][0],
optionsOverrideFn = (opts?: ExtendedCoreOptions) => opts,
): {
options?: ExtendedCoreOptions;
githubBadgeUrl?: string;
binderBadgeUrl?: string;
} {
if (!siteManifest) return {};
// TODO there may be multiple projects?
// useProjectManifest?
const mainProject = siteManifest?.projects?.[0];
const thebeFrontmatter = mainProject?.thebe;
const githubBadgeUrl = mainProject?.github;
const binderBadgeUrl = mainProject?.binder;
if (!project) return {};
const thebeFrontmatter = project?.thebe;
const githubBadgeUrl = project?.github;
const binderBadgeUrl = project?.binder;
const optionsFromFrontmatter = thebeFrontmatterToOptions(
thebeFrontmatter,
githubBadgeUrl,
Expand All @@ -45,21 +42,21 @@ type ThebeOptionsContextType = {
const ThebeOptionsContext = React.createContext<ThebeOptionsContextType | undefined>(undefined);

export function ConfiguredThebeServerProvider({
siteManifest,
project,
optionOverrideFn,
customRepoProviders,
children,
}: React.PropsWithChildren<{
siteManifest?: SiteManifest;
project?: Required<SiteManifest>['project'][0];
optionOverrideFn?: (opts?: ExtendedCoreOptions) => ExtendedCoreOptions | undefined;
customRepoProviders?: RepoProviderSpec[];
}>) {
const thebe = React.useMemo(
() => makeThebeOptions(siteManifest, optionOverrideFn),
[siteManifest, optionOverrideFn],
() => makeThebeOptions(project, optionOverrideFn),
[project, optionOverrideFn],
);

if (!siteManifest) return <>{children}</>;
if (!project) return <>{children}</>;

return (
<ThebeOptionsContext.Provider value={thebe}>
Expand Down

0 comments on commit d2709ed

Please sign in to comment.