aboutsummaryrefslogtreecommitdiff
path: root/website/src/pages/plugins.astro
blob: 6e96a13220e8b7cc3228108dc1142438c8d38f77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
---
import MarketingLayout from '../components/MarketingLayout.astro';
import fixture from '../data/plugins-fixture.json';

const snapshotUrl = 'https://assets.herdr.dev/plugins/index.json';

// Seed the page server-side from the public R2 snapshot so `bun run dev` and
// the production build both render real data immediately. If the live fetch
// fails, dev falls back to a local fixture for offline design; production seeds
// empty and lets the client fetch fill it (never fake data).
let liveData = null;
try {
  const res = await fetch(snapshotUrl);
  if (res.ok) liveData = await res.json();
} catch {
  // ignore: handled by the fallbacks below
}
const initialData = liveData ?? (import.meta.env.DEV ? fixture : null);
const initialIsFixture = !liveData && import.meta.env.DEV;
const apiUrl = import.meta.env.DEV ? null : snapshotUrl;
---

<MarketingLayout
  title="Herdr plugins: community plugin marketplace"
  description="Discover community Herdr plugins published on GitHub. An automatic index of public repositories tagged with the herdr-plugin topic."
  canonicalPath="/plugins/"
>
  <main class="plugins-page">
    <section class="section plugins-hero">
      <p class="section-kicker"># marketplace</p>
      <h2>Plugins built on Herdr.</h2>
      <p class="plugins-lede">
        Community plugins published on GitHub. Install any of them with
        <code>herdr plugin install</code>, or publish your own and get listed.
      </p>
      <p class="plugins-trust">
        <span class="status-dot dot-idle"></span>
        Listings are discovered automatically from the GitHub topic
        <code>herdr-plugin</code>. They are not reviewed by Herdr, so install at
        your own discretion. <a href="/docs/plugins/#trust-and-security">Trust guidance</a>.
      </p>
    </section>

    <section class="section plugins-controls">
      <div class="plugins-search-wrap">
        <span class="plugins-search-icon" aria-hidden="true">/</span>
        <input
          id="plugins-search"
          type="search"
          class="plugins-search"
          placeholder="search plugins, owners, languages…"
          autocomplete="off"
          spellcheck="false"
          aria-label="Search plugins"
        />
      </div>
      <label class="plugins-sort-wrap">
        <span class="plugins-sort-label">sort</span>
        <select id="plugins-sort" class="plugins-sort" aria-label="Sort plugins">
          <option value="popular">Popular</option>
          <option value="recent">Recently updated</option>
          <option value="newest">Newest</option>
          <option value="name">Name</option>
        </select>
      </label>
      <p id="plugins-meta" class="plugins-meta" aria-live="polite"></p>
    </section>

    <section class="section plugins-results">
      <div id="plugins-grid" class="plugins-grid" role="list"></div>
      <div id="plugins-status" class="plugins-status">Loading plugins…</div>
    </section>

    <section class="section plugins-publish">
      <div class="plugins-publish-card">
        <p class="section-kicker"># publish</p>
        <h3>Want your plugin listed?</h3>
        <p>
          Add the GitHub topic <code>herdr-plugin</code> to a public repository
          with a <code>herdr-plugin.toml</code> manifest. The index picks it up
          on the next refresh. No submission, no review queue.
        </p>
        <div class="plugins-publish-actions">
          <a class="button button-primary" href="/docs/marketplace/">How publishing works</a>
          <a class="button button-secondary" href="/docs/plugins/">Author a plugin</a>
        </div>
      </div>
    </section>
  </main>

  <script define:vars={{ initialData, initialIsFixture, apiUrl }}>
    const grid = document.getElementById("plugins-grid");
    const statusEl = document.getElementById("plugins-status");
    const searchInput = document.getElementById("plugins-search");
    const sortSelect = document.getElementById("plugins-sort");
    const metaEl = document.getElementById("plugins-meta");

    const LANG_COLORS = {
      TypeScript: "#3178c6",
      JavaScript: "#f1e05a",
      Rust: "#dea584",
      Python: "#3572A5",
      Go: "#00ADD8",
      Lua: "#000080",
      Shell: "#89e051",
      "C++": "#f34b7d",
      Ruby: "#701516",
    };

    let plugins = [];
    let usingFallback = false;

    function timeAgo(iso) {
      if (!iso) return null;
      const then = new Date(iso).getTime();
      if (Number.isNaN(then)) return null;
      const secs = Math.max(0, Math.round((Date.now() - then) / 1000));
      const units = [
        ["y", 31536000],
        ["mo", 2592000],
        ["w", 604800],
        ["d", 86400],
        ["h", 3600],
        ["m", 60],
      ];
      for (const [label, size] of units) {
        const v = Math.floor(secs / size);
        if (v >= 1) return v + label + " ago";
      }
      return "just now";
    }

    function isGithubUrl(url) {
      return typeof url === "string" && /^https:\/\/github\.com\/[^/]+\/[^/]+/.test(url);
    }

    function el(tag, className, text) {
      const node = document.createElement(tag);
      if (className) node.className = className;
      if (text != null) node.textContent = text;
      return node;
    }

    function buildCard(p) {
      const url = isGithubUrl(p.url) ? p.url : null;
      const card = el(url ? "a" : "div", "plugin-card");
      card.setAttribute("role", "listitem");
      if (url) {
        card.href = url;
        card.target = "_blank";
        card.rel = "noopener noreferrer";
      }

      const head = el("div", "plugin-card-head");
      const title = el("div", "plugin-title");
      title.appendChild(el("span", "plugin-owner", (p.owner || "?") + "/"));
      title.appendChild(el("span", "plugin-name", p.name || "unknown"));
      head.appendChild(title);
      head.appendChild(el("span", "plugin-go", "↗"));
      card.appendChild(head);

      const desc = el(
        "p",
        "plugin-desc" + (p.description ? "" : " is-empty"),
        p.description || "No description provided.",
      );
      card.appendChild(desc);

      const meta = el("div", "plugin-meta-row");

      const stars = el("span", "plugin-stat");
      stars.appendChild(el("span", "plugin-star", "★"));
      stars.appendChild(el("span", null, String(p.stars ?? 0)));
      meta.appendChild(stars);

      if (p.language) {
        const lang = el("span", "plugin-stat");
        const dot = el("span", "plugin-lang-dot");
        dot.style.background = LANG_COLORS[p.language] || "var(--muted)";
        lang.appendChild(dot);
        lang.appendChild(el("span", null, p.language));
        meta.appendChild(lang);
      }

      const updated = timeAgo(p.pushedAt);
      if (updated) meta.appendChild(el("span", "plugin-stat plugin-updated", "updated " + updated));

      card.appendChild(meta);
      return card;
    }

    function matches(p, q) {
      if (!q) return true;
      const hay = [p.fullName, p.owner, p.name, p.description, p.language, ...(p.topics || [])]
        .filter(Boolean)
        .join(" ")
        .toLowerCase();
      return q.split(/\s+/).every((term) => hay.includes(term));
    }

    function sortPlugins(list, mode) {
      const by = [...list];
      const t = (v) => new Date(v || 0).getTime() || 0;
      if (mode === "recent") by.sort((a, b) => t(b.pushedAt) - t(a.pushedAt));
      else if (mode === "newest") by.sort((a, b) => t(b.createdAt) - t(a.createdAt));
      else if (mode === "name") by.sort((a, b) => (a.fullName || "").localeCompare(b.fullName || ""));
      else
        by.sort(
          (a, b) => (b.stars ?? 0) - (a.stars ?? 0) || t(b.pushedAt) - t(a.pushedAt),
        );
      return by;
    }

    function render() {
      const q = searchInput.value.trim().toLowerCase();
      const visible = sortPlugins(plugins.filter((p) => matches(p, q)), sortSelect.value);

      grid.replaceChildren();
      for (const p of visible) grid.appendChild(buildCard(p));

      if (visible.length === 0) {
        statusEl.textContent = q
          ? "No plugins match your search."
          : "No plugins are listed yet.";
        statusEl.hidden = false;
      } else {
        statusEl.hidden = true;
      }
    }

    function setMeta(generatedAt) {
      const parts = [];
      parts.push(plugins.length + (plugins.length === 1 ? " plugin" : " plugins"));
      const ago = timeAgo(generatedAt);
      if (ago) parts.push("updated " + ago);
      if (usingFallback) parts.push("preview data");
      metaEl.textContent = parts.join(" · ");
    }

    function apply(data) {
      plugins = Array.isArray(data && data.plugins) ? data.plugins : [];
      setMeta(data && data.generatedAt);
      render();
    }

    function showError() {
      plugins = [];
      metaEl.textContent = "";
      grid.replaceChildren();
      statusEl.textContent =
        "The plugin marketplace is warming up. Check back in a few minutes.";
      statusEl.hidden = false;
    }

    async function load() {
      // Render the server-seeded data immediately (live in prod and dev; fixture
      // only as a dev offline fallback).
      if (initialData) {
        usingFallback = initialIsFixture;
        apply(initialData);
      }
      // Refresh from the same-origin function in production for the freshest snapshot.
      if (apiUrl) {
        try {
          const res = await fetch(apiUrl, { headers: { accept: "application/json" } });
          if (!res.ok) throw new Error("status " + res.status);
          usingFallback = false;
          apply(await res.json());
        } catch (err) {
          if (!initialData) showError();
        }
      } else if (!initialData) {
        showError();
      }
    }

    searchInput.addEventListener("input", render);
    sortSelect.addEventListener("change", render);
    load();
  </script>

  <style is:global>
    .plugins-page {
      padding-bottom: 5rem;
    }

    /* Reuse .section only for max-width centering, not its 5rem padding + top divider. */
    .plugins-page .section {
      padding-block: 0;
      border-top: none;
    }

    .plugins-page .plugins-hero {
      padding-top: 3rem;
    }

    .plugins-hero h2 {
      margin: 0;
      color: var(--ink);
      font-family: var(--mono);
      font-weight: 400;
      letter-spacing: -0.04em;
      line-height: 1.05;
      font-size: clamp(2rem, 4vw, 3rem);
    }

    .plugins-lede {
      max-width: 640px;
      margin: 1.1rem 0 0;
      color: var(--ink-soft);
      font-size: clamp(1rem, 1.6vw, 1.15rem);
      line-height: 1.6;
    }

    .plugins-lede code,
    .plugins-trust code,
    .plugins-publish-card code {
      font-family: var(--mono);
      font-size: 0.85em;
      background: var(--bg-elevated);
      border: 1px solid var(--line);
      border-radius: var(--radius-sm);
      padding: 0.1em 0.35em;
      white-space: nowrap;
    }

    .plugins-trust {
      max-width: 640px;
      margin: 1.1rem 0 0;
      color: var(--muted);
      font-size: 0.85rem;
      line-height: 1.55;
    }

    .plugins-trust .status-dot {
      display: inline-block;
      margin-right: 0.4rem;
      vertical-align: middle;
    }

    .plugins-trust a {
      color: var(--accent);
      text-decoration: underline;
      text-underline-offset: 2px;
    }

    /* Controls */
    .plugins-page .plugins-controls {
      position: relative;
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      gap: 0.75rem;
      margin-top: 2.5rem;
      padding-bottom: 1.75rem;
    }

    /* Divider bound to the content box (padding box), so it aligns with the
       search row and the cards instead of bleeding past them. */
    .plugins-controls::after {
      content: "";
      position: absolute;
      left: 0;
      right: 0;
      bottom: 0;
      border-top: 1px solid var(--line);
    }

    .plugins-search-wrap {
      position: relative;
      flex: 1 1 18rem;
      display: flex;
      align-items: center;
    }

    .plugins-search-icon {
      position: absolute;
      left: 0.7rem;
      color: var(--muted-2);
      font-family: var(--mono);
      font-size: 0.9rem;
      pointer-events: none;
    }

    .plugins-search {
      width: 100%;
      padding: 0.6rem 0.8rem 0.6rem 1.7rem;
      background: var(--bg-elevated);
      border: 1px solid var(--line);
      border-radius: var(--radius-md);
      color: var(--ink);
      font-family: var(--mono);
      font-size: 0.85rem;
    }

    .plugins-search:focus {
      outline: none;
      border-color: var(--accent);
    }

    .plugins-sort-wrap {
      display: inline-flex;
      align-items: center;
      gap: 0.5rem;
    }

    .plugins-sort-label {
      color: var(--muted);
      font-family: var(--mono);
      font-size: 0.78rem;
      text-transform: lowercase;
      letter-spacing: 0.06em;
    }

    .plugins-sort {
      padding: 0.55rem 0.7rem;
      background: var(--bg-elevated);
      border: 1px solid var(--line);
      border-radius: var(--radius-md);
      color: var(--ink);
      font-family: var(--mono);
      font-size: 0.82rem;
      cursor: pointer;
    }

    .plugins-sort:focus {
      outline: none;
      border-color: var(--accent);
    }

    .plugins-meta {
      margin: 0;
      margin-left: auto;
      color: var(--muted);
      font-family: var(--mono);
      font-size: 0.78rem;
      letter-spacing: 0.04em;
    }

    /* Grid */
    .plugins-results {
      margin-top: 2rem;
    }

    .plugins-grid {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(20rem, 1fr));
      gap: 0.85rem;
    }

    .plugin-card {
      display: flex;
      flex-direction: column;
      gap: 0.7rem;
      padding: 1.25rem;
      background: var(--bg-elevated);
      border: 1px solid var(--line);
      border-radius: var(--radius-md);
      transition: border-color 0.12s ease, transform 0.12s ease;
      min-height: 8.5rem;
    }

    a.plugin-card:hover {
      border-color: var(--accent);
      transform: translateY(-2px);
    }

    .plugin-card-head {
      display: flex;
      align-items: flex-start;
      justify-content: space-between;
      gap: 0.5rem;
    }

    .plugin-title {
      font-family: var(--mono);
      font-size: 0.95rem;
      line-height: 1.3;
      word-break: break-word;
    }

    .plugin-owner {
      color: var(--muted);
    }

    .plugin-name {
      color: var(--ink);
      font-weight: 600;
    }

    .plugin-go {
      color: var(--muted-2);
      font-family: var(--mono);
      flex: 0 0 auto;
      transition: color 0.12s ease;
    }

    a.plugin-card:hover .plugin-go {
      color: var(--accent);
    }

    .plugin-desc {
      margin: 0;
      color: var(--ink-soft);
      font-size: 0.88rem;
      line-height: 1.5;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
      overflow: hidden;
    }

    .plugin-desc.is-empty {
      color: var(--muted-2);
      font-style: italic;
    }

    .plugin-meta-row {
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      gap: 0.9rem;
      margin-top: auto;
      color: var(--muted);
      font-family: var(--mono);
      font-size: 0.78rem;
    }

    .plugin-stat {
      display: inline-flex;
      align-items: center;
      gap: 0.35rem;
    }

    .plugin-star {
      color: var(--yellow, #d4a72c);
    }

    .plugin-lang-dot {
      width: 0.6rem;
      height: 0.6rem;
      border-radius: 50%;
      flex: 0 0 auto;
    }

    .plugin-updated {
      margin-left: auto;
      color: var(--muted-2);
    }

    .plugins-status {
      padding: 3rem 1rem;
      text-align: center;
      color: var(--muted);
      font-family: var(--mono);
      font-size: 0.85rem;
    }

    /* Publish */
    .plugins-publish {
      margin-top: 3.5rem;
    }

    .plugins-publish-card {
      padding: 2rem;
      background: var(--bg-elevated);
      border: 1px solid var(--line);
      border-radius: var(--radius-lg);
    }

    .plugins-publish-card h3 {
      margin: 0.25rem 0 0;
      color: var(--ink);
      font-family: var(--mono);
      font-weight: 400;
      font-size: 1.4rem;
      letter-spacing: -0.02em;
    }

    .plugins-publish-card p {
      max-width: 620px;
      margin: 0.8rem 0 0;
      color: var(--ink-soft);
      line-height: 1.6;
    }

    .plugins-publish-actions {
      display: flex;
      flex-wrap: wrap;
      gap: 0.6rem;
      margin-top: 1.5rem;
    }

    @media (max-width: 38rem) {
      .plugins-meta {
        margin-left: 0;
        width: 100%;
      }
    }
  </style>
</MarketingLayout>