@grove-dev/astro 0.17.0 → 0.18.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 +2 -2
- package/src/server/collections.ts +27 -2
- package/src/server/models.ts +69 -39
- package/src/server/seo.ts +4 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grove-dev/astro",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.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.
|
|
54
|
+
"@grove-dev/core": "0.18.0"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
57
|
"astro": "^6.0.0 || ^7.0.0"
|
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
import type {
|
|
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: {
|
package/src/server/models.ts
CHANGED
|
@@ -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 }>;
|
|
@@ -684,46 +700,39 @@ export function getRecordDetailModel(
|
|
|
684
700
|
|
|
685
701
|
let recordLd: Record<string, unknown>;
|
|
686
702
|
if (isProject && proj) {
|
|
687
|
-
|
|
688
|
-
//
|
|
689
|
-
//
|
|
690
|
-
//
|
|
691
|
-
|
|
703
|
+
// Only verified fields (`SOFTWARE_APPLICATION_FIELDS`): nothing here
|
|
704
|
+
// is inferred. `dateCreated` is the repository's creation date — the
|
|
705
|
+
// work's own birthday, not the review date. Download links come only
|
|
706
|
+
// from channels a curator marked `verified: true`.
|
|
707
|
+
const owner = (github as { owner?: { login?: string; type?: string; html_url?: string } })
|
|
708
|
+
?.owner;
|
|
692
709
|
const dateCreated = github?.created_at ? String(github.created_at) : undefined;
|
|
693
|
-
recordLd = {
|
|
694
|
-
|
|
695
|
-
'@type': 'SoftwareSourceCode',
|
|
696
|
-
'@id': `${pageUrl}#record`,
|
|
710
|
+
recordLd = softwareApplicationSchema({
|
|
711
|
+
url: pageUrl,
|
|
697
712
|
name,
|
|
698
|
-
headline: name,
|
|
699
713
|
description,
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
? {
|
|
713
|
-
'@type': 'InteractionCounter',
|
|
714
|
-
interactionType: { '@type': 'LikeAction' },
|
|
715
|
-
userInteractionCount: stars,
|
|
716
|
-
}
|
|
717
|
-
: undefined,
|
|
718
|
-
author: ownerRepo
|
|
714
|
+
...(repoUrl ? { repoUrl } : {}),
|
|
715
|
+
...(homepageUrl ? { homepageUrl } : {}),
|
|
716
|
+
license: licenseSpdx,
|
|
717
|
+
platforms: platforms.map((id) => taxonomyLabel('platforms', id)),
|
|
718
|
+
...(categoryLabel ? { category: categoryLabel } : {}),
|
|
719
|
+
downloadUrls: (proj.distribution?.channels ?? [])
|
|
720
|
+
.filter((channel) => channel.verified === true)
|
|
721
|
+
.map((channel) => channel.url),
|
|
722
|
+
programmingLanguage: language,
|
|
723
|
+
dateCreated,
|
|
724
|
+
dateModified: pushedAt ?? dateCreated,
|
|
725
|
+
...(owner?.login && ownerRepo?.owner === owner.login
|
|
719
726
|
? {
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
727
|
+
owner: {
|
|
728
|
+
login: owner.login,
|
|
729
|
+
type: owner.type ?? null,
|
|
730
|
+
...(owner.html_url ? { url: owner.html_url } : {}),
|
|
731
|
+
},
|
|
723
732
|
}
|
|
724
|
-
:
|
|
725
|
-
|
|
726
|
-
};
|
|
733
|
+
: {}),
|
|
734
|
+
keywords: record.tags ?? [],
|
|
735
|
+
});
|
|
727
736
|
} else if (record.kind === 'resource') {
|
|
728
737
|
const schemaTypes: Record<string, string> = {
|
|
729
738
|
article: 'Article',
|
|
@@ -744,7 +753,6 @@ export function getRecordDetailModel(
|
|
|
744
753
|
author: record.author ? { '@type': 'Person', name: record.author } : undefined,
|
|
745
754
|
datePublished: record.publishedAt || undefined,
|
|
746
755
|
keywords: record.tags?.length ? record.tags.join(', ') : undefined,
|
|
747
|
-
isAccessibleForFree: true,
|
|
748
756
|
};
|
|
749
757
|
} else {
|
|
750
758
|
recordLd = {
|
|
@@ -781,12 +789,21 @@ export function getRecordDetailModel(
|
|
|
781
789
|
{ path: `${routeSlug}/${recordSlug}/`, name },
|
|
782
790
|
]),
|
|
783
791
|
];
|
|
792
|
+
// `seo.recordIndexPolicy`: a record without the editorial work the
|
|
793
|
+
// policy asks for still renders, but as `noindex,follow` — the same
|
|
794
|
+
// rule keeps it out of the sitemap (`prepareDirectory`).
|
|
795
|
+
const contentHtml = isProject ? getContentHtml(recordSlug) : null;
|
|
796
|
+
const indexable = recordIndexable(
|
|
797
|
+
{ hasBody: Boolean(contentHtml), reviewed: record.curation?.reviewed === true },
|
|
798
|
+
site.seo?.recordIndexPolicy as RecordIndexPolicy | undefined,
|
|
799
|
+
);
|
|
784
800
|
const seo: PageSeo = {
|
|
785
801
|
title,
|
|
786
802
|
description,
|
|
787
803
|
image: ogPath('record', recordSlug),
|
|
788
804
|
imageAlt: `${name} — ${site.name}`,
|
|
789
805
|
jsonLd,
|
|
806
|
+
...(indexable ? {} : { noindex: true, robots: NOINDEX_FOLLOW }),
|
|
790
807
|
};
|
|
791
808
|
|
|
792
809
|
return {
|
|
@@ -834,7 +851,7 @@ export function getRecordDetailModel(
|
|
|
834
851
|
// components can render the category pill without each consumer
|
|
835
852
|
// having to destructure `record.category` themselves.
|
|
836
853
|
category: record.category,
|
|
837
|
-
contentHtml
|
|
854
|
+
contentHtml,
|
|
838
855
|
// Curated summary (Open Apps-written) takes priority over the
|
|
839
856
|
// raw `description` (typically copied from GitHub). Fall back to
|
|
840
857
|
// `description` when the curator has not written a summary yet.
|
|
@@ -1102,7 +1119,20 @@ export function getTaxonomyPageModel(
|
|
|
1102
1119
|
...(r.description ? { description: r.description } : {}),
|
|
1103
1120
|
};
|
|
1104
1121
|
});
|
|
1122
|
+
// `seo.taxonomyIndexPolicy` covers categories and stacks — the pages
|
|
1123
|
+
// a term's intro copy (`description` in data/taxonomy) is written for.
|
|
1124
|
+
// Licenses have no editorial copy and are not covered. An empty term
|
|
1125
|
+
// is left to the page, as before.
|
|
1126
|
+
const term = kind === 'licenses' ? undefined : site.taxonomy?.[kind]?.find((t) => t.id === id);
|
|
1127
|
+
const excludedByPolicy =
|
|
1128
|
+
kind !== 'licenses' &&
|
|
1129
|
+
count > 0 &&
|
|
1130
|
+
!taxonomyTermIndexable(
|
|
1131
|
+
{ count, description: term?.description },
|
|
1132
|
+
site.seo?.taxonomyIndexPolicy as ListingIndexPolicy | undefined,
|
|
1133
|
+
);
|
|
1105
1134
|
const seo: PageSeo = {
|
|
1135
|
+
...(excludedByPolicy ? { noindex: true, robots: NOINDEX_FOLLOW } : {}),
|
|
1106
1136
|
// `main` already names the site, so seoTitle appends nothing —
|
|
1107
1137
|
// it still runs for the length/whitespace normalization.
|
|
1108
1138
|
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
|