@sarimarcus/content-sites-core 0.34.2 → 0.35.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/CHANGELOG.md +4 -0
- package/dist/url/index.d.ts +2 -0
- package/dist/url/index.js +1 -0
- package/dist/url/relatedZone.d.ts +53 -0
- package/dist/url/relatedZone.js +55 -0
- package/package.json +1 -1
- package/src/url/index.ts +2 -0
- package/src/url/relatedZone.ts +82 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
All packages in the platform release in lockstep; entries are per release version.
|
|
4
4
|
|
|
5
|
+
## 0.35.0 (2026-10-13)
|
|
6
|
+
|
|
7
|
+
- `url`: added `closerHeading`, `featuredInGuides(collectionOf, type, slug, guides, limit?)` and `buildTakenHrefs(sources, basePath)`, the related-zone helpers both tourism sites kept as copies. The type→collection map and the base path are now arguments instead of site imports (SLA-3042).
|
|
8
|
+
|
|
5
9
|
## 0.34.2 (2026-10-13)
|
|
6
10
|
|
|
7
11
|
- No changes; lockstep release with ui (SLA-3072).
|
package/dist/url/index.d.ts
CHANGED
|
@@ -9,3 +9,5 @@ export { DEFAULT_ROUTES, routePath } from './routes.ts';
|
|
|
9
9
|
export type { RouteKind, SiteRoutes } from './routes.ts';
|
|
10
10
|
export { outboundClassifier, outboundHostKey, applyOutboundRel } from './outbound.ts';
|
|
11
11
|
export type { OutboundDomainStore } from './outbound.ts';
|
|
12
|
+
export { RELATED_ZONE_ROLES, closerHeading, featuredInGuides, buildTakenHrefs } from './relatedZone.ts';
|
|
13
|
+
export type { RelatedZoneRole, TakenHrefSources } from './relatedZone.ts';
|
package/dist/url/index.js
CHANGED
|
@@ -7,3 +7,4 @@ export { articleFeedItem } from "./feed.js";
|
|
|
7
7
|
export { pageTypeOf } from "./pageType.js";
|
|
8
8
|
export { DEFAULT_ROUTES, routePath } from "./routes.js";
|
|
9
9
|
export { outboundClassifier, outboundHostKey, applyOutboundRel } from "./outbound.js";
|
|
10
|
+
export { RELATED_ZONE_ROLES, closerHeading, featuredInGuides, buildTakenHrefs } from "./relatedZone.js";
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* relatedZone — the shared half of an entity page's related-content tail.
|
|
3
|
+
*
|
|
4
|
+
* The tail has exactly one heading role, `closer`; its label is contextual and
|
|
5
|
+
* built through closerHeading(), never inlined. featuredInGuides() derives the
|
|
6
|
+
* "which guides feature this item" edge, which no `relatedContent` ref can
|
|
7
|
+
* express. buildTakenHrefs() builds the per-page Set of hrefs the closer must
|
|
8
|
+
* not repeat, in the one normalizeHref() form dedupRelated() compares against.
|
|
9
|
+
*
|
|
10
|
+
* Site-specific facts are passed in, never imported: the type→collection map
|
|
11
|
+
* (`collectionOf`) and the base path (`basePath`).
|
|
12
|
+
*/
|
|
13
|
+
/** The only heading role an entity-page tail may render. */
|
|
14
|
+
export declare const RELATED_ZONE_ROLES: readonly ["closer"];
|
|
15
|
+
export type RelatedZoneRole = (typeof RELATED_ZONE_ROLES)[number];
|
|
16
|
+
/** `context` is whatever frames the page best: the entity name, its neighborhood name, or a collection noun. */
|
|
17
|
+
export declare function closerHeading(context: string): string;
|
|
18
|
+
/** A guides-collection entry, as getCollection('guides') yields it. */
|
|
19
|
+
type GuideEntry = {
|
|
20
|
+
id: string;
|
|
21
|
+
data: {
|
|
22
|
+
items?: readonly {
|
|
23
|
+
type: string;
|
|
24
|
+
slug: string;
|
|
25
|
+
rank?: number;
|
|
26
|
+
order?: number;
|
|
27
|
+
}[];
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* The guides whose `items[]` feature this entity, best-placement first.
|
|
32
|
+
*
|
|
33
|
+
* Ordered by the entity's own placement inside each guide, then by guide id, so
|
|
34
|
+
* the top `limit` is stable between builds. A guide keys its items on `rank` or
|
|
35
|
+
* `order`; reading only `rank` would send an `order`-keyed guide to the end.
|
|
36
|
+
*
|
|
37
|
+
* `collectionOf` maps the entity's singular target type to the plural
|
|
38
|
+
* collection name guide items store ('activity' → 'activities').
|
|
39
|
+
*/
|
|
40
|
+
export declare function featuredInGuides<G extends GuideEntry>(collectionOf: (type: string) => string, type: string, slug: string, guides: readonly G[], limit?: number): G[];
|
|
41
|
+
export interface TakenHrefSources {
|
|
42
|
+
/** Rendered HTML chunks whose <a href>s are already on the page — same input shape as extractProseHrefs. */
|
|
43
|
+
proseHtml?: readonly (string | undefined | null)[];
|
|
44
|
+
/** Any other hrefs already rendered as cards/links. url()-applied or bare: both normalize to the same member. */
|
|
45
|
+
hrefs?: readonly string[];
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* One Set<string> of everything the page already links, in normalizeHref()
|
|
49
|
+
* form: hand it to RelatedBlock's `excludeHrefs`. External and pure-anchor
|
|
50
|
+
* hrefs normalize to null and are skipped.
|
|
51
|
+
*/
|
|
52
|
+
export declare function buildTakenHrefs({ proseHtml, hrefs }: TakenHrefSources, basePath: string): Set<string>;
|
|
53
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* relatedZone — the shared half of an entity page's related-content tail.
|
|
3
|
+
*
|
|
4
|
+
* The tail has exactly one heading role, `closer`; its label is contextual and
|
|
5
|
+
* built through closerHeading(), never inlined. featuredInGuides() derives the
|
|
6
|
+
* "which guides feature this item" edge, which no `relatedContent` ref can
|
|
7
|
+
* express. buildTakenHrefs() builds the per-page Set of hrefs the closer must
|
|
8
|
+
* not repeat, in the one normalizeHref() form dedupRelated() compares against.
|
|
9
|
+
*
|
|
10
|
+
* Site-specific facts are passed in, never imported: the type→collection map
|
|
11
|
+
* (`collectionOf`) and the base path (`basePath`).
|
|
12
|
+
*/
|
|
13
|
+
import { extractProseHrefs, normalizeHref } from "./relatedDedup.js";
|
|
14
|
+
/** The only heading role an entity-page tail may render. */
|
|
15
|
+
export const RELATED_ZONE_ROLES = ['closer'];
|
|
16
|
+
/** `context` is whatever frames the page best: the entity name, its neighborhood name, or a collection noun. */
|
|
17
|
+
export function closerHeading(context) {
|
|
18
|
+
return `Keep exploring ${context}`;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The guides whose `items[]` feature this entity, best-placement first.
|
|
22
|
+
*
|
|
23
|
+
* Ordered by the entity's own placement inside each guide, then by guide id, so
|
|
24
|
+
* the top `limit` is stable between builds. A guide keys its items on `rank` or
|
|
25
|
+
* `order`; reading only `rank` would send an `order`-keyed guide to the end.
|
|
26
|
+
*
|
|
27
|
+
* `collectionOf` maps the entity's singular target type to the plural
|
|
28
|
+
* collection name guide items store ('activity' → 'activities').
|
|
29
|
+
*/
|
|
30
|
+
export function featuredInGuides(collectionOf, type, slug, guides, limit = 3) {
|
|
31
|
+
const collection = collectionOf(type);
|
|
32
|
+
const rankOf = (g) => {
|
|
33
|
+
const item = g.data.items?.find((i) => i.type === collection && i.slug === slug);
|
|
34
|
+
return item?.rank ?? item?.order ?? Number.POSITIVE_INFINITY;
|
|
35
|
+
};
|
|
36
|
+
return guides
|
|
37
|
+
.filter((g) => g.data.items?.some((i) => i.type === collection && i.slug === slug))
|
|
38
|
+
.sort((a, b) => rankOf(a) - rankOf(b) || a.id.localeCompare(b.id))
|
|
39
|
+
.slice(0, limit);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* One Set<string> of everything the page already links, in normalizeHref()
|
|
43
|
+
* form: hand it to RelatedBlock's `excludeHrefs`. External and pure-anchor
|
|
44
|
+
* hrefs normalize to null and are skipped.
|
|
45
|
+
*/
|
|
46
|
+
export function buildTakenHrefs({ proseHtml = [], hrefs = [] }, basePath) {
|
|
47
|
+
const base = basePath.replace(/\/+$/, '');
|
|
48
|
+
const taken = extractProseHrefs([...proseHtml], base);
|
|
49
|
+
for (const href of hrefs) {
|
|
50
|
+
const n = normalizeHref(href, base);
|
|
51
|
+
if (n)
|
|
52
|
+
taken.add(n);
|
|
53
|
+
}
|
|
54
|
+
return taken;
|
|
55
|
+
}
|
package/package.json
CHANGED
package/src/url/index.ts
CHANGED
|
@@ -10,3 +10,5 @@ export { DEFAULT_ROUTES, routePath } from './routes.ts';
|
|
|
10
10
|
export type { RouteKind, SiteRoutes } from './routes.ts';
|
|
11
11
|
export { outboundClassifier, outboundHostKey, applyOutboundRel } from './outbound.ts';
|
|
12
12
|
export type { OutboundDomainStore } from './outbound.ts';
|
|
13
|
+
export { RELATED_ZONE_ROLES, closerHeading, featuredInGuides, buildTakenHrefs } from './relatedZone.ts';
|
|
14
|
+
export type { RelatedZoneRole, TakenHrefSources } from './relatedZone.ts';
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* relatedZone — the shared half of an entity page's related-content tail.
|
|
3
|
+
*
|
|
4
|
+
* The tail has exactly one heading role, `closer`; its label is contextual and
|
|
5
|
+
* built through closerHeading(), never inlined. featuredInGuides() derives the
|
|
6
|
+
* "which guides feature this item" edge, which no `relatedContent` ref can
|
|
7
|
+
* express. buildTakenHrefs() builds the per-page Set of hrefs the closer must
|
|
8
|
+
* not repeat, in the one normalizeHref() form dedupRelated() compares against.
|
|
9
|
+
*
|
|
10
|
+
* Site-specific facts are passed in, never imported: the type→collection map
|
|
11
|
+
* (`collectionOf`) and the base path (`basePath`).
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { extractProseHrefs, normalizeHref } from './relatedDedup.ts';
|
|
15
|
+
|
|
16
|
+
/** The only heading role an entity-page tail may render. */
|
|
17
|
+
export const RELATED_ZONE_ROLES = ['closer'] as const;
|
|
18
|
+
export type RelatedZoneRole = (typeof RELATED_ZONE_ROLES)[number];
|
|
19
|
+
|
|
20
|
+
/** `context` is whatever frames the page best: the entity name, its neighborhood name, or a collection noun. */
|
|
21
|
+
export function closerHeading(context: string): string {
|
|
22
|
+
return `Keep exploring ${context}`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** A guides-collection entry, as getCollection('guides') yields it. */
|
|
26
|
+
type GuideEntry = {
|
|
27
|
+
id: string;
|
|
28
|
+
data: { items?: readonly { type: string; slug: string; rank?: number; order?: number }[] };
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The guides whose `items[]` feature this entity, best-placement first.
|
|
33
|
+
*
|
|
34
|
+
* Ordered by the entity's own placement inside each guide, then by guide id, so
|
|
35
|
+
* the top `limit` is stable between builds. A guide keys its items on `rank` or
|
|
36
|
+
* `order`; reading only `rank` would send an `order`-keyed guide to the end.
|
|
37
|
+
*
|
|
38
|
+
* `collectionOf` maps the entity's singular target type to the plural
|
|
39
|
+
* collection name guide items store ('activity' → 'activities').
|
|
40
|
+
*/
|
|
41
|
+
export function featuredInGuides<G extends GuideEntry>(
|
|
42
|
+
collectionOf: (type: string) => string,
|
|
43
|
+
type: string,
|
|
44
|
+
slug: string,
|
|
45
|
+
guides: readonly G[],
|
|
46
|
+
limit = 3,
|
|
47
|
+
): G[] {
|
|
48
|
+
const collection = collectionOf(type);
|
|
49
|
+
const rankOf = (g: G) => {
|
|
50
|
+
const item = g.data.items?.find((i) => i.type === collection && i.slug === slug);
|
|
51
|
+
return item?.rank ?? item?.order ?? Number.POSITIVE_INFINITY;
|
|
52
|
+
};
|
|
53
|
+
return guides
|
|
54
|
+
.filter((g) => g.data.items?.some((i) => i.type === collection && i.slug === slug))
|
|
55
|
+
.sort((a, b) => rankOf(a) - rankOf(b) || a.id.localeCompare(b.id))
|
|
56
|
+
.slice(0, limit);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface TakenHrefSources {
|
|
60
|
+
/** Rendered HTML chunks whose <a href>s are already on the page — same input shape as extractProseHrefs. */
|
|
61
|
+
proseHtml?: readonly (string | undefined | null)[];
|
|
62
|
+
/** Any other hrefs already rendered as cards/links. url()-applied or bare: both normalize to the same member. */
|
|
63
|
+
hrefs?: readonly string[];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* One Set<string> of everything the page already links, in normalizeHref()
|
|
68
|
+
* form: hand it to RelatedBlock's `excludeHrefs`. External and pure-anchor
|
|
69
|
+
* hrefs normalize to null and are skipped.
|
|
70
|
+
*/
|
|
71
|
+
export function buildTakenHrefs(
|
|
72
|
+
{ proseHtml = [], hrefs = [] }: TakenHrefSources,
|
|
73
|
+
basePath: string,
|
|
74
|
+
): Set<string> {
|
|
75
|
+
const base = basePath.replace(/\/+$/, '');
|
|
76
|
+
const taken = extractProseHrefs([...proseHtml], base);
|
|
77
|
+
for (const href of hrefs) {
|
|
78
|
+
const n = normalizeHref(href, base);
|
|
79
|
+
if (n) taken.add(n);
|
|
80
|
+
}
|
|
81
|
+
return taken;
|
|
82
|
+
}
|