feat: plugin pages, ESM-only npm, and a home that sells the listing #2
No files matched your search
@@ -1,13 +1,8 @@
|
||||
---
|
||||
import { RUNTIMES } from '../../scripts/registry.mjs';
|
||||
// Brand marks from simple-icons (CC0), vendored rather than pulled at build time. `?raw` inlines
|
||||
// them so each is one path in the HTML instead of four more requests.
|
||||
import node from '../icons/nodedotjs.svg?raw';
|
||||
import deno from '../icons/deno.svg?raw';
|
||||
import bun from '../icons/bun.svg?raw';
|
||||
import workerd from '../icons/cloudflareworkers.svg?raw';
|
||||
import Runtimes from './Runtimes.astro';
|
||||
|
||||
interface Props {
|
||||
slug: string;
|
||||
name: string;
|
||||
description: string;
|
||||
repo: string;
|
||||
@@ -18,52 +13,14 @@ interface Props {
|
||||
internal: boolean;
|
||||
}
|
||||
|
||||
const { name, description, repo, version, npm, jsr, runtimes, internal } = Astro.props;
|
||||
|
||||
const ICONS: Record<string, string> = { node, deno, bun, workerd };
|
||||
const LABELS: Record<string, string> = {
|
||||
node: 'Node.js',
|
||||
deno: 'Deno',
|
||||
bun: 'Bun',
|
||||
workerd: 'workerd (Cloudflare Workers)',
|
||||
};
|
||||
|
||||
// All four are always shown. Colour means the package declares it runs there; dim grey means it
|
||||
// declared otherwise, or said nothing — the tooltip is what separates those two, because at a
|
||||
// glance they are the same fact: you cannot use it there.
|
||||
const runs = (runtime: string) => runtimes.includes(runtime);
|
||||
const tooltip = (runtime: string) => {
|
||||
if (runs(runtime)) return `Runs on ${LABELS[runtime]}`;
|
||||
|
||||
return internal
|
||||
? `Does not run on ${LABELS[runtime]} — see the README for why`
|
||||
: `${LABELS[runtime]} not declared by this package`;
|
||||
};
|
||||
const { slug, name, description, repo, version, npm, jsr, runtimes, internal } = Astro.props;
|
||||
---
|
||||
|
||||
<article class="card">
|
||||
<span class="version">{version}</span>
|
||||
<h2>{name}</h2>
|
||||
<h2><a class="card__link" href={`/plugins/${slug}/`}>{name}</a></h2>
|
||||
|
||||
<ul class="runtimes">
|
||||
{
|
||||
RUNTIMES.map((runtime) => (
|
||||
// `data-tip` rather than `title`: the native tooltip waits about a second, cannot be
|
||||
// styled, and — the reason it did not work at all here — loses to a `<title>` inside the
|
||||
// SVG. The marks now carry no `<title>`, and the label lives on this element for both the
|
||||
// tooltip and the screen reader. `tabindex` so it is reachable without a mouse.
|
||||
<li
|
||||
class={runs(runtime) ? 'yes' : 'no'}
|
||||
data-tip={tooltip(runtime)}
|
||||
role="img"
|
||||
aria-label={tooltip(runtime)}
|
||||
tabindex="0"
|
||||
>
|
||||
<Fragment set:html={ICONS[runtime]} />
|
||||
</li>
|
||||
))
|
||||
}
|
||||
</ul>
|
||||
<Runtimes runtimes={runtimes} internal={internal} />
|
||||
|
||||
<p>{description}</p>
|
||||
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
---
|
||||
import { RUNTIMES } from '../../scripts/registry.mjs';
|
||||
// Brand marks from simple-icons (CC0), vendored rather than pulled at build time. `?raw` inlines
|
||||
// them so each is one path in the HTML instead of four more requests.
|
||||
import node from '../icons/nodedotjs.svg?raw';
|
||||
import deno from '../icons/deno.svg?raw';
|
||||
import bun from '../icons/bun.svg?raw';
|
||||
import workerd from '../icons/cloudflareworkers.svg?raw';
|
||||
|
||||
interface Props {
|
||||
runtimes: string[];
|
||||
internal: boolean;
|
||||
}
|
||||
|
||||
const { runtimes, internal } = Astro.props;
|
||||
|
||||
const ICONS: Record<string, string> = { node, deno, bun, workerd };
|
||||
const LABELS: Record<string, string> = {
|
||||
node: 'Node.js',
|
||||
deno: 'Deno',
|
||||
bun: 'Bun',
|
||||
workerd: 'workerd (Cloudflare Workers)',
|
||||
};
|
||||
|
||||
// All four are always shown. Colour means the package declares it runs there; dim grey means it
|
||||
// declared otherwise, or said nothing — the tooltip is what separates those two, because at a
|
||||
// glance they are the same fact: you cannot use it there.
|
||||
const runs = (runtime: string) => runtimes.includes(runtime);
|
||||
const tooltip = (runtime: string) => {
|
||||
if (runs(runtime)) return `Runs on ${LABELS[runtime]}`;
|
||||
|
||||
return internal
|
||||
? `Does not run on ${LABELS[runtime]} — see the README for why`
|
||||
: `${LABELS[runtime]} not declared by this package`;
|
||||
};
|
||||
---
|
||||
|
||||
<ul class="runtimes">
|
||||
{
|
||||
RUNTIMES.map((runtime) => (
|
||||
// `data-tip` rather than `title`: the native tooltip waits about a second, cannot be
|
||||
// styled, and — the reason it did not work at all here — loses to a `<title>` inside the
|
||||
// SVG. The marks now carry no `<title>`, and the label lives on this element for both the
|
||||
// tooltip and the screen reader. `tabindex` so it is reachable without a mouse.
|
||||
<li
|
||||
class={runs(runtime) ? 'yes' : 'no'}
|
||||
data-tip={tooltip(runtime)}
|
||||
role="img"
|
||||
aria-label={tooltip(runtime)}
|
||||
tabindex="0"
|
||||
>
|
||||
<Fragment set:html={ICONS[runtime]} />
|
||||
</li>
|
||||
))
|
||||
}
|
||||
</ul>
|
||||
@@ -0,0 +1,94 @@
|
||||
---
|
||||
import { getCollection, render } from 'astro:content';
|
||||
import Header from '../components/Header.astro';
|
||||
import Footer from '../components/Footer.astro';
|
||||
import Runtimes from '../components/Runtimes.astro';
|
||||
import '../styles/global.css';
|
||||
|
||||
export async function getStaticPaths() {
|
||||
return (await getCollection('plugins')).map((entry) => ({ params: { slug: entry.id }, props: { entry } }));
|
||||
}
|
||||
|
||||
const { entry } = Astro.props;
|
||||
const { data } = entry;
|
||||
const { Content } = await render(entry);
|
||||
const hasReadme = Boolean(entry.rendered?.html);
|
||||
const internal = data.pkg.startsWith('@green-tea/');
|
||||
const install = data.registry === 'jsr' ? `npx jsr add ${data.pkg}` : `npm i ${data.pkg}`;
|
||||
const versionUrl = (v: string) =>
|
||||
data.registry === 'jsr' ? `https://jsr.io/${data.pkg}@${v}` : `https://www.npmjs.com/package/${data.pkg}/v/${v}`;
|
||||
const registryUrl = data.registry === 'jsr' ? `https://jsr.io/${data.pkg}` : `https://www.npmjs.com/package/${data.pkg}`;
|
||||
---
|
||||
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<link rel="icon" href="/plugins/favicon.svg" type="image/svg+xml" />
|
||||
<title>{data.pkg} · Green Tea. plugins</title>
|
||||
<meta name="description" content={data.description} />
|
||||
<link rel="canonical" href={`https://green-tea.expressive-tea.io/plugins/${entry.id}/`} />
|
||||
</head>
|
||||
<body>
|
||||
<Header />
|
||||
|
||||
<main class="wrap plugin">
|
||||
<header class="plugin__head">
|
||||
<p class="plugin__back"><a href="/plugins/">← All plugins</a></p>
|
||||
<h1>{data.pkg} <span class="version">{data.version}</span></h1>
|
||||
<p>{data.description}</p>
|
||||
<Runtimes runtimes={data.runtimes} internal={internal} />
|
||||
|
||||
<div class="install">
|
||||
<code>{install}</code>
|
||||
<button type="button" class="button" data-copy={install} aria-live="polite">Copy</button>
|
||||
</div>
|
||||
<p class="requires">Needs <code>@green-tea/core@26.9.0-beta.2</code> or newer.</p>
|
||||
|
||||
<p class="links">
|
||||
<a href={registryUrl}>{data.registry === 'jsr' ? 'JSR' : 'npm'}</a>
|
||||
<a href={data.repo}>source</a>
|
||||
</p>
|
||||
</header>
|
||||
|
||||
<div class="plugin__body">
|
||||
<article class="readme">
|
||||
{
|
||||
hasReadme ? (
|
||||
<Content />
|
||||
) : (
|
||||
<p>
|
||||
This package publishes no README. <a href={registryUrl}>See it on the registry.</a>
|
||||
</p>
|
||||
)
|
||||
}
|
||||
</article>
|
||||
|
||||
<aside class="versions" aria-label="Versions">
|
||||
<h2>Versions</h2>
|
||||
<ol>
|
||||
{
|
||||
data.versions.map((v) => (
|
||||
<li>
|
||||
<a href={versionUrl(v)}>{v}</a>
|
||||
</li>
|
||||
))
|
||||
}
|
||||
</ol>
|
||||
</aside>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<Footer />
|
||||
|
||||
<script>
|
||||
for (const button of document.querySelectorAll<HTMLButtonElement>('[data-copy]')) {
|
||||
button.addEventListener('click', async () => {
|
||||
await navigator.clipboard.writeText(button.dataset.copy ?? '');
|
||||
button.textContent = 'Copied';
|
||||
setTimeout(() => (button.textContent = 'Copy'), 1500);
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -386,3 +386,36 @@ main {
|
||||
color: var(--matcha);
|
||||
}
|
||||
|
||||
|
||||
/* The whole card opens the plugin's page; the registry links and runtime marks stay clickable on
|
||||
top of it. A stretched link rather than a wrapping <a>, because links cannot nest. */
|
||||
.card__link { color: inherit; text-decoration: none; }
|
||||
.card__link::after { content: ''; position: absolute; inset: 0; border-radius: inherit; }
|
||||
.card .links, .card .why, .card .runtimes { position: relative; z-index: 1; }
|
||||
.card:has(.card__link:focus-visible) { outline: 2px solid var(--matcha); outline-offset: 2px; }
|
||||
.card:has(.card__link:hover) { border-color: var(--matcha-deep); }
|
||||
|
||||
/* Plugin page. */
|
||||
.plugin__head { padding-block: 2rem 1.5rem; border-bottom: 1px solid var(--line); margin-bottom: 2rem; }
|
||||
.plugin__back a { color: var(--dim); text-decoration: none; }
|
||||
.plugin__back a:hover { color: var(--matcha); }
|
||||
.plugin__head h1 { display: flex; align-items: baseline; gap: 0.75rem; flex-wrap: wrap; font-family: var(--font-mono); word-break: break-word; }
|
||||
.plugin__head .version { position: static; }
|
||||
.install { display: flex; gap: 0.5rem; align-items: center; margin-block: 1rem 0.25rem; flex-wrap: wrap; }
|
||||
.install code { padding: 0.5rem 0.75rem; border-radius: 6px; overflow-x: auto; background: var(--panel); border: 1px solid var(--line); font-family: var(--font-mono); }
|
||||
.plugin__body { display: grid; grid-template-columns: minmax(0, 1fr) 12rem; gap: 2rem; padding-bottom: 3rem; }
|
||||
.readme { min-width: 0; line-height: 1.6; }
|
||||
.readme img { max-width: 100%; height: auto; }
|
||||
.readme pre { overflow-x: auto; padding: 1rem; border-radius: 6px; border: 1px solid var(--line); }
|
||||
.readme a { color: var(--matcha); }
|
||||
.readme table { border-collapse: collapse; display: block; overflow-x: auto; }
|
||||
.readme th, .readme td { border: 1px solid var(--line); padding: 0.4rem 0.6rem; }
|
||||
.versions h2 { font-size: 0.9rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--dim); }
|
||||
.versions ol { list-style: none; padding: 0; margin: 0; font-family: var(--font-mono); font-size: 0.9rem; }
|
||||
.versions li { padding-block: 0.2rem; }
|
||||
.versions a { color: var(--ink); }
|
||||
.versions a:hover { color: var(--matcha); }
|
||||
@media (max-width: 48rem) {
|
||||
.plugin__body { grid-template-columns: 1fr; }
|
||||
.versions { order: -1; }
|
||||
}
|
||||
Reference in new issue
Block a user