@grimoire-rs/indexer 0.3.3 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +137 -2
- package/dist/ci.d.ts +6 -1
- package/dist/ci.d.ts.map +1 -1
- package/dist/ci.js +32 -1
- package/dist/ci.js.map +1 -1
- package/dist/cli/build.d.ts.map +1 -1
- package/dist/cli/build.js +3 -1
- package/dist/cli/build.js.map +1 -1
- package/dist/cli/ci.d.ts.map +1 -1
- package/dist/cli/ci.js +5 -1
- package/dist/cli/ci.js.map +1 -1
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +17 -3
- package/dist/cli/init.js.map +1 -1
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +8 -0
- package/dist/cli/main.js.map +1 -1
- package/dist/cli/ratings.d.ts +3 -0
- package/dist/cli/ratings.d.ts.map +1 -0
- package/dist/cli/ratings.js +160 -0
- package/dist/cli/ratings.js.map +1 -0
- package/dist/config.d.ts +19 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +47 -1
- package/dist/config.js.map +1 -1
- package/dist/enrich/index.d.ts.map +1 -1
- package/dist/enrich/index.js +74 -1
- package/dist/enrich/index.js.map +1 -1
- package/dist/ratings/budget.d.ts +16 -0
- package/dist/ratings/budget.d.ts.map +1 -0
- package/dist/ratings/budget.js +7 -0
- package/dist/ratings/budget.js.map +1 -0
- package/dist/ratings/config.d.ts +56 -0
- package/dist/ratings/config.d.ts.map +1 -0
- package/dist/ratings/config.js +86 -0
- package/dist/ratings/config.js.map +1 -0
- package/dist/ratings/marker.d.ts +105 -0
- package/dist/ratings/marker.d.ts.map +1 -0
- package/dist/ratings/marker.js +141 -0
- package/dist/ratings/marker.js.map +1 -0
- package/dist/ratings/provider.d.ts +108 -0
- package/dist/ratings/provider.d.ts.map +1 -0
- package/dist/ratings/provider.js +202 -0
- package/dist/ratings/provider.js.map +1 -0
- package/dist/ratings/provider_github.d.ts +3 -0
- package/dist/ratings/provider_github.d.ts.map +1 -0
- package/dist/ratings/provider_github.js +134 -0
- package/dist/ratings/provider_github.js.map +1 -0
- package/dist/ratings/provider_gitlab.d.ts +3 -0
- package/dist/ratings/provider_gitlab.d.ts.map +1 -0
- package/dist/ratings/provider_gitlab.js +152 -0
- package/dist/ratings/provider_gitlab.js.map +1 -0
- package/dist/ratings/provider_memory.d.ts +28 -0
- package/dist/ratings/provider_memory.d.ts.map +1 -0
- package/dist/ratings/provider_memory.js +49 -0
- package/dist/ratings/provider_memory.js.map +1 -0
- package/dist/ratings/reconcile.d.ts +47 -0
- package/dist/ratings/reconcile.d.ts.map +1 -0
- package/dist/ratings/reconcile.js +133 -0
- package/dist/ratings/reconcile.js.map +1 -0
- package/dist/ratings/seed.d.ts +60 -0
- package/dist/ratings/seed.d.ts.map +1 -0
- package/dist/ratings/seed.js +132 -0
- package/dist/ratings/seed.js.map +1 -0
- package/dist/renderer/astro/components/Catalog.d.ts +2 -0
- package/dist/renderer/astro/components/Catalog.js +64 -15
- package/dist/renderer/astro/components/Catalog.tsx +104 -17
- package/dist/renderer/astro/layouts/Base.astro +7 -0
- package/dist/renderer/astro/lib/catalog.d.ts +25 -0
- package/dist/renderer/astro/lib/catalog.js +46 -0
- package/dist/renderer/astro/lib/catalog.ts +49 -0
- package/dist/renderer/astro/pages/p/[...slug].astro +146 -3
- package/dist/renderer/index.d.ts.map +1 -1
- package/dist/renderer/index.js +101 -2
- package/dist/renderer/index.js.map +1 -1
- package/dist/renderer/types.d.ts +41 -0
- package/dist/renderer/types.d.ts.map +1 -1
- package/dist/validate/adapters/http.d.ts +6 -1
- package/dist/validate/adapters/http.d.ts.map +1 -1
- package/dist/validate/adapters/http.js +5 -1
- package/dist/validate/adapters/http.js.map +1 -1
- package/package.json +1 -1
- package/templates/ci/github-pages.yml +11 -5
- package/templates/ci/github-ratings-seed.yml +88 -0
- package/templates/ci/github-ratings.yml +51 -0
- package/templates/ci/gitlab-ci.yml +3 -3
- package/templates/ci/gitlab-ratings-seed.sh +83 -0
- package/templates/ci/gitlab-ratings.yml +37 -0
- package/templates/gitignore +8 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/** The `stats.json` version this producer writes. */
|
|
2
|
+
export declare const SCHEMA_VERSION = 1;
|
|
3
|
+
/**
|
|
4
|
+
* Where a run leaves the sidecar in the repository root. The renderer reads it
|
|
5
|
+
* at build time and the deploy publishes it as `stats.json`; it is never
|
|
6
|
+
* committed, so a rollback is *both* dropping the `ratings` block and deleting
|
|
7
|
+
* the published file (S-016) — the last tally is otherwise served forever.
|
|
8
|
+
*/
|
|
9
|
+
export declare const STATS_FILE = ".stats.json";
|
|
10
|
+
/** One ref's bag of stats — `{ rating: {...}, downloads: {...} }`. Values are opaque here. */
|
|
11
|
+
export type StatEntries = Record<string, Record<string, unknown>>;
|
|
12
|
+
/**
|
|
13
|
+
* The carry-forward surface of a published `stats.json`: the two maps that are
|
|
14
|
+
* keyed by stat name and must therefore survive a run that did not produce
|
|
15
|
+
* that stat. Everything else in the document (`schema_version`,
|
|
16
|
+
* `generated_at`) is re-derived, never carried.
|
|
17
|
+
*/
|
|
18
|
+
export interface StatsSeed {
|
|
19
|
+
/** Which backend produced each signal, keyed by stat name. */
|
|
20
|
+
providers: Record<string, string>;
|
|
21
|
+
entries: StatEntries;
|
|
22
|
+
}
|
|
23
|
+
/** The complete published document. */
|
|
24
|
+
export interface StatsDocument extends StatsSeed {
|
|
25
|
+
schema_version: number;
|
|
26
|
+
generated_at: string;
|
|
27
|
+
}
|
|
28
|
+
/** The first run's seed, and the only shape a genuine 404 may produce. */
|
|
29
|
+
export declare const EMPTY_SEED: StatsSeed;
|
|
30
|
+
/**
|
|
31
|
+
* Fetch the currently published `stats.json` to merge over.
|
|
32
|
+
*
|
|
33
|
+
* | Outcome | Behaviour |
|
|
34
|
+
* |---|---|
|
|
35
|
+
* | 404 | empty seed — the first run, and the normal case |
|
|
36
|
+
* | 2xx that parses | merge base |
|
|
37
|
+
* | 2xx that does not parse | **throws** (65) |
|
|
38
|
+
* | transport / TLS / 5xx / timeout / over-cap | **throws** (69) |
|
|
39
|
+
*
|
|
40
|
+
* `request()` maps its transport catch *and* its response-size cap to
|
|
41
|
+
* `{status: 0}`, so that value is a hard error here and can never be read as
|
|
42
|
+
* "the seed was fine and empty".
|
|
43
|
+
*/
|
|
44
|
+
export declare function loadSeed(url: string): Promise<StatsSeed>;
|
|
45
|
+
/**
|
|
46
|
+
* Merge one completed producer's output over the seed, per stat key.
|
|
47
|
+
*
|
|
48
|
+
* `fresh` is keyed by ref and holds only this producer's stat value, so a ref
|
|
49
|
+
* absent from it had its key genuinely observed as empty — the key is dropped,
|
|
50
|
+
* which is correct *because this producer completed*. A producer that failed
|
|
51
|
+
* never reaches here at all, and the seed it would have merged over is what
|
|
52
|
+
* gets published instead. That asymmetry is R-2.
|
|
53
|
+
*
|
|
54
|
+
* Refs are emitted in sorted order so a re-run over unchanged data produces an
|
|
55
|
+
* unchanged file.
|
|
56
|
+
*/
|
|
57
|
+
export declare function mergeStats(seed: StatsSeed, key: string, provider: string, fresh: Record<string, unknown>): StatsSeed;
|
|
58
|
+
/** Wrap merged stats in the publishable document. */
|
|
59
|
+
export declare function statsDocument(merged: StatsSeed, now?: Date): StatsDocument;
|
|
60
|
+
//# sourceMappingURL=seed.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seed.d.ts","sourceRoot":"","sources":["../../src/ratings/seed.ts"],"names":[],"mappings":"AAoBA,qDAAqD;AACrD,eAAO,MAAM,cAAc,IAAI,CAAC;AAEhC;;;;;GAKG;AACH,eAAO,MAAM,UAAU,gBAAgB,CAAC;AAExC,8FAA8F;AAC9F,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAElE;;;;;GAKG;AACH,MAAM,WAAW,SAAS;IACxB,8DAA8D;IAC9D,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,OAAO,EAAE,WAAW,CAAC;CACtB;AAED,uCAAuC;AACvC,MAAM,WAAW,aAAc,SAAQ,SAAS;IAC9C,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,0EAA0E;AAC1E,eAAO,MAAM,UAAU,EAAE,SAA0C,CAAC;AAEpE;;;;;;;;;;;;;GAaG;AACH,wBAAsB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CA2C9D;AAoBD;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CACxB,IAAI,EAAE,SAAS,EACf,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,SAAS,CAaX;AAED,qDAAqD;AACrD,wBAAgB,aAAa,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,GAAE,IAAiB,GAAG,aAAa,CAQtF"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Copyright 2026 The Grimoire Authors
|
|
3
|
+
// Invariant R-2, "no silent emptying", in the two functions that carry it: the
|
|
4
|
+
// seed fetch and the per-stat-key merge over what it returned.
|
|
5
|
+
//
|
|
6
|
+
// A published `stats.json` is not committed anywhere (ADR D8), so the live
|
|
7
|
+
// site IS the checkpoint. Every run re-derives its own stat key and carries
|
|
8
|
+
// every other one forward from that checkpoint untouched — never a whole-file
|
|
9
|
+
// replacement, because a `rating` run must not drop a `downloads` key it never
|
|
10
|
+
// computed.
|
|
11
|
+
//
|
|
12
|
+
// The status branching in [`loadSeed`] is the whole of it, and `|| true` is
|
|
13
|
+
// forbidden: a corrupted or unreachable seed is indistinguishable from an
|
|
14
|
+
// empty one, and treating it as empty is exactly how a published rating set
|
|
15
|
+
// gets silently replaced with nothing. So a fetch that did not clearly say
|
|
16
|
+
// "there is nothing here" fails the run instead.
|
|
17
|
+
import { CliError, EXIT } from "../cli/exit.js";
|
|
18
|
+
import { request } from "../validate/adapters/http.js";
|
|
19
|
+
/** The `stats.json` version this producer writes. */
|
|
20
|
+
export const SCHEMA_VERSION = 1;
|
|
21
|
+
/**
|
|
22
|
+
* Where a run leaves the sidecar in the repository root. The renderer reads it
|
|
23
|
+
* at build time and the deploy publishes it as `stats.json`; it is never
|
|
24
|
+
* committed, so a rollback is *both* dropping the `ratings` block and deleting
|
|
25
|
+
* the published file (S-016) — the last tally is otherwise served forever.
|
|
26
|
+
*/
|
|
27
|
+
export const STATS_FILE = ".stats.json";
|
|
28
|
+
/** The first run's seed, and the only shape a genuine 404 may produce. */
|
|
29
|
+
export const EMPTY_SEED = { providers: {}, entries: {} };
|
|
30
|
+
/**
|
|
31
|
+
* Fetch the currently published `stats.json` to merge over.
|
|
32
|
+
*
|
|
33
|
+
* | Outcome | Behaviour |
|
|
34
|
+
* |---|---|
|
|
35
|
+
* | 404 | empty seed — the first run, and the normal case |
|
|
36
|
+
* | 2xx that parses | merge base |
|
|
37
|
+
* | 2xx that does not parse | **throws** (65) |
|
|
38
|
+
* | transport / TLS / 5xx / timeout / over-cap | **throws** (69) |
|
|
39
|
+
*
|
|
40
|
+
* `request()` maps its transport catch *and* its response-size cap to
|
|
41
|
+
* `{status: 0}`, so that value is a hard error here and can never be read as
|
|
42
|
+
* "the seed was fine and empty".
|
|
43
|
+
*/
|
|
44
|
+
export async function loadSeed(url) {
|
|
45
|
+
const response = await request(url);
|
|
46
|
+
if (response.status === 404)
|
|
47
|
+
return { providers: {}, entries: {} };
|
|
48
|
+
if (response.status < 200 || response.status >= 300) {
|
|
49
|
+
// `status: 0` lands here too, and deliberately: it is the transport catch
|
|
50
|
+
// and the over-cap read, neither of which says anything about what is
|
|
51
|
+
// published.
|
|
52
|
+
throw new CliError(`could not read the published stats.json at ${url} (HTTP ${response.status}) — ` +
|
|
53
|
+
`refusing to publish a sidecar that would empty every rating`, EXIT.unavailable);
|
|
54
|
+
}
|
|
55
|
+
let parsed;
|
|
56
|
+
try {
|
|
57
|
+
parsed = JSON.parse(response.body);
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
throw new CliError(`the published stats.json at ${url} did not parse (${err.message}) — ` +
|
|
61
|
+
`refusing to treat an unreadable seed as an empty one`, EXIT.data);
|
|
62
|
+
}
|
|
63
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
64
|
+
throw new CliError(`the published stats.json at ${url} is not a JSON object`, EXIT.data);
|
|
65
|
+
}
|
|
66
|
+
// Absence *within* a document that parsed is first-class — a site that
|
|
67
|
+
// published a header and no entries yet has genuinely nothing to carry.
|
|
68
|
+
// A key that is PRESENT but the wrong shape is not absence, though: it is
|
|
69
|
+
// an unreadable seed wearing the clothes of an empty one, and coercing it
|
|
70
|
+
// to `{}` here would empty every published rating on the next deploy —
|
|
71
|
+
// the same silent emptying the parse guard above refuses, one layer in.
|
|
72
|
+
const doc = parsed;
|
|
73
|
+
return {
|
|
74
|
+
providers: object(doc.providers, "providers", url),
|
|
75
|
+
entries: object(doc.entries, "entries", url),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* A nested map: `{}` when the key is absent, a hard error when it is present
|
|
80
|
+
* and not a plain object.
|
|
81
|
+
*
|
|
82
|
+
* @throws {CliError} `EXIT.data` when `value` is present but not an object.
|
|
83
|
+
*/
|
|
84
|
+
function object(value, key, url) {
|
|
85
|
+
if (value === undefined || value === null)
|
|
86
|
+
return {};
|
|
87
|
+
if (typeof value !== "object" || Array.isArray(value)) {
|
|
88
|
+
throw new CliError(`the published stats.json at ${url} has a '${key}' that is not an object ` +
|
|
89
|
+
`(${Array.isArray(value) ? "array" : typeof value}) — refusing to treat a malformed seed as an empty one`, EXIT.data);
|
|
90
|
+
}
|
|
91
|
+
return value;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Merge one completed producer's output over the seed, per stat key.
|
|
95
|
+
*
|
|
96
|
+
* `fresh` is keyed by ref and holds only this producer's stat value, so a ref
|
|
97
|
+
* absent from it had its key genuinely observed as empty — the key is dropped,
|
|
98
|
+
* which is correct *because this producer completed*. A producer that failed
|
|
99
|
+
* never reaches here at all, and the seed it would have merged over is what
|
|
100
|
+
* gets published instead. That asymmetry is R-2.
|
|
101
|
+
*
|
|
102
|
+
* Refs are emitted in sorted order so a re-run over unchanged data produces an
|
|
103
|
+
* unchanged file.
|
|
104
|
+
*/
|
|
105
|
+
export function mergeStats(seed, key, provider, fresh) {
|
|
106
|
+
const entries = {};
|
|
107
|
+
for (const ref of [...new Set([...Object.keys(seed.entries), ...Object.keys(fresh)])].sort()) {
|
|
108
|
+
const carried = {};
|
|
109
|
+
for (const [stat, value] of Object.entries(seed.entries[ref] ?? {})) {
|
|
110
|
+
if (stat !== key)
|
|
111
|
+
carried[stat] = value;
|
|
112
|
+
}
|
|
113
|
+
// A ref absent from `fresh` had this key genuinely observed as empty, so
|
|
114
|
+
// the key is dropped — correct only because this producer completed.
|
|
115
|
+
if (ref in fresh)
|
|
116
|
+
carried[key] = fresh[ref];
|
|
117
|
+
if (Object.keys(carried).length > 0)
|
|
118
|
+
entries[ref] = carried;
|
|
119
|
+
}
|
|
120
|
+
return { providers: { ...seed.providers, [key]: provider }, entries };
|
|
121
|
+
}
|
|
122
|
+
/** Wrap merged stats in the publishable document. */
|
|
123
|
+
export function statsDocument(merged, now = new Date()) {
|
|
124
|
+
return {
|
|
125
|
+
schema_version: SCHEMA_VERSION,
|
|
126
|
+
// RFC 3339 UTC, seconds resolution — the shape every fixture pins.
|
|
127
|
+
generated_at: now.toISOString().replace(/\.\d+Z$/, "Z"),
|
|
128
|
+
providers: merged.providers,
|
|
129
|
+
entries: merged.entries,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=seed.js.map
|
|
@@ -0,0 +1 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,YAAY,EAAE,GAAG,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC;QACvD,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,OAAO,EAAE,MAAM,CAAC,OAAO;KACxB,CAAC;AACJ,CAAC"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { type CatalogPackage } from "../lib/catalog.js";
|
|
2
|
+
export type Sort = "name" | "updated" | "rating";
|
|
3
|
+
export declare function compare(a: CatalogPackage, b: CatalogPackage, sort: Sort): number;
|
|
2
4
|
export default function Catalog({ packages, vscodeExtension, }: {
|
|
3
5
|
packages: CatalogPackage[];
|
|
4
6
|
vscodeExtension: string | null;
|
|
@@ -2,11 +2,11 @@ import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
|
2
2
|
import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "preact/hooks";
|
|
3
3
|
// Lucide (ISC) draws the UI; brand marks come from `@mdi/js`, which Lucide
|
|
4
4
|
// deliberately does not carry. No SVG on this site is hand-written.
|
|
5
|
-
import { Check, FolderRoot, Globe, Image, ImageOff } from "lucide-preact";
|
|
5
|
+
import { ArrowBigUp, Check, FolderRoot, Globe, Image, ImageOff } from "lucide-preact";
|
|
6
6
|
import { mdiMicrosoftVisualStudioCode } from "@mdi/js";
|
|
7
7
|
import { BrandMark } from "./BrandMark.js";
|
|
8
8
|
import { withBase } from "../lib/base.js";
|
|
9
|
-
import { timeAgo, vscodeUrl } from "../lib/catalog.js";
|
|
9
|
+
import { lastUpdated, timeAgo, vscodeUrl } from "../lib/catalog.js";
|
|
10
10
|
// Known kinds get stable chip ordering + badge colors; unknown kinds
|
|
11
11
|
// (future schema growth) still render with a neutral badge.
|
|
12
12
|
const KNOWN_KINDS = ["skill", "rule", "agent", "mcp", "bundle"];
|
|
@@ -14,17 +14,61 @@ function kindOrder(kind) {
|
|
|
14
14
|
const i = KNOWN_KINDS.indexOf(kind);
|
|
15
15
|
return i === -1 ? KNOWN_KINDS.length : i;
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Bigger first, with `null` as its own bucket underneath every number.
|
|
19
|
+
*
|
|
20
|
+
* The shared shape of the two ranked keys, and the reason both are written
|
|
21
|
+
* this way: "missing" is not a low value, it is the absence of one. Folding
|
|
22
|
+
* it into a number — 0 upvotes, epoch 0 — orders those rows against real
|
|
23
|
+
* data by accident, and ties them all with each other.
|
|
24
|
+
*/
|
|
25
|
+
function descending(a, b) {
|
|
26
|
+
if (a === null || b === null)
|
|
27
|
+
return Number(a === null) - Number(b === null);
|
|
28
|
+
return b - a;
|
|
29
|
+
}
|
|
30
|
+
/** `updated` as epoch ms; null when absent, empty or not a date at all. */
|
|
31
|
+
function updatedAt(p) {
|
|
32
|
+
const at = lastUpdated(p);
|
|
33
|
+
const ms = at ? new Date(at).getTime() : NaN;
|
|
34
|
+
return Number.isFinite(ms) ? ms : null;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Ascending, case-insensitive. The full ref breaks the last tie in every
|
|
38
|
+
* mode, and it is unique, so no two rows ever compare equal — a browse order
|
|
39
|
+
* that is not total is a browse order that reshuffles on rebuild.
|
|
40
|
+
*/
|
|
41
|
+
const byName = (a, b) => a.name.localeCompare(b.name, undefined, { sensitivity: "accent" }) || a.ref.localeCompare(b.ref);
|
|
42
|
+
/**
|
|
43
|
+
* Newest first. No usable date is *unknown*, not epoch 0: dating an undated
|
|
44
|
+
* package to 1970 sorts it below real packages by accident rather than by
|
|
45
|
+
* rule, so it goes into a bucket of its own at the bottom.
|
|
46
|
+
*/
|
|
47
|
+
const byUpdated = (a, b) => descending(updatedAt(a), updatedAt(b));
|
|
48
|
+
/**
|
|
49
|
+
* Most upvotes first. Unrated is its own bucket at the bottom, never a zero:
|
|
50
|
+
* a fresh index is all-unrated, and zeroes would leave every one of those
|
|
51
|
+
* rows comparing equal with nothing left to break the tie.
|
|
52
|
+
*/
|
|
53
|
+
const byRating = (a, b) => descending(a.rating?.up ?? null, b.rating?.up ?? null);
|
|
54
|
+
/** Each mode as a chain of keys, most significant first. */
|
|
55
|
+
const CHAINS = {
|
|
56
|
+
name: [byName],
|
|
57
|
+
updated: [byUpdated, byName],
|
|
58
|
+
rating: [byRating, byUpdated, byName],
|
|
59
|
+
};
|
|
60
|
+
// Deprecated packages get no special ordering here — they are filtered out
|
|
61
|
+
// of the default browse entirely (see `shown` below) and interleave like
|
|
62
|
+
// any other row when the toggle brings them back. grim's own browse order
|
|
63
|
+
// (`browse_sort.rs`) has no deprecated key either; keeping this comparator
|
|
64
|
+
// silent on deprecation is what keeps the two in sync.
|
|
65
|
+
export function compare(a, b, sort) {
|
|
66
|
+
for (const key of CHAINS[sort]) {
|
|
67
|
+
const d = key(a, b);
|
|
68
|
+
if (d !== 0)
|
|
69
|
+
return d;
|
|
70
|
+
}
|
|
71
|
+
return 0;
|
|
28
72
|
}
|
|
29
73
|
// The two install scopes previously wore the VS Code extension's own
|
|
30
74
|
// codicons so "project" and "global" read identically in both. That parity
|
|
@@ -376,9 +420,14 @@ export default function Catalog({ packages, vscodeExtension, }) {
|
|
|
376
420
|
});
|
|
377
421
|
const shown = (showDeprecated ? matching : matching.filter((p) => !p.deprecated)).sort((a, b) => compare(a, b, sort));
|
|
378
422
|
// A catalog with nothing deprecated gets no toggle — a control that can
|
|
379
|
-
// only ever be a no-op is worse than its absence.
|
|
423
|
+
// only ever be a no-op is worse than its absence. An index that publishes
|
|
424
|
+
// no ratings gets no rating chip for the same reason.
|
|
380
425
|
const hasDeprecated = packages.some((p) => p.deprecated);
|
|
426
|
+
const hasRatings = packages.some((p) => p.rating);
|
|
381
427
|
// Chips leave the Tab order only while there is a grid to arrow up from.
|
|
382
428
|
const chipTabIndex = shown.length === 0 ? 0 : -1;
|
|
383
|
-
return (_jsxs("section", { class: "catalog", children: [_jsxs("div", { class: "controls", ref: controlsRef, children: [_jsxs("div", { class: "search-field", children: [_jsx("input", { ref: searchRef, type: "search", placeholder: `Search ${counted.length} packages…`, value: query, onInput: (e) => setQuery(e.target.value), onKeyDown: onSearchKeyDown, "aria-label": "Search packages", "aria-keyshortcuts": "/" }), _jsx("kbd", { class: "search-hint", "aria-hidden": "true", children: "/" })] }), _jsxs("div", { class: "chips", role: "group", "aria-label": "Sort by", children: [_jsx("button", { type: "button", class: sort === "name" ? "chip active" : "chip", tabIndex: chipTabIndex, onKeyDown: onChipKeyDown, onClick: () => setSort("name"), children: "name" }), _jsx("button", { type: "button", class: sort === "updated" ? "chip active" : "chip", tabIndex: chipTabIndex, onKeyDown: onChipKeyDown, onClick: () => setSort("updated"), children: "updated" })] }), _jsx("span", { class: "chip-sep", "aria-hidden": "true" }), _jsxs("div", { class: "chips", role: "group", "aria-label": "Filter by kind", children: [_jsxs("button", { type: "button", class: kind === null ? "chip active" : "chip", tabIndex: chipTabIndex, onKeyDown: onChipKeyDown, onClick: () => setKind(null), children: ["all ", _jsx("small", { children: counted.length })] }), kinds.map(([k, count]) => (_jsxs("button", { type: "button", class: kind === k ? `chip active kind-${k}` : `chip kind-${k}`, tabIndex: chipTabIndex, onKeyDown: onChipKeyDown, onClick: () => setKind(kind === k ? null : k), children: [k, " ", _jsx("small", { children: count })] }, k)))] }), hasDeprecated && (_jsx("button", { type: "button", class: showDeprecated ? "chip deprecated-toggle active" : "chip deprecated-toggle", "aria-pressed": showDeprecated, title: showDeprecated ? "Hide deprecated packages" : "Show deprecated packages", tabIndex: chipTabIndex, onKeyDown: onChipKeyDown, onClick: () => setShowDeprecated((on) => !on), children: "deprecated" }))] }), shown.length === 0 ? (_jsx("p", { class: "empty", children: "No packages match." })) : (_jsx("ul", { class: "grid", ref: gridRef, children: shown.map((p) => (_jsxs("li", { class: "card", tabIndex: 0, onKeyDown: onCardKeyDown, children: [_jsxs("div", { class: "card-head", children: [_jsx(CardLogo, { pkg: p }), _jsx("h2", { children: _jsx("a", { href: withBase(`/p/${p.namespace}/${p.name}/`), tabIndex: -1, children: p.name }) }), p.deprecated ? (_jsx("span", { class: "badge deprecated", children: "deprecated" })) : (_jsx("span", { class: `badge kind-${p.kind}`, children: p.kind }))] }), _jsx("p", { class: "namespace", children: p.namespace }), (p.version || p.license || p.
|
|
429
|
+
return (_jsxs("section", { class: "catalog", children: [_jsxs("div", { class: "controls", ref: controlsRef, children: [_jsxs("div", { class: "search-field", children: [_jsx("input", { ref: searchRef, type: "search", placeholder: `Search ${counted.length} packages…`, value: query, onInput: (e) => setQuery(e.target.value), onKeyDown: onSearchKeyDown, "aria-label": "Search packages", "aria-keyshortcuts": "/" }), _jsx("kbd", { class: "search-hint", "aria-hidden": "true", children: "/" })] }), _jsxs("div", { class: "chips", role: "group", "aria-label": "Sort by", children: [_jsx("button", { type: "button", class: sort === "name" ? "chip active" : "chip", tabIndex: chipTabIndex, onKeyDown: onChipKeyDown, onClick: () => setSort("name"), children: "name" }), _jsx("button", { type: "button", class: sort === "updated" ? "chip active" : "chip", tabIndex: chipTabIndex, onKeyDown: onChipKeyDown, onClick: () => setSort("updated"), children: "updated" }), hasRatings && (_jsx("button", { type: "button", class: sort === "rating" ? "chip active" : "chip", tabIndex: chipTabIndex, onKeyDown: onChipKeyDown, onClick: () => setSort("rating"), children: "rating" }))] }), _jsx("span", { class: "chip-sep", "aria-hidden": "true" }), _jsxs("div", { class: "chips", role: "group", "aria-label": "Filter by kind", children: [_jsxs("button", { type: "button", class: kind === null ? "chip active" : "chip", tabIndex: chipTabIndex, onKeyDown: onChipKeyDown, onClick: () => setKind(null), children: ["all ", _jsx("small", { children: counted.length })] }), kinds.map(([k, count]) => (_jsxs("button", { type: "button", class: kind === k ? `chip active kind-${k}` : `chip kind-${k}`, tabIndex: chipTabIndex, onKeyDown: onChipKeyDown, onClick: () => setKind(kind === k ? null : k), children: [k, " ", _jsx("small", { children: count })] }, k)))] }), hasDeprecated && (_jsx("button", { type: "button", class: showDeprecated ? "chip deprecated-toggle active" : "chip deprecated-toggle", "aria-pressed": showDeprecated, title: showDeprecated ? "Hide deprecated packages" : "Show deprecated packages", tabIndex: chipTabIndex, onKeyDown: onChipKeyDown, onClick: () => setShowDeprecated((on) => !on), children: "deprecated" }))] }), shown.length === 0 ? (_jsx("p", { class: "empty", children: "No packages match." })) : (_jsx("ul", { class: "grid", ref: gridRef, children: shown.map((p) => (_jsxs("li", { class: "card", tabIndex: 0, onKeyDown: onCardKeyDown, children: [_jsxs("div", { class: "card-head", children: [_jsx(CardLogo, { pkg: p }), _jsx("h2", { children: _jsx("a", { href: withBase(`/p/${p.namespace}/${p.name}/`), tabIndex: -1, children: p.name }) }), p.deprecated ? (_jsx("span", { class: "badge deprecated", children: "deprecated" })) : (_jsx("span", { class: `badge kind-${p.kind}`, children: p.kind }))] }), _jsx("p", { class: "namespace", children: p.namespace }), (p.version || p.license || lastUpdated(p) || p.rating) && (_jsxs("div", { class: "meta-row", children: [p.version && _jsxs("span", { class: "pill version", children: ["v", p.version] }), p.license && _jsx("span", { class: "pill license", children: p.license }), p.rating && (_jsxs("span", { class: "pill rating", title: `${p.rating.up} upvote${p.rating.up === 1 ? "" : "s"}`, children: [_jsx(ArrowBigUp, { size: 13, "aria-hidden": "true" }), p.rating.up] })), (() => {
|
|
430
|
+
const at = lastUpdated(p);
|
|
431
|
+
return at && timeAgo(at) ? (_jsxs("time", { class: "updated", datetime: at, title: at, children: ["updated ", timeAgo(at)] })) : null;
|
|
432
|
+
})()] })), p.deprecated && (_jsxs("p", { class: "deprecated-strip", children: ["deprecated", p.replacedBy ? ` — replaced by ${p.replacedBy}` : ""] })), p.description && _jsx("p", { class: "description", children: p.description }), p.keywords && p.keywords.length > 0 && (_jsxs("div", { class: "keywords", children: [p.keywords.slice(0, 5).map((kw) => (_jsx("button", { type: "button", class: "chip keyword", tabIndex: -1, onClick: () => setQuery(kw), children: kw }, kw))), p.keywords.length > 5 && (_jsxs("span", { class: "chip keyword overflow", children: ["+", p.keywords.length - 5] }))] })), _jsxs("div", { class: "card-foot", children: [_jsxs("div", { class: "copy-group", children: [_jsx(CopyButton, { command: `grim add --global ${p.ref}`, variant: "global", name: `global add for ${p.name}` }), _jsx(CopyButton, { command: `grim add ${p.ref}`, name: `project add for ${p.name}` }), vscodeUrl(vscodeExtension, p.ref) && (_jsx("a", { class: "copy vscode", href: vscodeUrl(vscodeExtension, p.ref), title: "Open in VS Code", "aria-label": `Open ${p.name} in VS Code`, tabIndex: -1, children: _jsx(BrandMark, { path: mdiMicrosoftVisualStudioCode }) }))] }), p.repository && (_jsx("a", { class: "source", href: p.repository, target: "_blank", rel: "noopener noreferrer", tabIndex: -1, children: "source" }))] })] }, `${p.namespace}/${p.name}`))) }))] }));
|
|
384
433
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "preact/hooks";
|
|
2
2
|
// Lucide (ISC) draws the UI; brand marks come from `@mdi/js`, which Lucide
|
|
3
3
|
// deliberately does not carry. No SVG on this site is hand-written.
|
|
4
|
-
import { Check, FolderRoot, Globe, Image, ImageOff } from "lucide-preact";
|
|
4
|
+
import { ArrowBigUp, Check, FolderRoot, Globe, Image, ImageOff } from "lucide-preact";
|
|
5
5
|
import { mdiMicrosoftVisualStudioCode } from "@mdi/js";
|
|
6
6
|
import { BrandMark } from "./BrandMark.js";
|
|
7
7
|
import { withBase } from "../lib/base.js";
|
|
8
|
-
import { timeAgo, vscodeUrl, type CatalogPackage } from "../lib/catalog.js";
|
|
8
|
+
import { lastUpdated, timeAgo, vscodeUrl, type CatalogPackage } from "../lib/catalog.js";
|
|
9
9
|
|
|
10
10
|
// Known kinds get stable chip ordering + badge colors; unknown kinds
|
|
11
11
|
// (future schema growth) still render with a neutral badge.
|
|
@@ -16,16 +16,70 @@ function kindOrder(kind: string): number {
|
|
|
16
16
|
return i === -1 ? KNOWN_KINDS.length : i;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
type Sort = "name" | "updated";
|
|
19
|
+
export type Sort = "name" | "updated" | "rating";
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
type Key = (a: CatalogPackage, b: CatalogPackage) => number;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Bigger first, with `null` as its own bucket underneath every number.
|
|
25
|
+
*
|
|
26
|
+
* The shared shape of the two ranked keys, and the reason both are written
|
|
27
|
+
* this way: "missing" is not a low value, it is the absence of one. Folding
|
|
28
|
+
* it into a number — 0 upvotes, epoch 0 — orders those rows against real
|
|
29
|
+
* data by accident, and ties them all with each other.
|
|
30
|
+
*/
|
|
31
|
+
function descending(a: number | null, b: number | null): number {
|
|
32
|
+
if (a === null || b === null) return Number(a === null) - Number(b === null);
|
|
33
|
+
return b - a;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** `updated` as epoch ms; null when absent, empty or not a date at all. */
|
|
37
|
+
function updatedAt(p: CatalogPackage): number | null {
|
|
38
|
+
const at = lastUpdated(p);
|
|
39
|
+
const ms = at ? new Date(at).getTime() : NaN;
|
|
40
|
+
return Number.isFinite(ms) ? ms : null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Ascending, case-insensitive. The full ref breaks the last tie in every
|
|
45
|
+
* mode, and it is unique, so no two rows ever compare equal — a browse order
|
|
46
|
+
* that is not total is a browse order that reshuffles on rebuild.
|
|
47
|
+
*/
|
|
48
|
+
const byName: Key = (a, b) =>
|
|
49
|
+
a.name.localeCompare(b.name, undefined, { sensitivity: "accent" }) || a.ref.localeCompare(b.ref);
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Newest first. No usable date is *unknown*, not epoch 0: dating an undated
|
|
53
|
+
* package to 1970 sorts it below real packages by accident rather than by
|
|
54
|
+
* rule, so it goes into a bucket of its own at the bottom.
|
|
55
|
+
*/
|
|
56
|
+
const byUpdated: Key = (a, b) => descending(updatedAt(a), updatedAt(b));
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Most upvotes first. Unrated is its own bucket at the bottom, never a zero:
|
|
60
|
+
* a fresh index is all-unrated, and zeroes would leave every one of those
|
|
61
|
+
* rows comparing equal with nothing left to break the tie.
|
|
62
|
+
*/
|
|
63
|
+
const byRating: Key = (a, b) => descending(a.rating?.up ?? null, b.rating?.up ?? null);
|
|
64
|
+
|
|
65
|
+
/** Each mode as a chain of keys, most significant first. */
|
|
66
|
+
const CHAINS: Record<Sort, Key[]> = {
|
|
67
|
+
name: [byName],
|
|
68
|
+
updated: [byUpdated, byName],
|
|
69
|
+
rating: [byRating, byUpdated, byName],
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// Deprecated packages get no special ordering here — they are filtered out
|
|
73
|
+
// of the default browse entirely (see `shown` below) and interleave like
|
|
74
|
+
// any other row when the toggle brings them back. grim's own browse order
|
|
75
|
+
// (`browse_sort.rs`) has no deprecated key either; keeping this comparator
|
|
76
|
+
// silent on deprecation is what keeps the two in sync.
|
|
77
|
+
export function compare(a: CatalogPackage, b: CatalogPackage, sort: Sort): number {
|
|
78
|
+
for (const key of CHAINS[sort]) {
|
|
79
|
+
const d = key(a, b);
|
|
80
|
+
if (d !== 0) return d;
|
|
81
|
+
}
|
|
82
|
+
return 0;
|
|
29
83
|
}
|
|
30
84
|
|
|
31
85
|
// The two install scopes previously wore the VS Code extension's own
|
|
@@ -449,8 +503,10 @@ export default function Catalog({
|
|
|
449
503
|
);
|
|
450
504
|
|
|
451
505
|
// A catalog with nothing deprecated gets no toggle — a control that can
|
|
452
|
-
// only ever be a no-op is worse than its absence.
|
|
506
|
+
// only ever be a no-op is worse than its absence. An index that publishes
|
|
507
|
+
// no ratings gets no rating chip for the same reason.
|
|
453
508
|
const hasDeprecated = packages.some((p) => p.deprecated);
|
|
509
|
+
const hasRatings = packages.some((p) => p.rating);
|
|
454
510
|
|
|
455
511
|
// Chips leave the Tab order only while there is a grid to arrow up from.
|
|
456
512
|
const chipTabIndex = shown.length === 0 ? 0 : -1;
|
|
@@ -493,6 +549,17 @@ export default function Catalog({
|
|
|
493
549
|
>
|
|
494
550
|
updated
|
|
495
551
|
</button>
|
|
552
|
+
{hasRatings && (
|
|
553
|
+
<button
|
|
554
|
+
type="button"
|
|
555
|
+
class={sort === "rating" ? "chip active" : "chip"}
|
|
556
|
+
tabIndex={chipTabIndex}
|
|
557
|
+
onKeyDown={onChipKeyDown}
|
|
558
|
+
onClick={() => setSort("rating")}
|
|
559
|
+
>
|
|
560
|
+
rating
|
|
561
|
+
</button>
|
|
562
|
+
)}
|
|
496
563
|
</div>
|
|
497
564
|
{/* Divides sort from filter — two different questions sharing a row.
|
|
498
565
|
Decorative only: each group already carries its own aria-label,
|
|
@@ -574,15 +641,35 @@ export default function Catalog({
|
|
|
574
641
|
)}
|
|
575
642
|
</div>
|
|
576
643
|
<p class="namespace">{p.namespace}</p>
|
|
577
|
-
{(p.version || p.license || p.
|
|
644
|
+
{(p.version || p.license || lastUpdated(p) || p.rating) && (
|
|
578
645
|
<div class="meta-row">
|
|
579
646
|
{p.version && <span class="pill version">v{p.version}</span>}
|
|
580
647
|
{p.license && <span class="pill license">{p.license}</span>}
|
|
581
|
-
{
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
648
|
+
{/* A count and nothing more. The page is prerendered once
|
|
649
|
+
for everyone, so it cannot know whether *you* voted —
|
|
650
|
+
showing "not voted" to someone who has would be worse
|
|
651
|
+
than showing nothing. */}
|
|
652
|
+
{p.rating && (
|
|
653
|
+
<span
|
|
654
|
+
class="pill rating"
|
|
655
|
+
title={`${p.rating.up} upvote${p.rating.up === 1 ? "" : "s"}`}
|
|
656
|
+
>
|
|
657
|
+
<ArrowBigUp size={13} aria-hidden="true" />
|
|
658
|
+
{p.rating.up}
|
|
659
|
+
</span>
|
|
585
660
|
)}
|
|
661
|
+
{/* The date the sidecar derived, not the artifact's own
|
|
662
|
+
`created`: a package republished from the same commit
|
|
663
|
+
keeps its date, and one with no commit date at all gets
|
|
664
|
+
the day this index first saw its current digest. */}
|
|
665
|
+
{(() => {
|
|
666
|
+
const at = lastUpdated(p);
|
|
667
|
+
return at && timeAgo(at) ? (
|
|
668
|
+
<time class="updated" datetime={at} title={at}>
|
|
669
|
+
updated {timeAgo(at)}
|
|
670
|
+
</time>
|
|
671
|
+
) : null;
|
|
672
|
+
})()}
|
|
586
673
|
</div>
|
|
587
674
|
)}
|
|
588
675
|
{p.deprecated && (
|
|
@@ -1181,6 +1181,13 @@ function repoLabel(url: string): string {
|
|
|
1181
1181
|
.pill.version {
|
|
1182
1182
|
font-family: ui-monospace, "SFMono-Regular", monospace;
|
|
1183
1183
|
}
|
|
1184
|
+
/* The only pill carrying a glyph — inline would baseline the arrow
|
|
1185
|
+
low against the digits beside it. */
|
|
1186
|
+
.pill.rating {
|
|
1187
|
+
display: inline-flex;
|
|
1188
|
+
align-items: center;
|
|
1189
|
+
gap: 0.15rem;
|
|
1190
|
+
}
|
|
1184
1191
|
.updated {
|
|
1185
1192
|
font-size: 0.78rem;
|
|
1186
1193
|
color: var(--muted);
|
|
@@ -1,7 +1,32 @@
|
|
|
1
|
+
import type { CatalogPackage } from "../../types.js";
|
|
1
2
|
export type { CatalogPackage } from "../../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* When a package last moved, for sorting and for the "updated" stamp.
|
|
5
|
+
*
|
|
6
|
+
* `updated` is what `enrich` derived — the artifact's own `created` when it
|
|
7
|
+
* has one, and the first build that saw the current digest when it does not.
|
|
8
|
+
* The fallback to `created` is for a sidecar written before that field
|
|
9
|
+
* existed: those records still date correctly instead of dropping into the
|
|
10
|
+
* unknown bucket on the first build after an upgrade.
|
|
11
|
+
*/
|
|
12
|
+
export declare function lastUpdated(p: CatalogPackage): string | undefined;
|
|
2
13
|
export declare function versionCascade(version: string | undefined, tags: string[]): string[];
|
|
3
14
|
export declare function compareVersions(a: string, b: string): number;
|
|
4
15
|
export declare function timeAgo(iso: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* One registry-supplied string as an outbound href, or null.
|
|
18
|
+
*
|
|
19
|
+
* Every URL on a package page — its repository, its home page, its docs, its
|
|
20
|
+
* four support channels — is a string the index was handed by a registry it
|
|
21
|
+
* does not control, and an `href` is not made safe by escaping: `javascript:`
|
|
22
|
+
* is a perfectly well-formed attribute value that runs on click. Only the
|
|
23
|
+
* three schemes a link here can legitimately use survive; everything else
|
|
24
|
+
* renders as no link at all rather than as a live one.
|
|
25
|
+
*
|
|
26
|
+
* The raw string is returned rather than `URL.href`, so a link that was
|
|
27
|
+
* already fine is published exactly as the registry spelled it.
|
|
28
|
+
*/
|
|
29
|
+
export declare function externalUrl(raw: unknown): string | null;
|
|
5
30
|
/** `vscode://<publisher.extension>/open?repo=<ref>`, or null when disabled. */
|
|
6
31
|
export declare function vscodeUrl(extension: string | null, ref: string): string | null;
|
|
7
32
|
/**
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
// Copyright 2026 The Grimoire Authors
|
|
3
|
+
/**
|
|
4
|
+
* When a package last moved, for sorting and for the "updated" stamp.
|
|
5
|
+
*
|
|
6
|
+
* `updated` is what `enrich` derived — the artifact's own `created` when it
|
|
7
|
+
* has one, and the first build that saw the current digest when it does not.
|
|
8
|
+
* The fallback to `created` is for a sidecar written before that field
|
|
9
|
+
* existed: those records still date correctly instead of dropping into the
|
|
10
|
+
* unknown bucket on the first build after an upgrade.
|
|
11
|
+
*/
|
|
12
|
+
export function lastUpdated(p) {
|
|
13
|
+
return p.updated ?? p.created;
|
|
14
|
+
}
|
|
3
15
|
// Publishing 0.10.0 also moves the rolling tags 0.10, 0 and latest, so the
|
|
4
16
|
// full tag list is mostly history. Return just the current release's chain
|
|
5
17
|
// (latest | 0 | 0.10 | 0.10.0). `tags` must already be sorted newest-first.
|
|
@@ -54,6 +66,40 @@ export function timeAgo(iso) {
|
|
|
54
66
|
}
|
|
55
67
|
return RTF.format(Math.round(duration), "years");
|
|
56
68
|
}
|
|
69
|
+
/** A bare address, which `support.contact` is far more likely to hold than a URL. */
|
|
70
|
+
const EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
71
|
+
/** The only schemes a link on this site may carry. */
|
|
72
|
+
const LINK_SCHEMES = ["https:", "http:", "mailto:"];
|
|
73
|
+
/**
|
|
74
|
+
* One registry-supplied string as an outbound href, or null.
|
|
75
|
+
*
|
|
76
|
+
* Every URL on a package page — its repository, its home page, its docs, its
|
|
77
|
+
* four support channels — is a string the index was handed by a registry it
|
|
78
|
+
* does not control, and an `href` is not made safe by escaping: `javascript:`
|
|
79
|
+
* is a perfectly well-formed attribute value that runs on click. Only the
|
|
80
|
+
* three schemes a link here can legitimately use survive; everything else
|
|
81
|
+
* renders as no link at all rather than as a live one.
|
|
82
|
+
*
|
|
83
|
+
* The raw string is returned rather than `URL.href`, so a link that was
|
|
84
|
+
* already fine is published exactly as the registry spelled it.
|
|
85
|
+
*/
|
|
86
|
+
export function externalUrl(raw) {
|
|
87
|
+
if (typeof raw !== "string")
|
|
88
|
+
return null;
|
|
89
|
+
const value = raw.trim();
|
|
90
|
+
if (value === "")
|
|
91
|
+
return null;
|
|
92
|
+
try {
|
|
93
|
+
return LINK_SCHEMES.includes(new URL(value).protocol) ? value : null;
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
// Not a URL at all. `mailto:` is only added to something that carries no
|
|
97
|
+
// scheme of its own — testing for an address first would read the
|
|
98
|
+
// `mailto:alice@acme.example` a publisher already wrote as a bare
|
|
99
|
+
// address and prefix it a second time.
|
|
100
|
+
return EMAIL.test(value) ? `mailto:${value}` : null;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
57
103
|
/** `vscode://<publisher.extension>/open?repo=<ref>`, or null when disabled. */
|
|
58
104
|
export function vscodeUrl(extension, ref) {
|
|
59
105
|
return extension ? `vscode://${extension}/open?repo=${encodeURIComponent(ref)}` : null;
|