@sarimarcus/content-sites-core 0.53.1 → 0.54.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 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.54.0 (2026-11-02)
6
+
7
+ - `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.
8
+
5
9
  ## 0.53.1 (2026-10-29)
6
10
 
7
11
  - 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,26 @@
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
+ /**
13
+ * Paragraph the feature card goes after: the section's middle, moved to the nearest slot at least two
14
+ * paragraphs from any block already in the section (one paragraph of prose between), and never the last
15
+ * paragraph when the section has more than one, so prose always follows the card.
16
+ */
17
+ export declare function pickFeatureParagraph(section: Section): number;
18
+ /**
19
+ * Moves the single `article-feature` interlude to its display slot: the last free back-half section
20
+ * (or ~40% depth on a Discover piece). A section is free when it holds no interlude, affiliate carousel
21
+ * or inline image; with none free it falls back to a section without an interlude, then to the last
22
+ * section, and the paragraph pick keeps the card clear of the blocks there. Shared by every site's
23
+ * article page and by scripts/validate-articles.mjs, so the gate sees what the reader sees.
24
+ */
25
+ export declare function relocateArticleFeature<S extends Section>(sections: S[], editorialMode?: string): S[];
26
+ export {};
@@ -0,0 +1,57 @@
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
+ /**
5
+ * Paragraph the feature card goes after: the section's middle, moved to the nearest slot at least two
6
+ * paragraphs from any block already in the section (one paragraph of prose between), and never the last
7
+ * paragraph when the section has more than one, so prose always follows the card.
8
+ */
9
+ export function pickFeatureParagraph(section) {
10
+ const count = paragraphsOf(section);
11
+ const last = Math.max(0, count - 2);
12
+ const preferred = Math.min(Math.max(0, count - 1), Math.max(1, Math.floor(count / 2)));
13
+ const taken = occupied(section);
14
+ const ok = (p) => taken.every((t) => Math.abs(t - p) >= 2);
15
+ let best = -1;
16
+ for (let p = 0; p <= last; p++) {
17
+ if (ok(p) && (best < 0 || Math.abs(p - preferred) < Math.abs(best - preferred)))
18
+ best = p;
19
+ }
20
+ return best >= 0 ? best : Math.min(preferred, last);
21
+ }
22
+ /**
23
+ * Moves the single `article-feature` interlude to its display slot: the last free back-half section
24
+ * (or ~40% depth on a Discover piece). A section is free when it holds no interlude, affiliate carousel
25
+ * or inline image; with none free it falls back to a section without an interlude, then to the last
26
+ * section, and the paragraph pick keeps the card clear of the blocks there. Shared by every site's
27
+ * article page and by scripts/validate-articles.mjs, so the gate sees what the reader sees.
28
+ */
29
+ export function relocateArticleFeature(sections, editorialMode) {
30
+ let extracted = null;
31
+ const stripped = sections.map((section) => ({
32
+ ...section,
33
+ interludes: (section.interludes ?? []).filter((il) => {
34
+ if (il.type === 'article-feature') {
35
+ extracted = il;
36
+ return false;
37
+ }
38
+ return true;
39
+ }),
40
+ }));
41
+ if (!extracted)
42
+ return sections;
43
+ const n = stripped.length;
44
+ const order = [];
45
+ if (editorialMode === 'discover') {
46
+ for (let i = Math.min(n - 1, Math.max(1, Math.floor(n * 0.4))); i < n; i++)
47
+ order.push(i);
48
+ }
49
+ else {
50
+ for (let i = n - 1; i >= Math.ceil(n / 2); i--)
51
+ order.push(i);
52
+ }
53
+ const noInterlude = (i) => !stripped[i].interludes.length;
54
+ const targetIdx = order.find((i) => isFree(stripped[i])) ?? order.find(noInterlude) ?? order[0] ?? n - 1;
55
+ const afterParagraph = pickFeatureParagraph(stripped[targetIdx]);
56
+ return stripped.map((section, i) => i !== targetIdx ? section : { ...section, interludes: [...section.interludes, { ...extracted, afterParagraph }] });
57
+ }
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.0",
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,64 @@
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
+ /**
17
+ * Paragraph the feature card goes after: the section's middle, moved to the nearest slot at least two
18
+ * paragraphs from any block already in the section (one paragraph of prose between), and never the last
19
+ * paragraph when the section has more than one, so prose always follows the card.
20
+ */
21
+ export function pickFeatureParagraph(section: Section): number {
22
+ const count = paragraphsOf(section);
23
+ const last = Math.max(0, count - 2);
24
+ const preferred = Math.min(Math.max(0, count - 1), Math.max(1, Math.floor(count / 2)));
25
+ const taken = occupied(section);
26
+ const ok = (p: number) => taken.every((t) => Math.abs(t - p) >= 2);
27
+ let best = -1;
28
+ for (let p = 0; p <= last; p++) {
29
+ if (ok(p) && (best < 0 || Math.abs(p - preferred) < Math.abs(best - preferred))) best = p;
30
+ }
31
+ return best >= 0 ? best : Math.min(preferred, last);
32
+ }
33
+
34
+ /**
35
+ * Moves the single `article-feature` interlude to its display slot: the last free back-half section
36
+ * (or ~40% depth on a Discover piece). A section is free when it holds no interlude, affiliate carousel
37
+ * or inline image; with none free it falls back to a section without an interlude, then to the last
38
+ * section, and the paragraph pick keeps the card clear of the blocks there. Shared by every site's
39
+ * article page and by scripts/validate-articles.mjs, so the gate sees what the reader sees.
40
+ */
41
+ export function relocateArticleFeature<S extends Section>(sections: S[], editorialMode?: string): S[] {
42
+ let extracted: ({ type: string } & Partial<Block>) | null = null;
43
+ const stripped = sections.map((section) => ({
44
+ ...section,
45
+ interludes: (section.interludes ?? []).filter((il) => {
46
+ if (il.type === 'article-feature') { extracted = il; return false; }
47
+ return true;
48
+ }),
49
+ }));
50
+ if (!extracted) return sections;
51
+ const n = stripped.length;
52
+ const order: number[] = [];
53
+ if (editorialMode === 'discover') {
54
+ for (let i = Math.min(n - 1, Math.max(1, Math.floor(n * 0.4))); i < n; i++) order.push(i);
55
+ } else {
56
+ for (let i = n - 1; i >= Math.ceil(n / 2); i--) order.push(i);
57
+ }
58
+ const noInterlude = (i: number) => !stripped[i].interludes.length;
59
+ const targetIdx = order.find((i) => isFree(stripped[i])) ?? order.find(noInterlude) ?? order[0] ?? n - 1;
60
+ const afterParagraph = pickFeatureParagraph(stripped[targetIdx]);
61
+ return stripped.map((section, i) =>
62
+ i !== targetIdx ? section : { ...section, interludes: [...section.interludes, { ...extracted!, afterParagraph }] },
63
+ );
64
+ }