diff --git a/web/src/components/Installation/index.tsx b/web/src/components/Installation/index.tsx index 064a0ead..b149709e 100644 --- a/web/src/components/Installation/index.tsx +++ b/web/src/components/Installation/index.tsx @@ -1,16 +1,19 @@ import {ReactElement} from 'react'; import CodeBlock from '@theme/CodeBlock'; -import {useCurrentVersion} from '@site/src/hooks/versions'; +import {useActiveVersion} from '@docusaurus/plugin-content-docs/client'; -// InstallationSnippet is the kubectl incantation to install the lastest -// available version of the Barman Cloud Plugin. +// InstallationSnippet is the kubectl incantation to install the Barman +// Cloud Plugin: the manifest matching the doc version being viewed, or +// (on the unreleased "current" docs) the latest manifest on main. export function InstallationSnippet(): ReactElement { - const latest = useCurrentVersion('latestReleased'); + const activeVersion = useActiveVersion('default'); + const url = activeVersion && activeVersion.name !== 'current' + ? `https://github.com/cloudnative-pg/plugin-barman-cloud/releases/download/v${activeVersion.name}/manifest.yaml` + : 'https://raw.githubusercontent.com/cloudnative-pg/plugin-barman-cloud/refs/heads/main/manifest.yaml'; return ( {`kubectl apply -f \\ - https://github.com/cloudnative-pg/plugin-barman-cloud/releases/download/v${latest}/manifest.yaml`} + ${url}`} ); } - diff --git a/web/src/hooks/versions.ts b/web/src/hooks/versions.ts deleted file mode 100644 index 785cc2fb..00000000 --- a/web/src/hooks/versions.ts +++ /dev/null @@ -1,36 +0,0 @@ -import {useActiveVersion, useLatestVersion, useVersions} from '@docusaurus/plugin-content-docs/client'; - - -export function useCurrentVersion(fallback: 'latest' | 'latestReleased' = 'latest'): string { - switch (fallback) { - case 'latestReleased': - return useLatestReleasedVersion(); - case 'latest': { - const version = useActiveVersion('default'); - return version?.name ?? useLatestVersion('default')?.name; - } - default: - // The following line ensures that if `fallback` is not 'latest' or 'latestReleased', - // an error is thrown. This can be useful for catching unexpected states. - throw new Error(`Unhandled fallback type: ${fallback}`); - } -} - -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; -}