From 8c487991791e0bfa492a63e400f037dddc444f36 Mon Sep 17 00:00:00 2001 From: Franklin Koch Date: Sun, 14 Jul 2024 18:00:48 -0600 Subject: [PATCH] =?UTF-8?q?=E2=9C=8D=EF=B8=8F=20Keep=20all=20contributors/?= =?UTF-8?q?affiliations=20until=20final=20page=20resolution=20(#1390)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Rowan Cockett --- .changeset/eight-gifts-live.md | 5 ++++ .../src/utils/fillPageFrontmatter.ts | 28 ++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 .changeset/eight-gifts-live.md diff --git a/.changeset/eight-gifts-live.md b/.changeset/eight-gifts-live.md new file mode 100644 index 000000000..f6bf412b6 --- /dev/null +++ b/.changeset/eight-gifts-live.md @@ -0,0 +1,5 @@ +--- +'myst-frontmatter': patch +--- + +Keep all contributors/affiliations until final page resolution diff --git a/packages/myst-frontmatter/src/utils/fillPageFrontmatter.ts b/packages/myst-frontmatter/src/utils/fillPageFrontmatter.ts index 9c5fb3b6a..ddf33ea37 100644 --- a/packages/myst-frontmatter/src/utils/fillPageFrontmatter.ts +++ b/packages/myst-frontmatter/src/utils/fillPageFrontmatter.ts @@ -21,7 +21,13 @@ 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( @@ -29,6 +35,7 @@ export function fillSiteFrontmatter( filler: SiteFrontmatter, opts: ValidationOptions, keys?: string[], + trimUnused?: boolean, ) { const frontmatter = fillMissingKeys(base, filler, keys ?? Object.keys(filler)); @@ -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 = [ @@ -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 = {}; @@ -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) {