@grove-dev/astro 0.18.0 → 0.19.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grove-dev/astro",
3
- "version": "0.18.0",
3
+ "version": "0.19.0",
4
4
  "type": "module",
5
5
  "description": "Astro integration + server view-models for Grove directories. UI ships from @grove-dev/registry, not from this package.",
6
6
  "license": "MIT",
@@ -51,7 +51,7 @@
51
51
  "sanitize-html": "^2.17.7",
52
52
  "shiki": "^1.29.2",
53
53
  "yaml": "^2.9.0",
54
- "@grove-dev/core": "0.18.0"
54
+ "@grove-dev/core": "0.19.0"
55
55
  },
56
56
  "peerDependencies": {
57
57
  "astro": "^6.0.0 || ^7.0.0"
@@ -475,3 +475,83 @@ export function getRecordContextModel(
475
475
 
476
476
  return { relations, relatedRecords, collectionMembership };
477
477
  }
478
+
479
+ // ── Collection tiles ────────────────────────────────────────────
480
+
481
+ /** One collection as a card: what the index and "related" rows render. */
482
+ export interface CollectionTile {
483
+ slug: string;
484
+ url: string;
485
+ title: string;
486
+ /** First sentence of the editorial introduction, else the description. */
487
+ takeaway: string;
488
+ /** True when a curator wrote a note for at least one entry. */
489
+ editorial: boolean;
490
+ kind: 'curated' | 'generated';
491
+ count: number;
492
+ countLabel: string;
493
+ /** Up to eight entries with an image, in collection order. */
494
+ faces: Array<{ title: string; avatarUrl?: string }>;
495
+ /** First entries, for "Includes …" lines and quick picks. */
496
+ examples: Array<{
497
+ slug: string;
498
+ title: string;
499
+ url: string;
500
+ note?: string;
501
+ avatarUrl?: string;
502
+ stars?: number;
503
+ }>;
504
+ /** ISO date of the last editorial review, when the collection has one. */
505
+ reviewedAt?: string;
506
+ isEmpty: boolean;
507
+ }
508
+
509
+ function firstSentence(text: string | undefined): string | undefined {
510
+ const clean = text?.trim().replace(/\s+/g, ' ');
511
+ if (!clean) return undefined;
512
+ const match = clean.match(/^.+?[.!?](?=\s|$)/);
513
+ return match ? match[0] : clean;
514
+ }
515
+
516
+ /**
517
+ * Cards for `collections`, in the order given. `countNoun` defaults to
518
+ * the site's blueprint labels.
519
+ */
520
+ export function getCollectionTiles(
521
+ collections: Collection[],
522
+ entries: CollectionEntry[],
523
+ site?: { blueprintConfig?: { labelSingular?: string; labelPlural?: string } },
524
+ ): CollectionTile[] {
525
+ const singular = site?.blueprintConfig?.labelSingular ?? 'item';
526
+ const plural = site?.blueprintConfig?.labelPlural ?? 'items';
527
+ return collections.map((collection) => {
528
+ const result = runCollection(collection, entries);
529
+ const count = result.entries.length;
530
+ return {
531
+ slug: collection.slug,
532
+ url: `/collections/${collection.slug}/`,
533
+ title: collection.title,
534
+ takeaway: firstSentence(collection.editorial?.introduction) ?? collection.description,
535
+ editorial: result.entries.some((entry) => Boolean(entry.note)),
536
+ kind: collection.kind,
537
+ count,
538
+ countLabel: `${count} ${count === 1 ? singular : plural}`,
539
+ faces: result.entries
540
+ .filter((entry) => entry.avatarUrl)
541
+ .slice(0, 8)
542
+ .map((entry) => ({ title: entry.title, avatarUrl: entry.avatarUrl })),
543
+ examples: result.entries.slice(0, 4).map((entry) => ({
544
+ slug: entry.slug,
545
+ title: entry.title,
546
+ url: entry.url,
547
+ ...(entry.note ? { note: entry.note } : {}),
548
+ ...(entry.avatarUrl ? { avatarUrl: entry.avatarUrl } : {}),
549
+ ...(entry.stars !== undefined ? { stars: entry.stars } : {}),
550
+ })),
551
+ ...(collection.editorial?.lastReviewedAt
552
+ ? { reviewedAt: collection.editorial.lastReviewedAt }
553
+ : {}),
554
+ isEmpty: result.isEmpty,
555
+ };
556
+ });
557
+ }
@@ -274,7 +274,8 @@ export const fullProjects: ProjectRecord[] = fullRecords.filter(
274
274
  // matches the elements the `grove-prose` CSS actually
275
275
  // styles (h1-h4, p, ul/ol/li, pre/code, blockquote, a).
276
276
  // Links are restricted to safe schemes and external links
277
- // are hardened to `rel="noopener noreferrer" target="_blank"`.
277
+ // open in a new tab with `rel="noopener"` — the referrer is kept so
278
+ // the linked project sees the directory in its analytics.
278
279
  // javascript: / data: URIs are blocked; event handlers,
279
280
  // iframes, and scripts are stripped.
280
281
  //
@@ -462,7 +463,7 @@ const ANCHOR_TRANSFORM = (tagName: string, attribs: Record<string, string>) => {
462
463
  const external = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i.test(href);
463
464
  return {
464
465
  tagName,
465
- attribs: external ? { ...attribs, rel: 'noopener noreferrer', target: '_blank' } : attribs,
466
+ attribs: external ? { ...attribs, rel: 'noopener', target: '_blank' } : attribs,
466
467
  };
467
468
  };
468
469
 
@@ -452,6 +452,36 @@ export function getDirectoryIndexModel(
452
452
  };
453
453
  }
454
454
 
455
+ /**
456
+ * Records grouped by `submittedBy`, most submissions first. Only visible
457
+ * records count. Each person's `id` is their lowercased login — the
458
+ * anchor a record page's "Submitted by @login" links to.
459
+ */
460
+ export function getSubmissionsBySubmitter(
461
+ site: DirectorySiteConfig,
462
+ ): Array<{ id: string; login: string; items: Array<{ slug: string; name: string; url: string }> }> {
463
+ const routeSlug = site.blueprintConfig?.routeSlug ?? 'projects';
464
+ const byLogin = new Map<
465
+ string,
466
+ { id: string; login: string; items: Array<{ slug: string; name: string; url: string }> }
467
+ >();
468
+ for (const record of fullItems) {
469
+ const login = (record as { submittedBy?: string }).submittedBy;
470
+ if (!login) continue;
471
+ const id = login.toLowerCase();
472
+ const entry = byLogin.get(id) ?? { id, login, items: [] };
473
+ entry.items.push({
474
+ slug: record.slug,
475
+ name: 'name' in record && record.name ? String(record.name) : record.slug,
476
+ url: `/${routeSlug}/${record.slug}/`,
477
+ });
478
+ byLogin.set(id, entry);
479
+ }
480
+ return [...byLogin.values()].sort(
481
+ (a, b) => b.items.length - a.items.length || a.login.localeCompare(b.login),
482
+ );
483
+ }
484
+
455
485
  export function getContributorsPageModel(site: DirectorySiteConfig) {
456
486
  const contributors = loadDirectoryContributors();
457
487
  // Render-time guard: even if a stale `data/generated/contributors.json`