diff --git a/src/components/Asset.astro b/src/components/Asset.astro index 589817b..743875c 100644 --- a/src/components/Asset.astro +++ b/src/components/Asset.astro @@ -1,4 +1,6 @@ --- +import { formatBytes, formatNum } from '../utils'; + interface Asset { name: string; label: string; @@ -13,13 +15,6 @@ interface Props { } const { asset, include_downloads = true } = Astro.props; - -const formatNum = Intl.NumberFormat('en', { notation: 'compact' }).format; -function formatBytes(bytes: number): string { - const unit = Math.floor(Math.log10(bytes) / 3); - const adjusted = bytes / 10 ** (3 * unit); - return adjusted.toFixed(2) + ' ' + ['B', 'KB', 'MB', 'GB', 'TB'][unit]; -} --- diff --git a/src/components/Release.astro b/src/components/Release.astro index ccac626..0179a15 100644 --- a/src/components/Release.astro +++ b/src/components/Release.astro @@ -2,6 +2,7 @@ import { parse as parseMarkdown } from 'marked'; import type { Release } from '../repository'; import Asset from './Asset.astro'; +import { formatNum } from '../utils'; interface Props { release: Release; @@ -40,7 +41,7 @@ try { { release.assets?.length > 0 && (
-

Downloads

+

Downloads ({formatNum(release.assets.reduce((total, { download_count }) => total + download_count, 0))} total)

{release.assets?.map((asset: any) => ( diff --git a/src/pages/download.astro b/src/pages/download.astro index 8d737c7..78e2401 100644 --- a/src/pages/download.astro +++ b/src/pages/download.astro @@ -1,7 +1,8 @@ --- -import Main from '../layouts/Main.astro'; import Asset from '../components/Asset.astro'; -import { repo_url, repositoryAPIRequest, type Release } from '../repository'; +import Main from '../layouts/Main.astro'; +import { repositoryAPIRequest, type Release } from '../repository'; +import { formatNum } from '../utils'; let error: string | Error, release: Release; @@ -28,7 +29,7 @@ try { ) : (

-

Downloads

+

Downloads ({formatNum(release.assets.reduce((total, { download_count }) => total + download_count, 0))} total)

{release.assets?.map((asset: any) => ( diff --git a/src/pages/releases/index.astro b/src/pages/releases/index.astro index 6b1e872..2130e6e 100644 --- a/src/pages/releases/index.astro +++ b/src/pages/releases/index.astro @@ -14,12 +14,12 @@ try { } --- -

+
{ error ? (
- Failed to fetch changelog. See it  + Failed to fetch releases. See it  here diff --git a/src/utils.ts b/src/utils.ts index aa5e8d9..a683b13 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -42,3 +42,10 @@ export async function checkAdminAuth(astro: Readonly, minType?: Acc return account; } + +export const formatNum = Intl.NumberFormat('en', { notation: 'compact' }).format; +export function formatBytes(bytes: number): string { + const unit = Math.floor(Math.log10(bytes) / 3); + const adjusted = bytes / 10 ** (3 * unit); + return adjusted.toFixed(2) + ' ' + ['B', 'KB', 'MB', 'GB', 'TB'][unit]; +}