Skip to content

Commit

Permalink
✍️ Keep all contributors/affiliations until final page resolution (#1390
Browse files Browse the repository at this point in the history
)

Co-authored-by: Rowan Cockett <[email protected]>
  • Loading branch information
fwkoch and rowanc1 authored Jul 15, 2024
1 parent 167238b commit 8c48799
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/eight-gifts-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'myst-frontmatter': patch
---

Keep all contributors/affiliations until final page resolution
28 changes: 27 additions & 1 deletion packages/myst-frontmatter/src/utils/fillPageFrontmatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,21 @@ export function fillPageFrontmatter(
projectFrontmatter: ProjectFrontmatter,
opts: ValidationOptions,
): PageFrontmatter {
return fillProjectFrontmatter(pageFrontmatter, projectFrontmatter, opts, USE_PROJECT_FALLBACK);
return fillProjectFrontmatter(
pageFrontmatter,
projectFrontmatter,
opts,
USE_PROJECT_FALLBACK,
true,
);
}

export function fillSiteFrontmatter(
base: SiteFrontmatter,
filler: SiteFrontmatter,
opts: ValidationOptions,
keys?: string[],
trimUnused?: boolean,
) {
const frontmatter = fillMissingKeys(base, filler, keys ?? Object.keys(filler));

Expand Down Expand Up @@ -65,6 +72,17 @@ export function fillSiteFrontmatter(
contributorIds.add(editor);
});

if (!trimUnused) {
[
...(base.authors ?? []),
...(filler.authors ?? []),
...(base.contributors ?? []),
...(filler.contributors ?? []),
].forEach((auth) => {
if (auth.id) contributorIds.add(auth.id);
});
}

if (frontmatter.authors?.length || contributorIds.size) {
// Gather all people from page/project authors/contributors
const people = [
Expand Down Expand Up @@ -110,6 +128,12 @@ export function fillSiteFrontmatter(
if (aff.id) affiliationIds.add(aff.id);
});

if (!trimUnused) {
[...(base.affiliations ?? []), ...(filler.affiliations ?? [])].forEach((aff) => {
if (aff.id) affiliationIds.add(aff.id);
});
}

if (affiliationIds.size) {
const affiliations = [...(base.affiliations ?? []), ...(filler.affiliations ?? [])];
const affiliationLookup: Record<string, Affiliation> = {};
Expand Down Expand Up @@ -137,12 +161,14 @@ export function fillProjectFrontmatter(
filler: ProjectFrontmatter,
opts: ValidationOptions,
keys?: string[],
trimUnused?: boolean,
) {
const frontmatter: ProjectFrontmatter = fillSiteFrontmatter(
base,
filler,
opts,
keys ?? Object.keys(filler),
trimUnused,
);

if (filler.numbering || base.numbering) {
Expand Down

0 comments on commit 8c48799

Please sign in to comment.