mirror of
https://github.com/zap-proto/zap-proto.github.io.git
synced 2026-11-21 11:24:10 +00:00
36 lines
1.6 KiB
JavaScript
36 lines
1.6 KiB
JavaScript
// Go vanity imports: every ZAP Go module resolves as zap-proto.io/<repo>
|
|
// from git.hanzo.ai/zap-proto/<repo>. `go get` asks for <path>?go-get=1 and
|
|
// reads the go-import / go-source tags. This writes one page per repo into
|
|
// vanity/, which is committed: the edge redirects any ?go-get=1 request on
|
|
// zap-proto.io/<repo>[/...] to vanity/<repo>.html in this repo (universe
|
|
// infra/sites/sites.yaml, middleware zap-proto-vanity). Run it after changing
|
|
// the repo list, and add the repo to that middleware's regex.
|
|
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
import { join } from 'node:path';
|
|
|
|
const HOST = 'zap-proto.io';
|
|
const FORGE = 'https://git.hanzo.ai/zap-proto';
|
|
|
|
const repos = ['go', 'fiber', 'http', 'mcp', 'md', 'zip', 'zap2pb', 'pb2zap', 'rns', 'telemetry', 'bench'];
|
|
|
|
// Go matches the go-import prefix against the requested path, so it serves
|
|
// nested paths (zap-proto.io/fiber/v3, zap-proto.io/zip/contract) too.
|
|
const page = (repo) => {
|
|
const root = `${HOST}/${repo}`;
|
|
const url = `${FORGE}/${repo}`;
|
|
return `<!doctype html>
|
|
<meta charset="utf-8">
|
|
<title>${HOST}/${repo}</title>
|
|
<meta name="go-import" content="${root} git ${url}">
|
|
<meta name="go-source" content="${root} ${url} ${url}/src/branch/main{/dir} ${url}/src/branch/main{/dir}/{file}#L{line}">
|
|
<meta http-equiv="refresh" content="0; url=https://pkg.go.dev/${HOST}/${repo}">
|
|
<a href="https://pkg.go.dev/${HOST}/${repo}">${HOST}/${repo}</a>
|
|
`;
|
|
};
|
|
|
|
const out = new URL('../vanity/', import.meta.url).pathname;
|
|
mkdirSync(out, { recursive: true });
|
|
for (const repo of repos) {
|
|
writeFileSync(join(out, `${repo}.html`), page(repo));
|
|
}
|