Skip to content

Commit

Permalink
Update knownParts function
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanc1 committed Oct 17, 2024
1 parent a03edd8 commit 995fb41
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 27 deletions.
2 changes: 1 addition & 1 deletion packages/common/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export type FooterLinks = {
};

type PageFrontmatterWithDownloads = Omit<PageFrontmatter, 'parts' | 'downloads' | 'exports'> & {
parts?: Record<string, GenericParent>;
parts?: Record<string, { frontmatter?: PageFrontmatter; mdast: GenericParent }>;
downloads?: SiteAction[];
exports?: SiteExport[];
};
Expand Down
9 changes: 1 addition & 8 deletions packages/site/src/pages/Article.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,7 @@ export const ArticlePage = React.memo(function ({
const downloads = combineDownloads(manifest?.downloads, article.frontmatter);
const tree = copyNode(article.mdast);
const keywords = article.frontmatter?.keywords ?? [];
const parts = {
...extractKnownParts(tree),
...Object.fromEntries(
Object.entries(article.frontmatter?.parts ?? {}).map(([k, v]) => {
return [k, v.mdast];
}),
),
};
const parts = extractKnownParts(tree, article.frontmatter?.parts);

return (
<ReferencesProvider
Expand Down
12 changes: 10 additions & 2 deletions packages/site/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,21 @@ export type KnownParts = {
acknowledgments?: GenericParent;
};

export function extractKnownParts(tree: GenericParent): KnownParts {
export function extractKnownParts(
tree: GenericParent,
parts?: Record<string, { mdast?: GenericParent }>,
): KnownParts {
const abstract = extractPart(tree, 'abstract');
const summary = extractPart(tree, 'summary', { requireExplicitPart: true });
const keypoints = extractPart(tree, ['keypoints'], { requireExplicitPart: true });
const data_availability = extractPart(tree, ['data_availability', 'data availability']);
const acknowledgments = extractPart(tree, ['acknowledgments', 'acknowledgements']);
return { abstract, summary, keypoints, data_availability, acknowledgments };
const otherParts = Object.fromEntries(
Object.entries(parts ?? {}).map(([k, v]) => {
return [k, v.mdast];
}),
);
return { abstract, summary, keypoints, data_availability, acknowledgments, ...otherParts };
}

/**
Expand Down
9 changes: 1 addition & 8 deletions themes/article/app/components/Article.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,7 @@ export function Article({
}) {
const keywords = article.frontmatter?.keywords ?? [];
const tree = copyNode(article.mdast);
const parts = {
...extractKnownParts(tree),
...Object.fromEntries(
Object.entries(article.frontmatter?.parts ?? {}).map(([k, v]) => {
return [k, v.mdast];
}),
),
};
const parts = extractKnownParts(tree, article.frontmatter?.parts);
const { title, subtitle } = article.frontmatter;
const compute = useComputeOptions();
const top = useThemeTop();
Expand Down
9 changes: 1 addition & 8 deletions themes/book/app/components/ArticlePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,7 @@ export const ArticlePage = React.memo(function ({
const downloads = combineDownloads(manifest?.downloads, article.frontmatter);
const tree = copyNode(article.mdast);
const keywords = article.frontmatter?.keywords ?? [];
const parts = {
...extractKnownParts(tree),
...Object.fromEntries(
Object.entries(article.frontmatter?.parts ?? {}).map(([k, v]) => {
return [k, v.mdast];
}),
),
};
const parts = extractKnownParts(tree, article.frontmatter?.parts);
const isOutlineMargin = useMediaQuery('(min-width: 1024px)');
return (
<ReferencesProvider
Expand Down

0 comments on commit 995fb41

Please sign in to comment.