diff --git a/.changeset/eighty-ducks-retire.md b/.changeset/eighty-ducks-retire.md new file mode 100644 index 000000000..42201fcb3 --- /dev/null +++ b/.changeset/eighty-ducks-retire.md @@ -0,0 +1,6 @@ +--- +'@myst-theme/site': patch +'@myst-theme/book': patch +--- + +Add abstract to book theme through an option in site: showAbstract diff --git a/packages/site/src/pages/Article.tsx b/packages/site/src/pages/Article.tsx index 93f9a7454..db64a064d 100644 --- a/packages/site/src/pages/Article.tsx +++ b/packages/site/src/pages/Article.tsx @@ -4,7 +4,7 @@ import { Bibliography, ContentBlocks, FooterLinksBlock } from '../components'; import { ErrorDocumentNotFound } from './ErrorDocumentNotFound'; import { ErrorProjectNotFound } from './ErrorProjectNotFound'; import type { PageLoader } from '@myst-theme/common'; -import type { GenericParent } from 'myst-common'; +import { copyNode, extractPart, type GenericParent } from 'myst-common'; import { SourceFileKind } from 'myst-spec-ext'; import { useComputeOptions, @@ -17,18 +17,26 @@ import { ErrorTray, } from '@myst-theme/jupyter'; import { FrontmatterBlock } from '@myst-theme/frontmatter'; +import classNames from 'classnames'; export const ArticlePage = React.memo(function ({ article, hide_all_footer_links, + showAbstract, + hideKeywords, }: { article: PageLoader; hide_all_footer_links?: boolean; + showAbstract?: boolean; + hideKeywords?: boolean; }) { const canCompute = useCanCompute(article); const { binderBadgeUrl } = useComputeOptions(); const { hide_title_block, hide_footer_links } = (article.frontmatter as any)?.design ?? {}; + const tree = copyNode(article.mdast); + const keywords = article.frontmatter?.keywords ?? []; + const abstract = showAbstract ? extractPart(tree, 'abstract') : undefined; // take binder url from article frontmatter or fallback to project const binderUrl = article.frontmatter.binder ?? binderBadgeUrl; @@ -53,7 +61,30 @@ export const ArticlePage = React.memo(function ({ )} {canCompute && article.kind === SourceFileKind.Notebook && } - + {abstract && ( + <> + Abstract +
+ +
+ {!hideKeywords && keywords.length > 0 && ( +
+ Keywords: + {keywords.map((k, i) => ( + + {k} + + ))} +
+ )} + + )} + {!hide_footer_links && !hide_all_footer_links && ( diff --git a/themes/book/app/routes/$.tsx b/themes/book/app/routes/$.tsx index 64495f575..3893a6763 100644 --- a/themes/book/app/routes/$.tsx +++ b/themes/book/app/routes/$.tsx @@ -101,7 +101,7 @@ export default function Page({ top = DEFAULT_NAV_HEIGHT }: { top?: number }) { return (
- + {!hide_outline && (