mirror of
https://github.com/cloudnative-pg/plugin-barman-cloud.git
synced 2026-01-12 05:33:11 +01:00
docs: autoselect version
Define functions that can be used in mdx pages to dinamically choose the right version according to the documentation page viewed. Closes #343 Signed-off-by: Francesco Canovai <francesco.canovai@enterprisedb.com>
This commit is contained in:
parent
612064bae3
commit
2fc15432ce
@ -6,6 +6,20 @@ sidebar_position: 20
|
|||||||
|
|
||||||
<!-- SPDX-License-Identifier: CC-BY-4.0 -->
|
<!-- SPDX-License-Identifier: CC-BY-4.0 -->
|
||||||
|
|
||||||
|
import { react } from 'react';
|
||||||
|
import CodeBlock from '@theme/CodeBlock';
|
||||||
|
import { useCurrentVersion } from '@site/src/hooks/versions';
|
||||||
|
|
||||||
|
export function InstallationSnippet() {
|
||||||
|
const latest = useCurrentVersion('latestReleased');
|
||||||
|
return(
|
||||||
|
<CodeBlock language="sh" >
|
||||||
|
{`kubectl apply -f \\
|
||||||
|
https://github.com/cloudnative-pg/plugin-barman-cloud/releases/download/v${latest}/manifest.yaml`}
|
||||||
|
</CodeBlock>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
:::important
|
:::important
|
||||||
1. The plugin **must** be installed in the same namespace as the CloudNativePG
|
1. The plugin **must** be installed in the same namespace as the CloudNativePG
|
||||||
operator (typically `cnpg-system`).
|
operator (typically `cnpg-system`).
|
||||||
@ -59,14 +73,7 @@ Both checks are required before proceeding with the installation.
|
|||||||
Install the plugin using `kubectl` by applying the manifest for the latest
|
Install the plugin using `kubectl` by applying the manifest for the latest
|
||||||
release:
|
release:
|
||||||
|
|
||||||
<!-- x-release-please-start-version -->
|
<InstallationSnippet />
|
||||||
|
|
||||||
```sh
|
|
||||||
kubectl apply -f \
|
|
||||||
https://github.com/cloudnative-pg/plugin-barman-cloud/releases/download/v0.4.0/manifest.yaml
|
|
||||||
```
|
|
||||||
|
|
||||||
<!-- x-release-please-end -->
|
|
||||||
|
|
||||||
Example output:
|
Example output:
|
||||||
|
|
||||||
@ -114,4 +121,3 @@ following command:
|
|||||||
kubectl apply -f \
|
kubectl apply -f \
|
||||||
https://raw.githubusercontent.com/cloudnative-pg/plugin-barman-cloud/refs/heads/main/manifest.yaml
|
https://raw.githubusercontent.com/cloudnative-pg/plugin-barman-cloud/refs/heads/main/manifest.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -13,7 +13,7 @@ If you're currently relying on the built-in Barman Cloud integration, you can
|
|||||||
migrate seamlessly to the new **plugin-based architecture** using the Barman
|
migrate seamlessly to the new **plugin-based architecture** using the Barman
|
||||||
Cloud Plugin, with **no downtime**. Follow these steps:
|
Cloud Plugin, with **no downtime**. Follow these steps:
|
||||||
|
|
||||||
- [Install the Barman Cloud Plugin](installation.md)
|
- [Install the Barman Cloud Plugin](installation.mdx)
|
||||||
- Create an `ObjectStore` resource by translating the contents of the
|
- Create an `ObjectStore` resource by translating the contents of the
|
||||||
`.spec.backup.barmanObjectStore` section from your existing `Cluster`
|
`.spec.backup.barmanObjectStore` section from your existing `Cluster`
|
||||||
definition
|
definition
|
||||||
|
|||||||
@ -6,7 +6,7 @@ sidebar_position: 30
|
|||||||
|
|
||||||
<!-- SPDX-License-Identifier: CC-BY-4.0 -->
|
<!-- SPDX-License-Identifier: CC-BY-4.0 -->
|
||||||
|
|
||||||
After [installing the plugin](installation.md) in the same namespace as the
|
After [installing the plugin](installation.mdx) in the same namespace as the
|
||||||
CloudNativePG operator, enabling your PostgreSQL cluster to use the Barman
|
CloudNativePG operator, enabling your PostgreSQL cluster to use the Barman
|
||||||
Cloud Plugin involves just a few steps:
|
Cloud Plugin involves just a few steps:
|
||||||
|
|
||||||
|
|||||||
27
web/src/hooks/versions.ts
Normal file
27
web/src/hooks/versions.ts
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import { useActiveVersion, useLatestVersion, useVersions } from '@docusaurus/plugin-content-docs/client';
|
||||||
|
|
||||||
|
|
||||||
|
export function useCurrentVersion(fallback: 'latest' | 'latestReleased' = 'latest') {
|
||||||
|
const version = useActiveVersion('default');
|
||||||
|
if (fallback === 'latestReleased') {
|
||||||
|
return useLatestReleasedVersion();
|
||||||
|
}
|
||||||
|
if (fallback === 'latest') {
|
||||||
|
return version?.name ?? useLatestVersion('default');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export function useLatestReleasedVersion() {
|
||||||
|
const versions = useVersions('default'); // returns all versions, including "current"
|
||||||
|
|
||||||
|
// Filter out "current" to only consider versioned docs
|
||||||
|
const versioned = versions.filter(v => v.name !== 'current');
|
||||||
|
|
||||||
|
// Assuming the latest is the first in the list after sorting by semantic version
|
||||||
|
const latestVersion = versioned.length > 0
|
||||||
|
? versioned.sort((a, b) => (b.name.localeCompare(a.name, undefined, {numeric: true, sensitivity: 'base'})))[0]
|
||||||
|
: null;
|
||||||
|
|
||||||
|
return latestVersion.name
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user