mirror of
https://github.com/cloudnative-pg/plugin-barman-cloud.git
synced 2026-09-04 22:22:21 +02:00
refactor(web): simplify useLatestReleasedVersion
Docusaurus already exposes the latest released version via useLatestVersion (backed by GlobalVersion.isLast), making the manual filter and numeric-string sort redundant. Signed-off-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com>
This commit is contained in:
parent
c18ce8a12b
commit
a28fd19113
@ -1,4 +1,4 @@
|
|||||||
import {useActiveVersion, useLatestVersion, useVersions} from '@docusaurus/plugin-content-docs/client';
|
import {useActiveVersion, useLatestVersion} from '@docusaurus/plugin-content-docs/client';
|
||||||
|
|
||||||
|
|
||||||
export function useCurrentVersion(fallback: 'latest' | 'latestReleased' = 'latest'): string {
|
export function useCurrentVersion(fallback: 'latest' | 'latestReleased' = 'latest'): string {
|
||||||
@ -20,20 +20,5 @@ export function useCurrentVersion(fallback: 'latest' | 'latestReleased' = 'lates
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function useLatestReleasedVersion(): string {
|
export function useLatestReleasedVersion(): string {
|
||||||
const allVersions = useVersions('default');
|
return useLatestVersion('default').name;
|
||||||
|
|
||||||
// Filter out "current" to only consider versioned docs
|
|
||||||
const versionedDocs = allVersions.filter(version => version.name !== 'current');
|
|
||||||
|
|
||||||
// Handle the case where no versioned documents are found
|
|
||||||
if (versionedDocs.length === 0) {
|
|
||||||
return "unknown_version";
|
|
||||||
}
|
|
||||||
|
|
||||||
const sortedVersions = versionedDocs.sort((a, b) => {
|
|
||||||
return b.name.localeCompare(a.name, undefined, { numeric: true, sensitivity: 'base' });
|
|
||||||
});
|
|
||||||
|
|
||||||
// The latest version is the first in the sorted list since versionedDocs was not empty,
|
|
||||||
return sortedVersions[0].name;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user