Files
sweet/example/pages/x/[module].tsx
T
Luca Casonato 8e83a032d9 feat: --config is not needed anymore (#48)
This commit removes the need for users to specify a --config file. TS
libs are now configured via `/// <reference>` directives, and the JSX
transform is specified via the `/** @jsx h */` pragma.

The future is configless!
2021-08-08 11:11:34 +02:00

41 lines
950 B
TypeScript

/** @jsx h */
import { h, PageConfig, PageProps, useData } from "../../deps.ts";
export default function ModuleInfoPage({ params }: PageProps) {
const module = params.module;
if (module.includes("/")) {
return <div>Invalid module name.</div>;
}
const url = `https://cdn.deno.land/${params.module}/meta/versions.json`;
const info = useData(url, fetcher);
if (info === null) {
return <div>No module found with name `{params.module}`.</div>;
}
const { latest, versions } = info;
return (
<p>
The module `{params.module}` has {versions.length} versions, with {latest}
{" "}
being the most recent.
</p>
);
}
interface ModuleInfo {
latest: string;
versions: string[];
}
async function fetcher(url: string): Promise<ModuleInfo | null> {
const resp = await fetch(url);
if (resp.status === 200) return resp.json();
return null;
}
export const config: PageConfig = { runtimeJS: false };