@grove-dev/astro 1.2.0 → 1.3.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 +3 -3
- package/src/server/collections.ts +9 -2
- package/src/server/models.ts +13 -7
- package/src/server/seo.ts +29 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grove-dev/astro",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.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",
|
|
@@ -50,10 +50,10 @@
|
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"marked": "^18.0.0",
|
|
53
|
-
"sanitize-html": "^2.
|
|
53
|
+
"sanitize-html": "^2.18.0",
|
|
54
54
|
"shiki": "^4.4.3",
|
|
55
55
|
"yaml": "^2.9.0",
|
|
56
|
-
"@grove-dev/core": "1.
|
|
56
|
+
"@grove-dev/core": "1.3.0"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
59
|
"astro": "^6.0.0 || ^7.0.0"
|
|
@@ -14,7 +14,14 @@ import {
|
|
|
14
14
|
runCollection,
|
|
15
15
|
toCollectionEntries,
|
|
16
16
|
} from '@grove-dev/core';
|
|
17
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
absoluteUrl,
|
|
19
|
+
ogPath,
|
|
20
|
+
type PageSeo,
|
|
21
|
+
seoDescription,
|
|
22
|
+
seoTitle,
|
|
23
|
+
titleCaseFirst,
|
|
24
|
+
} from './seo.js';
|
|
18
25
|
|
|
19
26
|
// Collection YAML loading lives in @grove-dev/core (it also feeds the
|
|
20
27
|
// sitemap and OG-image pipelines there); re-exported for page code.
|
|
@@ -221,7 +228,7 @@ export function getCollectionIndexModel(
|
|
|
221
228
|
const siteUrl = (site.siteUrl ?? site.url ?? 'https://example.com').replace(/\/$/, '');
|
|
222
229
|
const siteName = site.name ?? '';
|
|
223
230
|
const plural = site.blueprintConfig?.labelPlural ?? 'items';
|
|
224
|
-
const title = seoTitle(
|
|
231
|
+
const title = seoTitle(`Curated Collections of ${titleCaseFirst(plural)}`, siteName);
|
|
225
232
|
const description = seoDescription(
|
|
226
233
|
undefined,
|
|
227
234
|
`${rows.length} curated and generated collections of ${plural} on ${siteName || 'this site'} — hand-picked lists kept in sync with the source files.`,
|
package/src/server/models.ts
CHANGED
|
@@ -406,7 +406,9 @@ export function getDirectoryIndexModel(
|
|
|
406
406
|
};
|
|
407
407
|
});
|
|
408
408
|
const seo: PageSeo = {
|
|
409
|
-
|
|
409
|
+
// The count tells a search result what the page holds; "Browse
|
|
410
|
+
// Apps" alone says nothing a snippet can use.
|
|
411
|
+
title: seoTitle(`Browse ${items.length} ${pluralTitle}`, siteName),
|
|
410
412
|
// Build the page-aware description BEFORE seoDescription truncates,
|
|
411
413
|
// so the page suffix fits inside the 160-char cap rather than
|
|
412
414
|
// pushing the sentence over and getting clipped mid-word.
|
|
@@ -509,7 +511,7 @@ export function getContributorsPageModel(site: DirectorySiteConfig) {
|
|
|
509
511
|
);
|
|
510
512
|
const repo = site.repoUrl?.replace(/\/$/, '');
|
|
511
513
|
const siteUrl = siteUrlOf(site);
|
|
512
|
-
const title = seoTitle(
|
|
514
|
+
const title = seoTitle(`Contributors to ${site.name}`, site.name);
|
|
513
515
|
const description = seoDescription(
|
|
514
516
|
undefined,
|
|
515
517
|
sorted.length > 0
|
|
@@ -815,14 +817,15 @@ export function getRecordDetailModel(
|
|
|
815
817
|
|
|
816
818
|
// "<Name> — <descriptor> | <Site>": the descriptor gives the search
|
|
817
819
|
// snippet a reason to exist beyond the bare project name. A curator's
|
|
818
|
-
// `record.seo.title` (when set)
|
|
819
|
-
//
|
|
820
|
+
// `record.seo.title` (when set) replaces the main part; the site
|
|
821
|
+
// suffix is still added when it fits, so every page carries the brand.
|
|
820
822
|
const descriptor = recordSeoDescriptor({
|
|
821
823
|
summary: record.summary,
|
|
824
|
+
description: record.description,
|
|
822
825
|
...(categoryLabel ? { categoryLabel } : {}),
|
|
823
826
|
singular,
|
|
824
827
|
});
|
|
825
|
-
const title = record.seo?.title
|
|
828
|
+
const title = seoTitle(record.seo?.title?.trim() || `${name} — ${descriptor}`, site.name);
|
|
826
829
|
const pluralTitle = titleCaseFirst(site.blueprintConfig?.labelPlural ?? itemLabelPlural());
|
|
827
830
|
const jsonLd = [
|
|
828
831
|
recordLd,
|
|
@@ -1224,7 +1227,10 @@ export function getTaxonomyIndexSeo(
|
|
|
1224
1227
|
.map((entry) => entry.name)
|
|
1225
1228
|
.join(', ');
|
|
1226
1229
|
const siteUrl = siteUrlOf(site);
|
|
1227
|
-
const title = seoTitle(
|
|
1230
|
+
const title = seoTitle(
|
|
1231
|
+
`${titleCaseFirst(plural)} by ${kind === 'categories' ? 'Category' : 'Stack'}`,
|
|
1232
|
+
site.name,
|
|
1233
|
+
);
|
|
1228
1234
|
const description = seoDescription(
|
|
1229
1235
|
undefined,
|
|
1230
1236
|
kind === 'categories'
|
|
@@ -1258,7 +1264,7 @@ export function getTaxonomyIndexSeo(
|
|
|
1258
1264
|
*/
|
|
1259
1265
|
export function getAboutPageSeo(site: DirectorySiteConfig): PageSeo {
|
|
1260
1266
|
const siteUrl = siteUrlOf(site);
|
|
1261
|
-
const title = seoTitle(
|
|
1267
|
+
const title = seoTitle(`About ${site.name}`, site.name);
|
|
1262
1268
|
const description = seoDescription(
|
|
1263
1269
|
undefined,
|
|
1264
1270
|
`About ${site.name}: ${site.tagline ?? site.description ?? 'a file-first knowledge site.'}`,
|
package/src/server/seo.ts
CHANGED
|
@@ -47,13 +47,23 @@ export function seoTitle(main: string, siteName: string): string {
|
|
|
47
47
|
return suffixed.length <= TITLE_SUFFIX_MAX ? suffixed : cleaned;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
/** A cut on a sentence end must keep at least this much of the text. */
|
|
51
|
+
const SENTENCE_CUT_MIN = 90;
|
|
52
|
+
|
|
50
53
|
/**
|
|
51
54
|
* Normalize a meta description: prefer `raw`, fall back, collapse
|
|
52
|
-
* whitespace, and
|
|
55
|
+
* whitespace, and keep it within ~160 chars. Too-long text ends on its
|
|
56
|
+
* last full sentence that fits; only when no sentence ends late enough
|
|
57
|
+
* is it cut on a word boundary with an ellipsis — a snippet that stops
|
|
58
|
+
* mid-thought reads as broken.
|
|
53
59
|
*/
|
|
54
60
|
export function seoDescription(raw: string | undefined, fallback: string): string {
|
|
55
61
|
const source = (raw ?? '').replace(/\s+/g, ' ').trim() || fallback.replace(/\s+/g, ' ').trim();
|
|
56
62
|
if (source.length <= DESCRIPTION_MAX) return source;
|
|
63
|
+
const sentenceEnd = Math.max(
|
|
64
|
+
...['. ', '! ', '? '].map((end) => source.lastIndexOf(end, DESCRIPTION_MAX - 1)),
|
|
65
|
+
);
|
|
66
|
+
if (sentenceEnd + 1 >= SENTENCE_CUT_MIN) return source.slice(0, sentenceEnd + 1);
|
|
57
67
|
const cut = source.slice(0, DESCRIPTION_MAX - 1);
|
|
58
68
|
const lastSpace = cut.lastIndexOf(' ');
|
|
59
69
|
return `${(lastSpace > 80 ? cut.slice(0, lastSpace) : cut).replace(/[,;:\s]+$/, '')}…`;
|
|
@@ -67,23 +77,32 @@ export function titleCaseFirst(value: string): string {
|
|
|
67
77
|
/**
|
|
68
78
|
* Short record descriptor for `<Name> — <descriptor> | <Site>` titles.
|
|
69
79
|
* Prefers the curator-written summary's first clause when it is short
|
|
70
|
-
* enough to fit a title; otherwise falls back
|
|
71
|
-
*
|
|
80
|
+
* enough to fit a title, then the description's; otherwise falls back
|
|
81
|
+
* to the category label, or the item noun when there is none.
|
|
72
82
|
*/
|
|
73
83
|
export function recordSeoDescriptor(input: {
|
|
74
84
|
summary?: string;
|
|
85
|
+
description?: string;
|
|
75
86
|
categoryLabel?: string;
|
|
76
87
|
singular: string;
|
|
77
88
|
}): string {
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
89
|
+
const firstClause = (text?: string) =>
|
|
90
|
+
(text ?? '')
|
|
91
|
+
.split(/[.!?\n]|\s[—–]\s/)[0]
|
|
92
|
+
?.replace(/\s+/g, ' ')
|
|
93
|
+
.trim();
|
|
94
|
+
// The short card description often has a usable first clause when the
|
|
95
|
+
// summary's runs long.
|
|
96
|
+
for (const clause of [firstClause(input.summary), firstClause(input.description)]) {
|
|
97
|
+
if (clause && clause.length <= 45) return clause;
|
|
98
|
+
}
|
|
99
|
+
// Last resort: the category on its own ("Flip — Games"), never glued
|
|
100
|
+
// to the item noun — "Games app" and "Open-source Games app" read as
|
|
101
|
+
// broken, and not every directory lists open-source software.
|
|
83
102
|
const category = input.categoryLabel?.trim();
|
|
84
103
|
return category && category.toLowerCase() !== 'uncategorized'
|
|
85
|
-
?
|
|
86
|
-
:
|
|
104
|
+
? category
|
|
105
|
+
: titleCaseFirst(input.singular);
|
|
87
106
|
}
|
|
88
107
|
|
|
89
108
|
export type OgKind =
|