Skip to content

Commit

Permalink
📦 Upgrade v0.9.5, Footnotes, Localize ArticlePage
Browse files Browse the repository at this point in the history
  • Loading branch information
stevejpurves committed Jun 14, 2024
1 parent f8603a9 commit 9c7745f
Show file tree
Hide file tree
Showing 6 changed files with 2,261 additions and 988 deletions.
94 changes: 94 additions & 0 deletions theme/app/components/ArticlePage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { ReferencesProvider, useProjectManifest } from '@myst-theme/providers';
import {
Bibliography,
ContentBlocks,
FooterLinksBlock,
FrontmatterParts,
BackmatterParts,
Footnotes,
extractKnownParts,
} from '@myst-theme/site';
import type { PageLoader } from '@myst-theme/common';
import { copyNode, type GenericParent } from 'myst-common';
import { SourceFileKind } from 'myst-spec-ext';
import {
ExecuteScopeProvider,
BusyScopeProvider,
NotebookToolbar,
ConnectionStatusTray,
ErrorTray,
useComputeOptions,
} from '@myst-theme/jupyter';
import { FrontmatterBlock } from '@myst-theme/frontmatter';
import type { SiteAction } from 'myst-config';

/**
* Combines the project downloads and the export options
*/
function combineDownloads(
siteDownloads: SiteAction[] | undefined,
pageFrontmatter: PageLoader['frontmatter']
) {
if (pageFrontmatter.downloads) {
return pageFrontmatter.downloads;
}
// No downloads on the page, combine the exports if they exist
if (siteDownloads) {
return [...(pageFrontmatter.exports ?? []), ...siteDownloads];
}
return pageFrontmatter.exports;
}

export function ArticlePage({
article,
hide_all_footer_links,
hideKeywords,
}: {
article: PageLoader;
hide_all_footer_links?: boolean;
hideKeywords?: boolean;
}) {
const manifest = useProjectManifest();
const compute = useComputeOptions();

const { hide_title_block, hide_footer_links } = (article.frontmatter as any)?.options ?? {};
const downloads = combineDownloads(manifest?.downloads, article.frontmatter);
const tree = copyNode(article.mdast);
const keywords = article.frontmatter?.keywords ?? [];
const parts = extractKnownParts(tree);

return (
<ReferencesProvider
references={{ ...article.references, article: article.mdast }}
frontmatter={article.frontmatter}
>
<BusyScopeProvider>
<ExecuteScopeProvider enable={compute?.enabled ?? false} contents={article}>
{!hide_title_block && (
<FrontmatterBlock
kind={article.kind}
frontmatter={{ ...article.frontmatter, downloads }}
className="pt-5 mb-8"
/>
)}
{compute?.enabled &&
compute.features.notebookCompute &&
article.kind === SourceFileKind.Notebook && <NotebookToolbar showLaunch />}
{compute?.enabled && article.kind === SourceFileKind.Article && (
<ErrorTray pageSlug={article.slug} />
)}
<div id="skip-to-article" />
<FrontmatterParts parts={parts} keywords={keywords} hideKeywords={hideKeywords} />
<ContentBlocks pageKind={article.kind} mdast={tree as GenericParent} />
<BackmatterParts parts={parts} />
<Footnotes />
<Bibliography />
<ConnectionStatusTray />
{!hide_footer_links && !hide_all_footer_links && (
<FooterLinksBlock links={article.footer} />
)}
</ExecuteScopeProvider>
</BusyScopeProvider>
</ReferencesProvider>
);
}
2 changes: 2 additions & 0 deletions theme/app/routes/$project.($slug).tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
DocumentOutline,
ContentBlocks,
Bibliography,
Footnotes,
} from '@myst-theme/site';
import { FrontmatterBlock } from '@myst-theme/frontmatter';
import { ComputeOptionsProvider, ThebeLoaderAndServer } from '@myst-theme/jupyter';
Expand Down Expand Up @@ -42,6 +43,7 @@ function ArticlePage({ article }: { article: PageLoader }) {
<>
<div id="skip-to-article" />
<ContentBlocks mdast={article.mdast as GenericParent} />
<Footnotes />
<Bibliography />
<FooterLinksBlock links={article.footer} />
</>
Expand Down
3 changes: 2 additions & 1 deletion theme/app/routes/_index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import type { LinksFunction, LoaderFunction, V2_MetaFunction } from '@remix-run/node';
import type { PageLoader } from '@myst-theme/common';
import { getMetaTagsForArticle, KatexCSS, ArticlePage } from '@myst-theme/site';
import { getMetaTagsForArticle, KatexCSS } from '@myst-theme/site';
import { ComputeOptionsProvider, ThebeLoaderAndServer } from '@myst-theme/jupyter';
import { getPage } from '~/utils/loaders.server';
import { useLoaderData } from '@remix-run/react';
import { ArticleAndNavigation, HeaderSection, NavigationAndFooter } from '../components/Page';
import { Error404 } from '../components/Error404';
import { ProjectProvider } from '@myst-theme/providers';
import { ArticlePage } from '~/components/ArticlePage';

export const meta: V2_MetaFunction = ({ data, location }) => {
if (!data) return [];
Expand Down
3 changes: 2 additions & 1 deletion theme/app/routes/overview.($slug).tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import type { LoaderFunction, V2_MetaFunction } from '@remix-run/node';
import type { PageLoader } from '@myst-theme/common';
import { ArticlePage, getMetaTagsForArticle } from '@myst-theme/site';
import { getMetaTagsForArticle } from '@myst-theme/site';
import { ComputeOptionsProvider, ThebeLoaderAndServer } from '@myst-theme/jupyter';
import { getPage } from '../utils/loaders.server';
import { NavLink, useLoaderData } from '@remix-run/react';
import { ArticleAndNavigation, NavigationAndFooter } from '../components/Page';
import { BaseUrlProvider, ProjectProvider, useSiteManifest } from '@myst-theme/providers';
import classNames from 'classnames';
import { Error404 } from '../components/Error404';
import { ArticlePage } from '~/components/ArticlePage';

const baseurl = 'overview';

Expand Down
Loading

0 comments on commit 9c7745f

Please sign in to comment.