@grove-dev/astro 0.17.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.17.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.17.0"
54
+ "@grove-dev/core": "0.19.0"
55
55
  },
56
56
  "peerDependencies": {
57
57
  "astro": "^6.0.0 || ^7.0.0"
@@ -1,8 +1,16 @@
1
- import type { Collection, CollectionEntry, CollectionSourceRecord } from '@grove-dev/core';
1
+ import type {
2
+ Collection,
3
+ CollectionEntry,
4
+ CollectionSourceRecord,
5
+ ListingIndexPolicy,
6
+ } from '@grove-dev/core';
2
7
  import {
8
+ collectionIndexable,
3
9
  collectionSchema,
4
10
  faqSchema,
5
11
  findRelated,
12
+ hasEditorialBody,
13
+ NOINDEX_FOLLOW,
6
14
  runCollection,
7
15
  toCollectionEntries,
8
16
  } from '@grove-dev/core';
@@ -96,6 +104,8 @@ export function getCollectionPageModel(
96
104
  url?: string;
97
105
  siteUrl?: string;
98
106
  blueprintConfig?: { labelPlural?: string };
107
+ /** `seo.collectionIndexPolicy` is read from here. */
108
+ seo?: { collectionIndexPolicy?: string };
99
109
  },
100
110
  ): CollectionPageModel {
101
111
  const result = runCollection(collection, entries);
@@ -141,6 +151,20 @@ export function getCollectionPageModel(
141
151
  // The curator's `seo.title` / `seo.description` overrides win
142
152
  // verbatim; the fallback pattern advertises the list size. A
143
153
  // collection marked `seo.index: false` renders with noindex.
154
+ // `seo.collectionIndexPolicy: 'editorial'` also noindexes (with
155
+ // `follow`) a non-empty collection that has no intro or body.
156
+ const excludedByPolicy =
157
+ collection.seo?.index !== false &&
158
+ !result.isEmpty &&
159
+ !collectionIndexable(
160
+ {
161
+ introduction: collection.editorial?.introduction,
162
+ hasBody: hasEditorialBody(collection.content),
163
+ seoIndex: collection.seo?.index,
164
+ entryCount: result.entries.length,
165
+ },
166
+ site?.seo?.collectionIndexPolicy as ListingIndexPolicy | undefined,
167
+ );
144
168
  const seo: PageSeo = {
145
169
  title:
146
170
  collection.seo?.title ??
@@ -151,7 +175,8 @@ export function getCollectionPageModel(
151
175
  jsonLd: jsonLd as unknown as Record<string, unknown>[],
152
176
  // An empty collection has nothing to rank for; it also stays out of
153
177
  // the sitemap (see `prepareDirectory`).
154
- noindex: collection.seo?.index === false || result.isEmpty,
178
+ noindex: collection.seo?.index === false || result.isEmpty || excludedByPolicy,
179
+ ...(excludedByPolicy ? { robots: NOINDEX_FOLLOW } : {}),
155
180
  };
156
181
  return {
157
182
  collection: {
@@ -450,3 +475,83 @@ export function getRecordContextModel(
450
475
 
451
476
  return { relations, relatedRecords, collectionMembership };
452
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
 
@@ -10,8 +10,10 @@ import type {
10
10
  IndexFilters,
11
11
  IndexProjectRecord,
12
12
  IndexRecord,
13
+ ListingIndexPolicy,
13
14
  ProjectRecord,
14
15
  ReadingMetrics,
16
+ RecordIndexPolicy,
15
17
  Resource,
16
18
  TocEntry,
17
19
  } from '@grove-dev/core';
@@ -33,13 +35,17 @@ import {
33
35
  hasAnyFilter,
34
36
  hrefForClearedFilters,
35
37
  hrefForFilters,
38
+ NOINDEX_FOLLOW,
36
39
  nameInitials,
37
40
  pagePathHref,
38
41
  paginate,
39
42
  projectStackIds,
40
43
  readContentFile,
41
44
  readingMetrics,
45
+ recordIndexable,
46
+ softwareApplicationSchema,
42
47
  statusDisplay,
48
+ taxonomyTermIndexable,
43
49
  totalPages,
44
50
  truncateWords,
45
51
  } from '@grove-dev/core';
@@ -66,6 +72,12 @@ import {
66
72
  titleCaseFirst,
67
73
  } from './seo.js';
68
74
 
75
+ export interface SiteIndexPolicy {
76
+ recordIndexPolicy?: string;
77
+ collectionIndexPolicy?: string;
78
+ taxonomyIndexPolicy?: string;
79
+ }
80
+
69
81
  export interface DirectorySiteConfig {
70
82
  name: string;
71
83
  tagline?: string;
@@ -83,6 +95,10 @@ export interface DirectorySiteConfig {
83
95
  analytics?: {
84
96
  googleAnalyticsId?: string;
85
97
  };
98
+ /** Index policy from `grove.config.ts` (`seo.*IndexPolicy`). Plain
99
+ * strings: `site-config.json` is a JSON import, and the values were
100
+ * already validated by the config schema. */
101
+ seo?: SiteIndexPolicy;
86
102
  footer?: {
87
103
  columns?: Array<{
88
104
  heading: string;
@@ -104,8 +120,8 @@ export interface DirectorySiteConfig {
104
120
  labelPlural?: string;
105
121
  };
106
122
  taxonomy?: {
107
- categories?: Array<{ id: string; name: string }>;
108
- stacks?: Array<{ id: string; name: string }>;
123
+ categories?: Array<{ id: string; name: string; description?: string }>;
124
+ stacks?: Array<{ id: string; name: string; description?: string }>;
109
125
  platforms?: Array<{ id: string; name: string }>;
110
126
  topics?: Array<{ id: string; name: string }>;
111
127
  licenses?: Array<{ id: string; name: string }>;
@@ -436,6 +452,36 @@ export function getDirectoryIndexModel(
436
452
  };
437
453
  }
438
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
+
439
485
  export function getContributorsPageModel(site: DirectorySiteConfig) {
440
486
  const contributors = loadDirectoryContributors();
441
487
  // Render-time guard: even if a stale `data/generated/contributors.json`
@@ -684,46 +730,39 @@ export function getRecordDetailModel(
684
730
 
685
731
  let recordLd: Record<string, unknown>;
686
732
  if (isProject && proj) {
687
- const sameAs = [repoUrl, homepageUrl].filter(Boolean);
688
- // schema.org `dateCreated` is when the *work* was created, so the
689
- // repository's own creation date is the honest answer. This used to
690
- // read `curation.reviewedAt` and published the review date as the
691
- // project's birthday — off by years on most records.
733
+ // Only verified fields (`SOFTWARE_APPLICATION_FIELDS`): nothing here
734
+ // is inferred. `dateCreated` is the repository's creation date — the
735
+ // work's own birthday, not the review date. Download links come only
736
+ // from channels a curator marked `verified: true`.
737
+ const owner = (github as { owner?: { login?: string; type?: string; html_url?: string } })
738
+ ?.owner;
692
739
  const dateCreated = github?.created_at ? String(github.created_at) : undefined;
693
- recordLd = {
694
- '@context': 'https://schema.org',
695
- '@type': 'SoftwareSourceCode',
696
- '@id': `${pageUrl}#record`,
740
+ recordLd = softwareApplicationSchema({
741
+ url: pageUrl,
697
742
  name,
698
- headline: name,
699
743
  description,
700
- url: pageUrl,
701
- codeRepository: repoUrl || undefined,
702
- sameAs: sameAs.length ? sameAs : undefined,
703
- programmingLanguage: language ?? undefined,
704
- license: licenseSpdx ?? undefined,
705
- applicationCategory: record.category || undefined,
706
- operatingSystem: platforms.length ? platforms.join(', ') : undefined,
707
- keywords: record.tags?.length ? record.tags.join(', ') : undefined,
708
- dateCreated: dateCreated ?? undefined,
709
- dateModified: pushedAt ?? dateCreated ?? undefined,
710
- interactionStatistic:
711
- stars > 0
712
- ? {
713
- '@type': 'InteractionCounter',
714
- interactionType: { '@type': 'LikeAction' },
715
- userInteractionCount: stars,
716
- }
717
- : undefined,
718
- author: ownerRepo
744
+ ...(repoUrl ? { repoUrl } : {}),
745
+ ...(homepageUrl ? { homepageUrl } : {}),
746
+ license: licenseSpdx,
747
+ platforms: platforms.map((id) => taxonomyLabel('platforms', id)),
748
+ ...(categoryLabel ? { category: categoryLabel } : {}),
749
+ downloadUrls: (proj.distribution?.channels ?? [])
750
+ .filter((channel) => channel.verified === true)
751
+ .map((channel) => channel.url),
752
+ programmingLanguage: language,
753
+ dateCreated,
754
+ dateModified: pushedAt ?? dateCreated,
755
+ ...(owner?.login && ownerRepo?.owner === owner.login
719
756
  ? {
720
- '@type': 'Organization',
721
- name: ownerRepo.owner,
722
- url: `https://github.com/${ownerRepo.owner}`,
757
+ owner: {
758
+ login: owner.login,
759
+ type: owner.type ?? null,
760
+ ...(owner.html_url ? { url: owner.html_url } : {}),
761
+ },
723
762
  }
724
- : undefined,
725
- isAccessibleForFree: true,
726
- };
763
+ : {}),
764
+ keywords: record.tags ?? [],
765
+ });
727
766
  } else if (record.kind === 'resource') {
728
767
  const schemaTypes: Record<string, string> = {
729
768
  article: 'Article',
@@ -744,7 +783,6 @@ export function getRecordDetailModel(
744
783
  author: record.author ? { '@type': 'Person', name: record.author } : undefined,
745
784
  datePublished: record.publishedAt || undefined,
746
785
  keywords: record.tags?.length ? record.tags.join(', ') : undefined,
747
- isAccessibleForFree: true,
748
786
  };
749
787
  } else {
750
788
  recordLd = {
@@ -781,12 +819,21 @@ export function getRecordDetailModel(
781
819
  { path: `${routeSlug}/${recordSlug}/`, name },
782
820
  ]),
783
821
  ];
822
+ // `seo.recordIndexPolicy`: a record without the editorial work the
823
+ // policy asks for still renders, but as `noindex,follow` — the same
824
+ // rule keeps it out of the sitemap (`prepareDirectory`).
825
+ const contentHtml = isProject ? getContentHtml(recordSlug) : null;
826
+ const indexable = recordIndexable(
827
+ { hasBody: Boolean(contentHtml), reviewed: record.curation?.reviewed === true },
828
+ site.seo?.recordIndexPolicy as RecordIndexPolicy | undefined,
829
+ );
784
830
  const seo: PageSeo = {
785
831
  title,
786
832
  description,
787
833
  image: ogPath('record', recordSlug),
788
834
  imageAlt: `${name} — ${site.name}`,
789
835
  jsonLd,
836
+ ...(indexable ? {} : { noindex: true, robots: NOINDEX_FOLLOW }),
790
837
  };
791
838
 
792
839
  return {
@@ -834,7 +881,7 @@ export function getRecordDetailModel(
834
881
  // components can render the category pill without each consumer
835
882
  // having to destructure `record.category` themselves.
836
883
  category: record.category,
837
- contentHtml: isProject ? getContentHtml(recordSlug) : null,
884
+ contentHtml,
838
885
  // Curated summary (Open Apps-written) takes priority over the
839
886
  // raw `description` (typically copied from GitHub). Fall back to
840
887
  // `description` when the curator has not written a summary yet.
@@ -1102,7 +1149,20 @@ export function getTaxonomyPageModel(
1102
1149
  ...(r.description ? { description: r.description } : {}),
1103
1150
  };
1104
1151
  });
1152
+ // `seo.taxonomyIndexPolicy` covers categories and stacks — the pages
1153
+ // a term's intro copy (`description` in data/taxonomy) is written for.
1154
+ // Licenses have no editorial copy and are not covered. An empty term
1155
+ // is left to the page, as before.
1156
+ const term = kind === 'licenses' ? undefined : site.taxonomy?.[kind]?.find((t) => t.id === id);
1157
+ const excludedByPolicy =
1158
+ kind !== 'licenses' &&
1159
+ count > 0 &&
1160
+ !taxonomyTermIndexable(
1161
+ { count, description: term?.description },
1162
+ site.seo?.taxonomyIndexPolicy as ListingIndexPolicy | undefined,
1163
+ );
1105
1164
  const seo: PageSeo = {
1165
+ ...(excludedByPolicy ? { noindex: true, robots: NOINDEX_FOLLOW } : {}),
1106
1166
  // `main` already names the site, so seoTitle appends nothing —
1107
1167
  // it still runs for the length/whitespace normalization.
1108
1168
  title: seoTitle(main, site.name),
package/src/server/seo.ts CHANGED
@@ -21,6 +21,10 @@ export interface PageSeo {
21
21
  imageAlt?: string;
22
22
  jsonLd?: Record<string, unknown>[];
23
23
  noindex?: boolean;
24
+ /** Exact robots meta value, when it differs from the layout's
25
+ * `noindex` default — `noindex,follow` for a page the index policy
26
+ * excludes (see `seo.*IndexPolicy`). Pass to BaseLayout's `robots`. */
27
+ robots?: string;
24
28
  }
25
29
 
26
30
  /** Google truncates titles around 60 chars; suffixing past ~65 only