-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor getLatestVersion to getLatestVersionWarningUrl [elifescience…
- Loading branch information
1 parent
abe62e5
commit 1d7d972
Showing
6 changed files
with
46 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { EnhancedArticleWithVersions } from '../../types'; | ||
import { isPreprintVersionSummary } from '../type-guards'; | ||
|
||
export const getLatestVersionWarningUrl = (articleWithVersions: EnhancedArticleWithVersions): string | null => { | ||
const publishedDesc = Object.values(articleWithVersions.versions) // get the versions in an array | ||
.filter((ver) => ver.published && new Date(ver.published).getTime() <= (new Date()).getTime()) // get only the versions that have been published | ||
.sort((a, b) => new Date(a.published!).getTime() - new Date(b.published!).getTime()) // sort them by published date | ||
.reverse(); | ||
|
||
const latestVersion = publishedDesc[0]; | ||
|
||
if (latestVersion && latestVersion.versionIdentifier !== articleWithVersions.article.versionIdentifier) { | ||
return isPreprintVersionSummary(latestVersion) ? `/reviewed-preprints/${articleWithVersions.article.msid}` : `https://doi.org/${latestVersion.doi}`; | ||
} | ||
|
||
return null; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export { fetchVersion, fetchVersions, fetchVersionsNoContent } from './fetch-data'; | ||
export { getLatestVersion } from './get-latest-version'; | ||
export { getLatestVersionWarningUrl } from './get-latest-version-warning-url'; | ||
export { jsonFetch, jsonFetchOrNull } from './json-fetch'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters