-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #369 from executablebooks/agoose77/wip-outline-inline
📑 Add document outline mobile view
- Loading branch information
Showing
12 changed files
with
187 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@myst-theme/site': patch | ||
--- | ||
|
||
Mark ArticlePage as deprecated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@myst-theme/article': patch | ||
'@myst-theme/book': patch | ||
--- | ||
|
||
Support inline navigation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export interface TemplateOptions { | ||
hide_toc?: boolean; | ||
hide_outline?: boolean; | ||
hide_footer_links?: boolean; | ||
outline_maxdepth?: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import React from 'react'; | ||
import { ReferencesProvider, useProjectManifest, useSiteManifest } from '@myst-theme/providers'; | ||
import { | ||
Bibliography, | ||
ContentBlocks, | ||
FooterLinksBlock, | ||
FrontmatterParts, | ||
BackmatterParts, | ||
DocumentOutline, | ||
extractKnownParts, | ||
} from '@myst-theme/site'; | ||
import type { SiteManifest } from 'myst-config'; | ||
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'; | ||
import type { TemplateOptions } from '../types.js'; | ||
|
||
/** | ||
* 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 const ArticlePage = React.memo(function ({ | ||
article, | ||
hide_all_footer_links, | ||
hideKeywords, | ||
}: { | ||
article: PageLoader; | ||
hide_all_footer_links?: boolean; | ||
hideKeywords?: boolean; | ||
}) { | ||
const manifest = useProjectManifest(); | ||
const compute = useComputeOptions(); | ||
|
||
const pageDesign: TemplateOptions = (article.frontmatter as any)?.options ?? {}; | ||
const siteDesign: TemplateOptions = | ||
(useSiteManifest() as SiteManifest & TemplateOptions)?.options ?? {}; | ||
const { hide_title_block, hide_footer_links, hide_outline, outline_maxdepth } = { | ||
...siteDesign, | ||
...pageDesign, | ||
}; | ||
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" | ||
/> | ||
)} | ||
{!hide_outline && ( | ||
<div className="block my-10 lg:sticky lg:top-0 lg:z-10 lg:h-0 lg:pt-2 lg:my-0 lg:ml-10 lg:col-margin-right"> | ||
<DocumentOutline className="relative" maxdepth={outline_maxdepth} /> | ||
</div> | ||
)} | ||
{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} /> | ||
<Bibliography /> | ||
<ConnectionStatusTray /> | ||
{!hide_footer_links && !hide_all_footer_links && ( | ||
<FooterLinksBlock links={article.footer} /> | ||
)} | ||
</ExecuteScopeProvider> | ||
</BusyScopeProvider> | ||
</ReferencesProvider> | ||
); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export interface TemplateOptions { | ||
hide_toc?: boolean; | ||
hide_outline?: boolean; | ||
hide_footer_links?: boolean; | ||
outline_maxdepth?: number; | ||
hide_title_block?: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters