Skip to content

Commit

Permalink
Add getPublishedOutput method in docmap-parser [elifesciences/enhance…
Browse files Browse the repository at this point in the history
…d-preprints-issues#1120]

This commit introduces a new function, getPublishedOutput, in docmap-parser.
This function checks the length of preprintOutputs and versionOfRecordOutputs
and returns the first item if there's one, otherwise it returns false. The
existing function getPublishedVersionOfRecord has been updated to use the newly
implemented getPublishedOutput function.
  • Loading branch information
nlisgo committed Jun 20, 2024
1 parent 5040ac2 commit 71cae09
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/parser/docmap-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,17 @@ const extractExpressions = (step: Step): ExtractedExpressions => {
};
};

const getPublishedOutput = (step: Step): Item | false => {
const items = extractExpressions(step);
if (items.preprintOutputs.length === 1) {
return items.preprintOutputs[0];
}
if (items.versionOfRecordOutputs.length === 1) {
return items.versionOfRecordOutputs[0];
}
return false;
};

const getPublishedVersionOfRecord = (step: Step): Item | false => {
const items = extractExpressions(step);
return (items.versionOfRecordOutputs.length === 1) ? items.versionOfRecordOutputs[0] : false;
Expand Down Expand Up @@ -470,8 +481,8 @@ const parseStep = (step: Step, preprints: Array<ReviewedPreprint>, manuscript: M
preprint.corrections = [];
}
const correction = { correctedDate: preprintCorrectedAssertion.happened };
const versionOfRecord = getPublishedVersionOfRecord(step);
const content = (versionOfRecord && versionOfRecord.content ? versionOfRecord.content : []).reduce<string[]>((ac, { type, url }) => {
const publishedOutput = getPublishedOutput(step);
const content = (publishedOutput && publishedOutput.content ? publishedOutput.content : []).reduce<string[]>((ac, { type, url }) => {
if (type === 'web-page' && url) {
ac.push(url);
}
Expand Down

0 comments on commit 71cae09

Please sign in to comment.