Update landing-hero-github-stars.tsx

This commit is contained in:
Stefan Pejcic
2025-02-18 19:30:06 +01:00
committed by GitHub
parent 298102d86c
commit 0fb2e0acc7

View File

@@ -9,13 +9,13 @@ export const LandingHeroGithubStars = () => {
// Function to fetch the latest version tag from Docker Hub
const fetchVersion = async () => {
try {
const response = await fetch('https://registry.hub.docker.com/v1/repositories/openpanel/openpanel/tags');
const response = await fetch('https://hub.docker.com/v2/repositories/openpanel/openpanel/tags');
const data = await response.json();
// Filter out 'latest' and sort the tags to find the highest version number
const versions = data
.map(tag => tag.name)
.filter(tag => /^\d+\.\d+\.\d+$/.test(tag)) // Only keep valid version tags
// Extract tags, filter out 'latest', sort, and get the latest numeric version
const tags = data.results.map(tag => tag.name);
const filteredTags = tags
.filter(tag => /^\d+\.\d+\.\d+$/.test(tag)) // Only valid version tags
.sort((a, b) => {
// Compare versions numerically
const [majorA, minorA, patchA] = a.split('.').map(Number);
@@ -25,10 +25,10 @@ export const LandingHeroGithubStars = () => {
if (minorA !== minorB) return minorB - minorA;
return patchB - patchA;
});
if (versions.length > 0) {
setVersion(versions[0]); // Set the latest version (highest number)
}
// Get the latest version from the sorted list
const latestVersion = filteredTags.length > 0 ? filteredTags[0] : '1.0.0'; // Default to '1.0.0' if no valid version found
setVersion(latestVersion); // Update the version state
} catch (error) {
console.error('Failed to fetch version:', error);
}
@@ -37,12 +37,6 @@ export const LandingHeroGithubStars = () => {
fetchVersion();
}, []); // After initial render
// Function to format version for URL
const formatVersionForURL = (version) => {
const parts = version.split('.');
return `${parts[0]}.${parts[1]}/#${parts[1]}${parts[2]}`;
};
return (
<a
href={`/docs/changelog/${version}`}