feat: read entries, registry data and READMEs in one loader

renderMarkdown only exists inside a content loader, and the README
should render through the site's own pipeline. One loader also means
the home and every plugin page share a single registry read per build.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
chrnx committed 2026-09-24 09:54:51 -05:00
1 parent d61b577a48
commit 84dae62864
6 files changed
+113 -46

No files matched your search

+25 -15
View File
@@ -1,5 +1,6 @@
import { defineCollection, z } from 'astro:content';
import { glob } from 'astro/loaders';
import { pluginsLoader } from '../scripts/loader.mjs';
// Naming, from spec 5.2. Enforced here so a wrongly-named submission is rejected by the build
// rather than by a reviewer's memory.
@@ -8,21 +9,30 @@ import { glob } from 'astro/loaders';
const NPM_NAME = /^(@green-tea\/[a-z0-9-]+|green-tea-[a-z0-9-]+|@[a-z0-9-]+\/green-tea-[a-z0-9-]+)$/;
const JSR_NAME = /^@[a-z0-9-]+\/(green-tea-)?[a-z0-9-]+$/;
// `npm` and `jsr` rather than one `name`: a third party's package has a different name on each
// registry. No `version` and no `runtimes` — both come from the registry, so an entry cannot go
// stale or claim a runtime the package never declared.
const FIELDS = z.object({
npm: z.string().regex(NPM_NAME, 'npm name must be @green-tea/<x>, green-tea-<x> or @scope/green-tea-<x>').optional(),
jsr: z.string().regex(JSR_NAME, 'JSR name must be @scope/<x>').optional(),
repo: z.string().url(),
description: z.string().min(20).max(200),
});
const ENTRY = FIELDS.refine((entry) => entry.npm ?? entry.jsr, {
message: 'an entry needs at least one of npm / jsr — otherwise there is nothing to install',
});
const plugins = defineCollection({
loader: glob({ pattern: '**/[^_]*.yaml', base: './src/content/plugins' }),
schema: z
.object({
// `npm` and `jsr` rather than one `name`: a third party's package has a different name on
// each registry. No `version` and no `runtimes` — both come from the registry, so an entry
// cannot go stale or claim a runtime the package never declared.
npm: z.string().regex(NPM_NAME, 'npm name must be @green-tea/<x>, green-tea-<x> or @scope/green-tea-<x>').optional(),
jsr: z.string().regex(JSR_NAME, 'JSR name must be @scope/<x>').optional(),
repo: z.string().url(),
description: z.string().min(20).max(200),
})
.refine((entry) => entry.npm ?? entry.jsr, {
message: 'an entry needs at least one of npm / jsr — otherwise there is nothing to install',
}),
loader: pluginsLoader(ENTRY),
// What the loader stores: the entry plus what the registry said.
schema: FIELDS.extend({
pkg: z.string(),
registry: z.enum(['jsr', 'npm']),
version: z.string(),
versions: z.array(z.string()),
runtimes: z.array(z.string()),
}),
});
export const collections = { plugins };
+16 -27
View File
@@ -1,37 +1,26 @@
---
import { getCollection } from 'astro:content';
import { readEntry } from '../../scripts/registry.mjs';
import Header from '../components/Header.astro';
import Footer from '../components/Footer.astro';
import PluginCard from '../components/PluginCard.astro';
import '../styles/global.css';
// Read at build time, never at request time — this site is static files on cPanel. Under CI a
// registry that does not answer fails the build; off CI that entry is left out. See
// scripts/registry.mjs.
const entries = await getCollection('plugins');
const plugins = (
await Promise.all(
entries.map(async (entry) => {
const live = await readEntry(entry.data);
if (!live) return null;
return {
name: entry.data.jsr ?? entry.data.npm,
description: entry.data.description,
repo: entry.data.repo,
npm: entry.data.npm,
jsr: entry.data.jsr,
version: live.version,
runtimes: live.runtimes,
// An internal plugin could be listed on npm alone and still be ours, so check both fields.
internal: (entry.data.jsr ?? entry.data.npm ?? '').startsWith('@green-tea/'),
};
}),
)
).filter((plugin) => plugin !== null);
plugins.sort((a, b) => a.name.localeCompare(b.name));
// Read at build time by the collection's loader (scripts/loader.mjs) — this site is static files
// on cPanel. Under CI a registry that does not answer fails the build; off CI that entry is left out.
const plugins = (await getCollection('plugins'))
.map(({ id, data }) => ({
slug: id,
name: data.pkg,
description: data.description,
repo: data.repo,
npm: data.npm,
jsr: data.jsr,
version: data.version,
runtimes: data.runtimes,
// An internal plugin could be listed on npm alone and still be ours, so check both fields.
internal: (data.jsr ?? data.npm ?? '').startsWith('@green-tea/'),
}))
.sort((a, b) => a.name.localeCompare(b.name));
---
<html lang="en">