Skip to content

Commit 437d58c

Browse files
authored
fix: Show the latest version and its release date on the cards and drop the download count. (#4)
1 parent 9861088 commit 437d58c

5 files changed

Lines changed: 16 additions & 31 deletions

File tree

‎src/components/Home.astro‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
import { libraries as allLibraries } from '../content'
77
import { AREA_TEXT, AREAS, repositoryUrl } from '../content/catalog'
8-
import { MAIN_ID, SITE, TEXT } from '../content/site'
8+
import { MAIN_ID, releaseDate, SITE, TEXT } from '../content/site'
99
import BaseLayout from '../layouts/BaseLayout.astro'
1010
import Icon from './Icon.astro'
1111
import HeroCompose from './HeroCompose.astro'
@@ -103,9 +103,9 @@ const origin = Astro.site ?? Astro.url.origin
103103
<span class="tb-card__summary">{library.data.description}</span>
104104
<span class="tb-card__foot">
105105
<span class="tb-chip">{library.data.version}</span>
106-
{library.data.usedBy.length > 0 && (
107-
<span class="tb-chip">{TEXT.library.usedByCount(library.data.usedBy.length)}</span>
108-
)}
106+
<time class="tb-chip" datetime={library.data.released}>
107+
{releaseDate(library.data.released)}
108+
</time>
109109
</span>
110110
</a>
111111
</li>

‎src/components/LibraryPage.astro‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { render } from 'astro:content'
77
import type { Library } from '../content'
88
import { AREA_TEXT, packagistUrl, repositoryUrl } from '../content/catalog'
9-
import { MAIN_ID, TEXT } from '../content/site'
9+
import { MAIN_ID, releaseDate, TEXT } from '../content/site'
1010
import BaseLayout from '../layouts/BaseLayout.astro'
1111
import Icon from './Icon.astro'
1212
@@ -21,8 +21,7 @@ const packageName = `tiny-blocks/${data.name}`
2121
const install = `composer require ${packageName}`
2222
const origin = Astro.site ?? Astro.url.origin
2323
const url = new URL(`/${data.name}/`, origin).href
24-
const released = new Intl.DateTimeFormat('en', { dateStyle: 'medium', timeZone: 'UTC' }).format(new Date(data.released))
25-
const downloads = new Intl.NumberFormat('en').format(data.downloads.monthly)
24+
const released = releaseDate(data.released)
2625
/** Search engines show about 160 characters, so a short summary is completed with what the library is. */
2726
const completed = `${data.description} ${TEXT.library.pitch}`
2827
const description = completed.length <= 165 ? completed : data.description
@@ -91,7 +90,6 @@ const relations = [
9190
<li>{TEXT.library.version} <strong>{data.version}</strong>, {TEXT.library.released} {released}</li>
9291
<li>{TEXT.library.php} <strong>{data.php}</strong></li>
9392
<li>{TEXT.library.license} <strong>{data.license}</strong></li>
94-
<li>{TEXT.library.downloads} <strong>{downloads}</strong> {TEXT.library.perMonth}</li>
9593
<li>
9694
<a href={repositoryUrl(data.name)} target="_blank" rel="noopener noreferrer">
9795
{TEXT.library.source} <Icon name="external" size={12} />

‎src/content.config.ts‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { z } from 'astro/zod'
66
import { AREAS, CATALOG } from './content/catalog'
77
import { dependencyGraph } from './content/graph'
88
import { documentation } from './content/readme'
9-
import { composerFile, downloads, latestRelease, readme } from './content/sources'
9+
import { composerFile, latestRelease, readme } from './content/sources'
1010

1111
const libraries = defineCollection({
1212
loader: {
@@ -15,19 +15,18 @@ const libraries = defineCollection({
1515
const names = new Set(CATALOG.map((entry) => entry.name))
1616
const sources = await Promise.all(
1717
CATALOG.map(async (entry) => {
18-
const [text, composer, release, stats] = await Promise.all([
18+
const [text, composer, release] = await Promise.all([
1919
readme(entry.name),
2020
composerFile(entry.name),
2121
latestRelease(entry.name),
22-
downloads(entry.name),
2322
])
24-
return { entry, text, composer, release, stats }
23+
return { entry, text, composer, release }
2524
}),
2625
)
2726
const graph = dependencyGraph(new Map(sources.map((source) => [source.entry.name, source.composer])))
2827

2928
store.clear()
30-
for (const [index, { entry, text, composer, release, stats }] of sources.entries()) {
29+
for (const [index, { entry, text, composer, release }] of sources.entries()) {
3130
const node = graph[index]
3231
if (node === undefined) {
3332
throw new Error(`No node of the graph for ${entry.name}.`)
@@ -45,7 +44,6 @@ const libraries = defineCollection({
4544
license: [composer.license ?? 'MIT'].flat().join(', '),
4645
version: release.version,
4746
released: release.time,
48-
downloads: stats,
4947
dependsOn: node.dependsOn,
5048
usedBy: node.usedBy,
5149
testedWith: node.testedWith,
@@ -69,7 +67,6 @@ const libraries = defineCollection({
6967
license: z.string(),
7068
version: z.string(),
7169
released: z.string(),
72-
downloads: z.object({ total: z.number(), monthly: z.number() }),
7370
dependsOn: z.array(z.string()),
7471
usedBy: z.array(z.string()),
7572
testedWith: z.array(z.string()),

‎src/content/site.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ export const TEXT = {
5353
released: 'released',
5454
php: 'PHP',
5555
license: 'License',
56-
downloads: 'Downloads',
57-
perMonth: 'a month',
5856
source: 'Source',
5957
packagist: 'Packagist',
6058
dependsOn: 'Stands on',
@@ -67,7 +65,6 @@ export const TEXT = {
6765
headline: (title: string) => `${title} for PHP`,
6866
/** What closes the description of a library page when the summary of the library is short. */
6967
pitch: 'A small, framework-agnostic PHP library from Tiny Blocks.',
70-
usedByCount: (count: number) => (count === 1 ? 'used by 1 library' : `used by ${count} libraries`),
7168
},
7269
search: {
7370
title: 'Search the libraries',
@@ -82,3 +79,8 @@ export const TEXT = {
8279
},
8380
notFound: { title: 'Page not found', lede: 'This address does not exist or has moved.', back: 'Back to home' },
8481
} as const
82+
83+
/** The day a release was published, from its ISO 8601 instant, as the site shows it: Oct 24, 2026. */
84+
export function releaseDate(instant: string): string {
85+
return new Intl.DateTimeFormat('en', { dateStyle: 'medium', timeZone: 'UTC' }).format(new Date(instant))
86+
}

‎src/content/sources.ts‎

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* What the site reads about each library when it is built: the README and the `composer.json` from
3-
* its repository, and the latest release and the downloads from Packagist. A failed request fails the
3+
* its repository, and the latest release from Packagist. A failed request fails the
44
* build, so the site never publishes a library with half of its page missing.
55
*/
66
import { ORGANIZATION, rawUrl } from './catalog'
@@ -17,11 +17,6 @@ export interface Release {
1717
readonly time: string
1818
}
1919

20-
export interface Downloads {
21-
readonly total: number
22-
readonly monthly: number
23-
}
24-
2520
async function fetchOk(url: string): Promise<Response> {
2621
const response = await fetch(url)
2722
if (!response.ok) {
@@ -49,10 +44,3 @@ export async function latestRelease(name: string): Promise<Release> {
4944
}
5045
return { version: release.version, time: release.time }
5146
}
52-
53-
export async function downloads(name: string): Promise<Downloads> {
54-
const body = (await (await fetchOk(`https://packagist.org/packages/${ORGANIZATION}/${name}/stats.json`)).json()) as {
55-
downloads: Downloads
56-
}
57-
return { total: body.downloads.total, monthly: body.downloads.monthly }
58-
}

0 commit comments

Comments
 (0)