Skip to content

Commit

Permalink
feat: get latest version from GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
yult123 committed Jan 30, 2024
1 parent 0606fd6 commit 7ac91d2
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 48 deletions.
8 changes: 4 additions & 4 deletions website/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
const lightCodeTheme = require('prism-react-renderer/themes/github');
const darkCodeTheme = require('prism-react-renderer/themes/dracula');

const isDev = process.env.NODE_ENV?.toLocaleLowerCase() !== "production"
const isDev = process.env.NODE_ENV?.toLocaleLowerCase() !== 'production';

/** @type {import('@docusaurus/types').Config} */
const config = {
Expand Down Expand Up @@ -51,7 +51,7 @@ const config = {
// Please change this to your repo.
// Remove this to remove the "edit this page" links.
editUrl:
'https://github.com/kubenetworks/kubenetworks.github.io/tree/master/website/blog',
'https://github.com/kubenetworks/kubenetworks.github.io/tree/master/website/blog',
},
theme: {
customCss: require.resolve('./src/css/custom.css'),
Expand Down Expand Up @@ -121,8 +121,8 @@ const config = {
title: 'Latest Release',
items: [
{
label: 'v2.2.1',
href: 'https://github.com/kubenetworks/kubevpn/releases/tag/v2.2.1',
label: 'latest',
href: 'https://github.com/kubenetworks/kubevpn/releases/latest',
},
{
label: 'Archives',
Expand Down
2 changes: 1 addition & 1 deletion website/i18n/en/docusaurus-theme-classic/footer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"description": "The label of footer link with label=KubeVPN Docs linking to https://github.com/kubenetworks/kubenetworks.github.io"
},
"link.item.label.v2.2.1": {
"message": "v2.2.1",
"message": "latest",
"description": "The label of footer link with label=v2.2.1 linking to https://github.com/kubenetworks/kubevpn/releases/tag/v2.2.1"
},
"link.item.label.Archives": {
Expand Down
2 changes: 1 addition & 1 deletion website/i18n/zh/docusaurus-theme-classic/footer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"description": "The label of footer link with label=KubeVPN Docs linking to https://github.com/kubenetworks/kubenetworks.github.io"
},
"link.item.label.v2.2.1": {
"message": "v2.2.1",
"message": "latest",
"description": "The label of footer link with label=v2.2.1 linking to https://github.com/kubenetworks/kubevpn/releases/tag/v2.2.1"
},
"link.item.label.Archives": {
Expand Down
101 changes: 59 additions & 42 deletions website/src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,54 +1,71 @@
import React from 'react';
import clsx from 'clsx';
import Link from '@docusaurus/Link';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import Layout from '@theme/Layout';
import HomepageFeatures from '@site/src/components/HomepageFeatures';
import Layout from '@theme/Layout';
import clsx from 'clsx';
import React, { useEffect, useState } from 'react';

import Translate, {translate} from '@docusaurus/Translate';
import Translate, { translate } from '@docusaurus/Translate';

import styles from './index.module.css';
import config from '@generated/docusaurus.config';
import styles from './index.module.css';

function HomepageHeader() {
const {siteConfig} = useDocusaurusContext();
return (
<header className={clsx('hero hero--primary', styles.heroBanner)}>
<div className="container">
<img style={{width: 300, height: 100, objectFit: "cover"}}
src={require('@site/static/img/logo.jpeg').default}/>
<p className="hero__subtitle">
<Translate>Cloud Native Dev Environment</Translate>
</p>
<div className={styles.buttons}>
<Link
className="button button--secondary button--lg"
to="/docs/quickstart">
<Translate>QuickStart</Translate>
</Link>
<Link
className={styles.homepageVersion}
to="https://github.com/kubenetworks/kubevpn/releases/tag/v2.2.1">
v2.2.1
</Link>
</div>
</div>
</header>
);
const { siteConfig } = useDocusaurusContext();

const [ver, setVer] = useState('latest');

useEffect(() => {
fetch(
'https://raw.githubusercontent.com/kubenetworks/kubevpn/master/plugins/stable.txt',
)
.then(res => res.text())
.then(ver => setVer(ver));
}, []);

return (
<header className={clsx('hero hero--primary', styles.heroBanner)}>
<div className="container">
<img
style={{ width: 300, height: 100, objectFit: 'cover' }}
src={require('@site/static/img/logo.jpeg').default}
/>
<p className="hero__subtitle">
<Translate>Cloud Native Dev Environment</Translate>
</p>
<div className={styles.buttons}>
<Link
className="button button--secondary button--lg"
to="/docs/quickstart"
>
<Translate>QuickStart</Translate>
</Link>
<Link
className={styles.homepageVersion}
to="https://github.com/kubenetworks/kubevpn/releases/latest"
>
{ver}
</Link>
</div>
</div>
</header>
);
}

export default function Home(): React.JSX.Element {
const {siteConfig} = useDocusaurusContext();
return (
<Layout
title={translate({
message: "Homepage"
})}
description={config.tagline}>
<HomepageHeader/>
<main>
<HomepageFeatures/>
</main>
</Layout>
);
const { siteConfig } = useDocusaurusContext();

return (
<Layout
title={translate({
message: 'Homepage',
})}
description={config.tagline}
>
<HomepageHeader />
<main>
<HomepageFeatures />
</main>
</Layout>
);
}

0 comments on commit 7ac91d2

Please sign in to comment.