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:
Marco Nenciarini 2026-08-25 12:23:25 +02:00 committed by Francesco Canovai
parent c18ce8a12b
commit a28fd19113

View File

@ -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 {
@ -20,20 +20,5 @@ export function useCurrentVersion(fallback: 'latest' | 'latestReleased' = 'lates
}
export function useLatestReleasedVersion(): string {
const allVersions = useVersions('default');
// 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;
return useLatestVersion('default').name;
}