@sarimarcus/content-sites-core 0.53.1 → 0.54.1

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 CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  All packages in the platform release in lockstep; entries are per release version.
4
4
 
5
+ ## 0.54.1 (2026-11-02)
6
+
7
+ - `interludes`: `relocateArticleFeature` no longer falls back to the carousel's section when no back-half section is free. It takes a display section with a slot at least two paragraphs from every block (preferring one without a carousel), then the same search over the whole article, so the card stops stacking on the affiliate carousel. Across the 530 articles with a feature card, those landing within a paragraph of another block drop from 79 to 1.
8
+
9
+ ## 0.54.0 (2026-11-02)
10
+
11
+ - `interludes`: new `relocateArticleFeature(sections, editorialMode)` and `pickFeatureParagraph(section)`, the build-time move of the `article-feature` card, now skipping sections that hold an affiliate carousel, inline image or interlude and keeping one paragraph of prose between the card and any other block and after it. The three article pages kept identical local copies that ignored carousels and images, so the card could land on the carousel's slot.
12
+
5
13
  ## 0.53.1 (2026-10-29)
6
14
 
7
15
  - Lockstep release, no change (SLA-3604).
@@ -114,3 +114,4 @@ export declare function createInterludeSchema(z: ZodBuilders, config: InterludeS
114
114
  afterParagraph: Zod.ZodNumber;
115
115
  }, Zod.z.core.$strip>], "type">;
116
116
  export { pickBandSlot } from './bandSlot.ts';
117
+ export { relocateArticleFeature, pickFeatureParagraph } from './relocateFeature.ts';
@@ -90,3 +90,4 @@ export function createInterludeSchema(z, config) {
90
90
  ]);
91
91
  }
92
92
  export { pickBandSlot } from "./bandSlot.js";
93
+ export { relocateArticleFeature, pickFeatureParagraph } from "./relocateFeature.js";
@@ -0,0 +1,16 @@
1
+ interface Block {
2
+ afterParagraph: number;
3
+ }
4
+ interface Section {
5
+ body?: string;
6
+ interludes?: ({
7
+ type: string;
8
+ } & Partial<Block>)[];
9
+ affiliateCarousels?: Block[];
10
+ inlineImages?: Block[];
11
+ }
12
+ /** The card's paragraph: the clear slot nearest the section's middle, else the middle clamped before the last paragraph. */
13
+ export declare function pickFeatureParagraph(section: Section): number;
14
+ /** Moves the one `article-feature` interlude to its display slot, clear of carousels, images and interludes. Shared with validate-articles.mjs. */
15
+ export declare function relocateArticleFeature<S extends Section>(sections: S[], editorialMode?: string): S[];
16
+ export {};
@@ -0,0 +1,59 @@
1
+ const paragraphsOf = (s) => (s.body ?? '').split(/\n{2,}/).filter(Boolean).length;
2
+ const occupied = (s) => [...(s.interludes ?? []), ...(s.affiliateCarousels ?? []), ...(s.inlineImages ?? [])].flatMap((b) => typeof b.afterParagraph === 'number' ? [b.afterParagraph] : []);
3
+ const isFree = (s) => !(s.interludes?.length || s.affiliateCarousels?.length || s.inlineImages?.length);
4
+ /** Slots at least two paragraphs from every block, so prose sits between; never the last paragraph of a multi-paragraph section. */
5
+ const clearSlots = (section) => {
6
+ const taken = occupied(section);
7
+ const last = Math.max(0, paragraphsOf(section) - 2);
8
+ return Array.from({ length: last + 1 }, (_, p) => p).filter((p) => taken.every((t) => Math.abs(t - p) >= 2));
9
+ };
10
+ /** The card's paragraph: the clear slot nearest the section's middle, else the middle clamped before the last paragraph. */
11
+ export function pickFeatureParagraph(section) {
12
+ const count = paragraphsOf(section);
13
+ const preferred = Math.min(Math.max(0, count - 1), Math.max(1, Math.floor(count / 2)));
14
+ const slots = clearSlots(section);
15
+ if (!slots.length)
16
+ return Math.min(preferred, Math.max(0, count - 2));
17
+ return slots.reduce((best, p) => (Math.abs(p - preferred) < Math.abs(best - preferred) ? p : best));
18
+ }
19
+ /** Moves the one `article-feature` interlude to its display slot, clear of carousels, images and interludes. Shared with validate-articles.mjs. */
20
+ export function relocateArticleFeature(sections, editorialMode) {
21
+ let extracted = null;
22
+ const stripped = sections.map((section) => ({
23
+ ...section,
24
+ interludes: (section.interludes ?? []).filter((il) => {
25
+ if (il.type === 'article-feature') {
26
+ extracted = il;
27
+ return false;
28
+ }
29
+ return true;
30
+ }),
31
+ }));
32
+ if (!extracted)
33
+ return sections;
34
+ const n = stripped.length;
35
+ const order = [];
36
+ if (editorialMode === 'discover') {
37
+ for (let i = Math.min(n - 1, Math.max(1, Math.floor(n * 0.4))); i < n; i++)
38
+ order.push(i);
39
+ }
40
+ else {
41
+ for (let i = n - 1; i >= Math.ceil(n / 2); i--)
42
+ order.push(i);
43
+ }
44
+ const everywhere = Array.from({ length: n }, (_, i) => n - 1 - i);
45
+ const clearAt = stripped.map((section) => clearSlots(section).length > 0);
46
+ const clear = (i) => clearAt[i];
47
+ const noCarousel = (i) => !stripped[i].affiliateCarousels?.length;
48
+ const noInterlude = (i) => !stripped[i].interludes.length;
49
+ const targetIdx = order.find((i) => isFree(stripped[i])) ??
50
+ order.find((i) => clear(i) && noCarousel(i)) ??
51
+ order.find(clear) ??
52
+ everywhere.find((i) => clear(i) && noCarousel(i)) ??
53
+ everywhere.find(clear) ??
54
+ order.find(noInterlude) ??
55
+ order[0] ??
56
+ n - 1;
57
+ const afterParagraph = pickFeatureParagraph(stripped[targetIdx]);
58
+ return stripped.map((section, i) => i !== targetIdx ? section : { ...section, interludes: [...section.interludes, { ...extracted, afterParagraph }] });
59
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sarimarcus/content-sites-core",
3
- "version": "0.53.1",
3
+ "version": "0.54.1",
4
4
  "description": "Non-visual utilities, Astro config builders and SEO schema assembly shared by the content sites.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -116,3 +116,4 @@ export function createInterludeSchema(z: ZodBuilders, config: InterludeSchemaCon
116
116
  }
117
117
 
118
118
  export { pickBandSlot } from './bandSlot.ts';
119
+ export { relocateArticleFeature, pickFeatureParagraph } from './relocateFeature.ts';
@@ -0,0 +1,68 @@
1
+ interface Block { afterParagraph: number }
2
+ interface Section {
3
+ body?: string;
4
+ interludes?: ({ type: string } & Partial<Block>)[];
5
+ affiliateCarousels?: Block[];
6
+ inlineImages?: Block[];
7
+ }
8
+
9
+ const paragraphsOf = (s: Section) => (s.body ?? '').split(/\n{2,}/).filter(Boolean).length;
10
+ const occupied = (s: Section) =>
11
+ [...(s.interludes ?? []), ...(s.affiliateCarousels ?? []), ...(s.inlineImages ?? [])].flatMap((b) =>
12
+ typeof b.afterParagraph === 'number' ? [b.afterParagraph] : [],
13
+ );
14
+ const isFree = (s: Section) => !(s.interludes?.length || s.affiliateCarousels?.length || s.inlineImages?.length);
15
+
16
+ /** Slots at least two paragraphs from every block, so prose sits between; never the last paragraph of a multi-paragraph section. */
17
+ const clearSlots = (section: Section): number[] => {
18
+ const taken = occupied(section);
19
+ const last = Math.max(0, paragraphsOf(section) - 2);
20
+ return Array.from({ length: last + 1 }, (_, p) => p).filter((p) => taken.every((t) => Math.abs(t - p) >= 2));
21
+ };
22
+
23
+ /** The card's paragraph: the clear slot nearest the section's middle, else the middle clamped before the last paragraph. */
24
+ export function pickFeatureParagraph(section: Section): number {
25
+ const count = paragraphsOf(section);
26
+ const preferred = Math.min(Math.max(0, count - 1), Math.max(1, Math.floor(count / 2)));
27
+ const slots = clearSlots(section);
28
+ if (!slots.length) return Math.min(preferred, Math.max(0, count - 2));
29
+ return slots.reduce((best, p) => (Math.abs(p - preferred) < Math.abs(best - preferred) ? p : best));
30
+ }
31
+
32
+ /** Moves the one `article-feature` interlude to its display slot, clear of carousels, images and interludes. Shared with validate-articles.mjs. */
33
+ export function relocateArticleFeature<S extends Section>(sections: S[], editorialMode?: string): S[] {
34
+ let extracted: ({ type: string } & Partial<Block>) | null = null;
35
+ const stripped = sections.map((section) => ({
36
+ ...section,
37
+ interludes: (section.interludes ?? []).filter((il) => {
38
+ if (il.type === 'article-feature') { extracted = il; return false; }
39
+ return true;
40
+ }),
41
+ }));
42
+ if (!extracted) return sections;
43
+ const n = stripped.length;
44
+ const order: number[] = [];
45
+ if (editorialMode === 'discover') {
46
+ for (let i = Math.min(n - 1, Math.max(1, Math.floor(n * 0.4))); i < n; i++) order.push(i);
47
+ } else {
48
+ for (let i = n - 1; i >= Math.ceil(n / 2); i--) order.push(i);
49
+ }
50
+ const everywhere = Array.from({ length: n }, (_, i) => n - 1 - i);
51
+ const clearAt = stripped.map((section) => clearSlots(section).length > 0);
52
+ const clear = (i: number) => clearAt[i];
53
+ const noCarousel = (i: number) => !stripped[i].affiliateCarousels?.length;
54
+ const noInterlude = (i: number) => !stripped[i].interludes.length;
55
+ const targetIdx =
56
+ order.find((i) => isFree(stripped[i])) ??
57
+ order.find((i) => clear(i) && noCarousel(i)) ??
58
+ order.find(clear) ??
59
+ everywhere.find((i) => clear(i) && noCarousel(i)) ??
60
+ everywhere.find(clear) ??
61
+ order.find(noInterlude) ??
62
+ order[0] ??
63
+ n - 1;
64
+ const afterParagraph = pickFeatureParagraph(stripped[targetIdx]);
65
+ return stripped.map((section, i) =>
66
+ i !== targetIdx ? section : { ...section, interludes: [...section.interludes, { ...extracted!, afterParagraph }] },
67
+ );
68
+ }