From b847040a6df7c041fdd941403ce6cf5d6c8377bf Mon Sep 17 00:00:00 2001 From: Alex Freska Date: Wed, 4 Oct 2023 12:30:41 -0400 Subject: [PATCH] fix: website download links --- .changeset/moody-eels-itch.md | 5 + .../components/CalloutCoreSoftware.tsx | 17 -- apps/website/components/CalloutHostd.tsx | 7 +- apps/website/components/CalloutRenterd.tsx | 7 +- apps/website/components/CalloutWalletd.tsx | 7 +- ...ownloadWidgetLarge.tsx => DownloadBar.tsx} | 11 +- apps/website/components/DownloadSelect.tsx | 45 +++++ apps/website/components/DownloadWidget.tsx | 40 ----- .../components/DownloadWidgetSelect.tsx | 76 --------- .../components/SoftwareSectionNextGen.tsx | 19 --- .../components/SoftwareSectionTestnet.tsx | 75 -------- apps/website/content/downloads.ts | 161 ++---------------- apps/website/pages/software/hostd.tsx | 8 +- apps/website/pages/software/renterd.tsx | 38 ++--- apps/website/pages/software/walletd.tsx | 8 +- libs/data-sources/src/lib/github.ts | 25 ++- 16 files changed, 117 insertions(+), 432 deletions(-) create mode 100644 .changeset/moody-eels-itch.md rename apps/website/components/{DownloadWidgetLarge.tsx => DownloadBar.tsx} (82%) create mode 100644 apps/website/components/DownloadSelect.tsx delete mode 100644 apps/website/components/DownloadWidget.tsx delete mode 100644 apps/website/components/DownloadWidgetSelect.tsx delete mode 100644 apps/website/components/SoftwareSectionNextGen.tsx delete mode 100644 apps/website/components/SoftwareSectionTestnet.tsx diff --git a/.changeset/moody-eels-itch.md b/.changeset/moody-eels-itch.md new file mode 100644 index 000000000..08e187aee --- /dev/null +++ b/.changeset/moody-eels-itch.md @@ -0,0 +1,5 @@ +--- +'website': minor +--- + +The download selectors now dynamically show all published GitHub assets. diff --git a/apps/website/components/CalloutCoreSoftware.tsx b/apps/website/components/CalloutCoreSoftware.tsx index 4065687a9..059babfc9 100644 --- a/apps/website/components/CalloutCoreSoftware.tsx +++ b/apps/website/components/CalloutCoreSoftware.tsx @@ -5,9 +5,7 @@ import { Link, Badge, } from '@siafoundation/design-system' -import { cx } from 'class-variance-authority' import Image from 'next/image' -import { DownloadWidget } from './DownloadWidget' type Props = { name: string @@ -15,7 +13,6 @@ type Props = { description: React.ReactNode href?: string daemon?: 'renterd' | 'hostd' | 'walletd' - version?: string newTab?: boolean image?: string background: string @@ -27,8 +24,6 @@ export function CalloutCoreSoftware({ status, description, href, - daemon, - version, image, background, children, @@ -75,18 +70,6 @@ export function CalloutCoreSoftware({ )} {children} - {version && daemon && ( -
- -
- )} ) } diff --git a/apps/website/components/CalloutHostd.tsx b/apps/website/components/CalloutHostd.tsx index 4d2e3f221..254f17e7d 100644 --- a/apps/website/components/CalloutHostd.tsx +++ b/apps/website/components/CalloutHostd.tsx @@ -2,11 +2,7 @@ import { routes } from '../config/routes' import { CalloutCoreSoftware } from './CalloutCoreSoftware' import { patterns, getAssetUrl } from '../content/assets' -type Props = { - version?: string -} - -export function CalloutHostd({ version }: Props) { +export function CalloutHostd() { return (
- {version ? ( + {release ? ( <> Downloads - + ) : null}
diff --git a/apps/website/components/DownloadSelect.tsx b/apps/website/components/DownloadSelect.tsx new file mode 100644 index 000000000..155511892 --- /dev/null +++ b/apps/website/components/DownloadSelect.tsx @@ -0,0 +1,45 @@ +import { + Select, + Option, + ControlGroup, + Button, + LinkButton, +} from '@siafoundation/design-system' +import { Download16 } from '@siafoundation/react-icons' +import { useState } from 'react' +import { getDownloadLinks } from '../content/downloads' +import { GitHubRelease } from '@siafoundation/data-sources' + +type Props = { + daemon: 'renterd' | 'hostd' | 'walletd' + release: GitHubRelease +} + +export function DownloadSelect({ daemon, release }: Props) { + const downloadLinks = getDownloadLinks(daemon, release) + + const [download, setDownload] = useState(downloadLinks[0]) + + return ( + + + + + + + + ) +} diff --git a/apps/website/components/DownloadWidget.tsx b/apps/website/components/DownloadWidget.tsx deleted file mode 100644 index 1032a867e..000000000 --- a/apps/website/components/DownloadWidget.tsx +++ /dev/null @@ -1,40 +0,0 @@ -import { webLinks, Link } from '@siafoundation/design-system' -import { LogoGithub16, Book20 } from '@siafoundation/react-icons' -import { DownloadWidgetSelect } from './DownloadWidgetSelect' - -type Daemon = 'renterd' | 'hostd' | 'walletd' -type Props = { - daemon: Daemon - version: string -} - -export function DownloadWidget({ daemon, version }: Props) { - return ( -
- -
-
- - - - - - -
-
- ) -} diff --git a/apps/website/components/DownloadWidgetSelect.tsx b/apps/website/components/DownloadWidgetSelect.tsx deleted file mode 100644 index a52bb49ff..000000000 --- a/apps/website/components/DownloadWidgetSelect.tsx +++ /dev/null @@ -1,76 +0,0 @@ -import { - Select, - Option, - ControlGroup, - Button, - LinkButton, -} from '@siafoundation/design-system' -import { Download16 } from '@siafoundation/react-icons' -import { useState } from 'react' -import { - getHostdDownloadLinks, - getRenterdDownloadLinks, - getWalletDownloadLinks, -} from '../content/downloads' - -type Daemon = 'renterd' | 'hostd' | 'walletd' -type Props = { - daemon: Daemon - version: string -} - -export function DownloadWidgetSelect({ daemon, version }: Props) { - const downloadLinks = - daemon === 'renterd' - ? getRenterdDownloadLinks(version) - : daemon === 'hostd' - ? getHostdDownloadLinks(version) - : getWalletDownloadLinks(version) - - const [download, setDownload] = useState(downloadLinks[0]) - - const combined = downloadLinks.filter((i) => i.group === 'combined') - const mainnet = downloadLinks.filter((i) => i.group === 'mainnet') - const testnet = downloadLinks.filter((i) => i.group === 'testnet') - return ( - - - - - - - - ) -} diff --git a/apps/website/components/SoftwareSectionNextGen.tsx b/apps/website/components/SoftwareSectionNextGen.tsx deleted file mode 100644 index 14a83747f..000000000 --- a/apps/website/components/SoftwareSectionNextGen.tsx +++ /dev/null @@ -1,19 +0,0 @@ -import { CalloutRenterd } from './CalloutRenterd' -import { CalloutHostd } from './CalloutHostd' - -type Props = { - versionRenterd?: string - versionHostd?: string -} - -export function SoftwareSectionNextGen({ - versionRenterd, - versionHostd, -}: Props) { - return ( - <> - - - - ) -} diff --git a/apps/website/components/SoftwareSectionTestnet.tsx b/apps/website/components/SoftwareSectionTestnet.tsx deleted file mode 100644 index d6d0175af..000000000 --- a/apps/website/components/SoftwareSectionTestnet.tsx +++ /dev/null @@ -1,75 +0,0 @@ -/* eslint-disable react/no-unescaped-entities */ -import { webLinks } from '@siafoundation/design-system' -import { backgrounds } from '../content/assets' -import { SoftwareSection } from './SoftwareSection' - -type Versions = { - sia: { - latest: string - testnet: string - } - embarcadero: { - latest: string - } -} - -type Props = { - versions: Versions -} - -export function SoftwareSectionTestnet({ versions }: Props) { - return ( - <> - - Modified for running on the Zen Testnet. Built for technical users - comfortable with command line interfaces. - - } - sourceLink={webLinks.github.siad} - docsLink={webLinks.docs.siad} - version={versions.sia.testnet} - background={backgrounds.natePath} - links={[ - { - title: 'Windows AMD', - link: `${webLinks.website.index}/releases/siad/Sia-v${versions.sia.testnet}-Testnet-windows-amd64.zip`, - newTab: true, - }, - { - title: 'Windows ARM', - link: `${webLinks.website.index}/releases/siad/Sia-v${versions.sia.testnet}-Testnet-windows-arm64.zip`, - newTab: true, - }, - { - title: 'MacOS AMD', - link: `${webLinks.website.index}/releases/siad/Sia-v${versions.sia.testnet}-Testnet-darwin-amd64.zip`, - newTab: true, - }, - { - title: 'MacOS ARM', - link: `${webLinks.website.index}/releases/siad/Sia-v${versions.sia.testnet}-Testnet-darwin-arm64.zip`, - newTab: true, - }, - { - title: 'Linux AMD', - link: `${webLinks.website.index}/releases/siad/Sia-v${versions.sia.testnet}-Testnet-linux-amd64.zip`, - newTab: true, - }, - { - title: 'Linux ARM', - link: `${webLinks.website.index}/releases/siad/Sia-v${versions.sia.testnet}-Testnet-linux-arm64.zip`, - newTab: true, - }, - { - title: 'Docker', - link: 'https://github.com/SiaFoundation/siad/pkgs/container/siad', - newTab: true, - }, - ]} - /> - - ) -} diff --git a/apps/website/content/downloads.ts b/apps/website/content/downloads.ts index fcf63b263..c0d77ec43 100644 --- a/apps/website/content/downloads.ts +++ b/apps/website/content/downloads.ts @@ -1,150 +1,19 @@ -import { webLinks } from '@siafoundation/design-system' +import { GitHubRelease } from '@siafoundation/data-sources' -export function getRenterdDownloadLinks(version: string) { - if (!version) { +export function getDownloadLinks(daemon: string, release: GitHubRelease) { + if (!release) { return [] } - return [ - { - title: 'Windows AMD64', - link: `${webLinks.github.index}/renterd/releases/download/${version}/renterd_mainnet_windows_amd64.zip`, - group: 'mainnet', - }, - { - title: 'MacOS AMD64', - link: `${webLinks.github.index}/renterd/releases/download/${version}/renterd_mainnet_darwin_amd64.zip`, - group: 'mainnet', - }, - { - title: 'MacOS ARM64', - link: `${webLinks.github.index}/renterd/releases/download/${version}/renterd_mainnet_darwin_arm64.zip`, - group: 'mainnet', - }, - { - title: 'Linux AMD64', - link: `${webLinks.github.index}/renterd/releases/download/${version}/renterd_mainnet_linux_amd64.zip`, - group: 'mainnet', - }, - { - title: 'Linux ARM64', - link: `${webLinks.github.index}/renterd/releases/download/${version}/renterd_mainnet_linux_arm64.zip`, - group: 'mainnet', - }, - { - title: 'testnet - Windows AMD64', - link: `${webLinks.github.index}/renterd/releases/download/${version}/renterd_testnet_windows_amd64.zip`, - group: 'testnet', - }, - { - title: 'testnet - MacOS AMD64', - link: `${webLinks.github.index}/renterd/releases/download/${version}/renterd_testnet_darwin_amd64.zip`, - group: 'testnet', - }, - { - title: 'testnet - MacOS ARM64', - link: `${webLinks.github.index}/renterd/releases/download/${version}/renterd_testnet_darwin_arm64.zip`, - group: 'testnet', - }, - { - title: 'testnet - Linux AMD64', - link: `${webLinks.github.index}/renterd/releases/download/${version}/renterd_testnet_linux_amd64.zip`, - group: 'testnet', - }, - { - title: 'testnet - Linux ARM64', - link: `${webLinks.github.index}/renterd/releases/download/${version}/renterd_testnet_linux_arm64.zip`, - group: 'testnet', - }, - ] -} - -export function getHostdDownloadLinks(version: string) { - if (!version) { - return [] - } - return [ - { - title: 'Windows AMD64', - link: `${webLinks.github.index}/hostd/releases/download/${version}/hostd_windows_amd64.zip`, - group: 'mainnet', - }, - { - title: 'MacOS AMD64', - link: `${webLinks.github.index}/hostd/releases/download/${version}/hostd_darwin_amd64.zip`, - group: 'mainnet', - }, - { - title: 'MacOS ARM64', - link: `${webLinks.github.index}/hostd/releases/download/${version}/hostd_darwin_arm64.zip`, - group: 'mainnet', - }, - { - title: 'Linux AMD64', - link: `${webLinks.github.index}/hostd/releases/download/${version}/hostd_linux_amd64.zip`, - group: 'mainnet', - }, - { - title: 'Linux ARM64', - link: `${webLinks.github.index}/hostd/releases/download/${version}/hostd_linux_arm64.zip`, - group: 'mainnet', - }, - { - title: 'testnet - Windows AMD64', - link: `${webLinks.github.index}/hostd/releases/download/${version}/hostd_zen_windows_amd64.zip`, - group: 'testnet', - }, - { - title: 'testnet - MacOS AMD64', - link: `${webLinks.github.index}/hostd/releases/download/${version}/hostd_zen_darwin_amd64.zip`, - group: 'testnet', - }, - { - title: 'testnet - MacOS ARM64', - link: `${webLinks.github.index}/hostd/releases/download/${version}/hostd_zen_darwin_arm64.zip`, - group: 'testnet', - }, - { - title: 'testnet - Linux AMD64', - link: `${webLinks.github.index}/hostd/releases/download/${version}/hostd_zen_linux_amd64.zip`, - group: 'testnet', - }, - { - title: 'testnet - Linux ARM64', - link: `${webLinks.github.index}/hostd/releases/download/${version}/hostd_zen_linux_arm64.zip`, - group: 'testnet', - }, - ] -} - -export function getWalletDownloadLinks(version: string) { - if (!version) { - return [] - } - return [ - { - title: 'Windows AMD64', - link: `${webLinks.github.index}/walletd/releases/download/${version}/walletd_windows_amd64.zip`, - group: 'combined', - }, - { - title: 'MacOS AMD64', - link: `${webLinks.github.index}/walletd/releases/download/${version}/walletd_darwin_amd64.zip`, - group: 'combined', - }, - { - title: 'MacOS ARM64', - link: `${webLinks.github.index}/walletd/releases/download/${version}/walletd_darwin_arm64.zip`, - group: 'combined', - }, - { - title: 'Linux AMD64', - link: `${webLinks.github.index}/walletd/releases/download/${version}/walletd_linux_amd64.zip`, - group: 'combined', - }, - { - title: 'Linux ARM64', - link: `${webLinks.github.index}/walletd/releases/download/${version}/walletd_linux_arm64.zip`, - group: 'combined', - }, - ] + return release.assets.map((asset) => ({ + title: asset.name + .replace(daemon, '') + .replace('.zip', '') + .replace('windows', 'Windows') + .replace('darwin', 'MacOS') + .replace('linux', 'Linux') + .replace('amd64', 'AMD64') + .replace('arm64', 'ARM64') + .replace(/_/g, ' '), + link: asset.browser_download_url, + })) } diff --git a/apps/website/pages/software/hostd.tsx b/apps/website/pages/software/hostd.tsx index 906e769a7..d14a7e93b 100644 --- a/apps/website/pages/software/hostd.tsx +++ b/apps/website/pages/software/hostd.tsx @@ -20,7 +20,7 @@ import { useInView } from 'react-intersection-observer' import { cx } from 'class-variance-authority' import { getHostdLatestRelease } from '../../content/releases' import { CarouselHostd } from '../../components/CarouselHostd' -import { DownloadWidgetLarge } from '../../components/DownloadWidgetLarge' +import { DownloadBar } from '../../components/DownloadBar' import { backgrounds, previews } from '../../content/assets' import { SectionTransparent } from '../../components/SectionTransparent' @@ -41,8 +41,8 @@ const description = ( type Props = AsyncReturnType['props'] -export default function Hostd({ version, technical, tutorials }: Props) { - const downloadEl = +export default function Hostd({ release, technical, tutorials }: Props) { + const downloadEl = const { ref: appRef, inView: appInView } = useInView() return ( @@ -130,7 +130,7 @@ export async function getStaticProps() { technical, tutorials, services, - version: release?.tag_name || null, + release, fallback: { '/api/stats': stats, }, diff --git a/apps/website/pages/software/renterd.tsx b/apps/website/pages/software/renterd.tsx index 7cc787a15..fe47edb20 100644 --- a/apps/website/pages/software/renterd.tsx +++ b/apps/website/pages/software/renterd.tsx @@ -23,7 +23,7 @@ import { SectionTransparent } from '../../components/SectionTransparent' import { useInView } from 'react-intersection-observer' import { cx } from 'class-variance-authority' import { getRenterdLatestRelease } from '../../content/releases' -import { DownloadWidgetLarge } from '../../components/DownloadWidgetLarge' +import { DownloadBar } from '../../components/DownloadBar' import { backgrounds, previews } from '../../content/assets' const title = 'renterd' @@ -40,8 +40,8 @@ const description = ( type Props = AsyncReturnType['props'] -export default function Renterd({ version, technical, tutorials }: Props) { - const downloadEl = +export default function Renterd({ release, technical, tutorials }: Props) { + const downloadEl = const { ref: appRef, inView: appInView } = useInView() return ( @@ -172,21 +172,21 @@ export default function Renterd({ version, technical, tutorials }: Props) { command: [ 'curl -X POST http://localhost:9980/api/worker/rhp/form --json \\', "'" + - JSON.stringify( - { - hostKey: - 'ed25519:878d7d27e75691aa8f554ecb4c3e0c371a2a2a3d0901fe77727b6df6c6a11a6a', - hostIP: '127.0.0.1:59868', - hostCollateral: '191285052982572071957200', - renterFunds: '16666666666666666666666666', - renterAddress: - 'addr:861c1574947689c04df41a987b3a6a0a44eef27bb4511f3d64d1531913ca26288a12efc3f227', - endHeight: 126, - }, - null, - 2 - ) + - "'", + JSON.stringify( + { + hostKey: + 'ed25519:878d7d27e75691aa8f554ecb4c3e0c371a2a2a3d0901fe77727b6df6c6a11a6a', + hostIP: '127.0.0.1:59868', + hostCollateral: '191285052982572071957200', + renterFunds: '16666666666666666666666666', + renterAddress: + 'addr:861c1574947689c04df41a987b3a6a0a44eef27bb4511f3d64d1531913ca26288a12efc3f227', + endHeight: 126, + }, + null, + 2 + ) + + "'", ], result: ['{ file contract transaction }'], }, @@ -285,7 +285,7 @@ export async function getStaticProps() { technical, tutorials, services, - version: release?.tag_name, + release, fallback: { '/api/stats': stats, }, diff --git a/apps/website/pages/software/walletd.tsx b/apps/website/pages/software/walletd.tsx index 062515d12..86fdf1fd6 100644 --- a/apps/website/pages/software/walletd.tsx +++ b/apps/website/pages/software/walletd.tsx @@ -19,7 +19,7 @@ import { SectionGradient } from '../../components/SectionGradient' import { useInView } from 'react-intersection-observer' import { cx } from 'class-variance-authority' import { getWalletdLatestRelease } from '../../content/releases' -import { DownloadWidgetLarge } from '../../components/DownloadWidgetLarge' +import { DownloadBar } from '../../components/DownloadBar' import { backgrounds, previews } from '../../content/assets' import { SectionTransparent } from '../../components/SectionTransparent' import { CarouselWalletd } from '../../components/CarouselWalletd' @@ -43,8 +43,8 @@ const description = ( type Props = AsyncReturnType['props'] -export default function Walletd({ version, technical, tutorials }: Props) { - const downloadEl = +export default function Walletd({ release, technical, tutorials }: Props) { + const downloadEl = const { ref: appRef, inView: appInView } = useInView() return ( @@ -132,7 +132,7 @@ export async function getStaticProps() { technical, tutorials, services, - version: release?.tag_name || null, + release, fallback: { '/api/stats': stats, }, diff --git a/libs/data-sources/src/lib/github.ts b/libs/data-sources/src/lib/github.ts index 7dfce93c1..3f216069f 100644 --- a/libs/data-sources/src/lib/github.ts +++ b/libs/data-sources/src/lib/github.ts @@ -118,15 +118,6 @@ async function getReleaseCount() { return historic.data.length + current.data.length } -// NOTE: Currently not in use, copied from previous website code for reference. -// function getUIReleases() { -// // TODO: Needs to be updated, historic count from a Gitlab API? -// return axios.get( -// 'https://api.github.com/repos/NebulousLabs/Sia-UI/releases?per_page=100' -// ) -// // TODO: Add next gen UI repo -// } - type GitHub = { commits: number contributors: number @@ -168,9 +159,25 @@ export async function getGitHub(): AsyncDataSourceResponse { } } +export type GitHubReleaseAsset = { + url: string + id: number + node_id: string + name: string + label?: string + content_type: string + state: string + size: number + download_count: number + created_at: string + updated_at: string + browser_download_url: string +} + export type GitHubRelease = { name: string tag_name: string + assets: GitHubReleaseAsset[] } export async function getGitHubRenterdLatestRelease(): Promise {