@sarimarcus/content-sites-core 0.54.0 → 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,10 @@
|
|
|
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
|
+
|
|
5
9
|
## 0.54.0 (2026-11-02)
|
|
6
10
|
|
|
7
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.
|
|
@@ -9,18 +9,8 @@ interface Section {
|
|
|
9
9
|
affiliateCarousels?: Block[];
|
|
10
10
|
inlineImages?: Block[];
|
|
11
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
|
-
*/
|
|
12
|
+
/** The card's paragraph: the clear slot nearest the section's middle, else the middle clamped before the last paragraph. */
|
|
17
13
|
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
|
-
*/
|
|
14
|
+
/** Moves the one `article-feature` interlude to its display slot, clear of carousels, images and interludes. Shared with validate-articles.mjs. */
|
|
25
15
|
export declare function relocateArticleFeature<S extends Section>(sections: S[], editorialMode?: string): S[];
|
|
26
16
|
export {};
|
|
@@ -1,31 +1,22 @@
|
|
|
1
1
|
const paragraphsOf = (s) => (s.body ?? '').split(/\n{2,}/).filter(Boolean).length;
|
|
2
2
|
const occupied = (s) => [...(s.interludes ?? []), ...(s.affiliateCarousels ?? []), ...(s.inlineImages ?? [])].flatMap((b) => typeof b.afterParagraph === 'number' ? [b.afterParagraph] : []);
|
|
3
3
|
const isFree = (s) => !(s.interludes?.length || s.affiliateCarousels?.length || s.inlineImages?.length);
|
|
4
|
-
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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. */
|
|
9
11
|
export function pickFeatureParagraph(section) {
|
|
10
12
|
const count = paragraphsOf(section);
|
|
11
|
-
const last = Math.max(0, count - 2);
|
|
12
13
|
const preferred = Math.min(Math.max(0, count - 1), Math.max(1, Math.floor(count / 2)));
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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);
|
|
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));
|
|
21
18
|
}
|
|
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
|
-
*/
|
|
19
|
+
/** Moves the one `article-feature` interlude to its display slot, clear of carousels, images and interludes. Shared with validate-articles.mjs. */
|
|
29
20
|
export function relocateArticleFeature(sections, editorialMode) {
|
|
30
21
|
let extracted = null;
|
|
31
22
|
const stripped = sections.map((section) => ({
|
|
@@ -50,8 +41,19 @@ export function relocateArticleFeature(sections, editorialMode) {
|
|
|
50
41
|
for (let i = n - 1; i >= Math.ceil(n / 2); i--)
|
|
51
42
|
order.push(i);
|
|
52
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;
|
|
53
48
|
const noInterlude = (i) => !stripped[i].interludes.length;
|
|
54
|
-
const targetIdx = order.find((i) => isFree(stripped[i])) ??
|
|
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;
|
|
55
57
|
const afterParagraph = pickFeatureParagraph(stripped[targetIdx]);
|
|
56
58
|
return stripped.map((section, i) => i !== targetIdx ? section : { ...section, interludes: [...section.interludes, { ...extracted, afterParagraph }] });
|
|
57
59
|
}
|
package/package.json
CHANGED
|
@@ -13,31 +13,23 @@ const occupied = (s: Section) =>
|
|
|
13
13
|
);
|
|
14
14
|
const isFree = (s: Section) => !(s.interludes?.length || s.affiliateCarousels?.length || s.inlineImages?.length);
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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. */
|
|
21
24
|
export function pickFeatureParagraph(section: Section): number {
|
|
22
25
|
const count = paragraphsOf(section);
|
|
23
|
-
const last = Math.max(0, count - 2);
|
|
24
26
|
const preferred = Math.min(Math.max(0, count - 1), Math.max(1, Math.floor(count / 2)));
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
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);
|
|
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));
|
|
32
30
|
}
|
|
33
31
|
|
|
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
|
-
*/
|
|
32
|
+
/** Moves the one `article-feature` interlude to its display slot, clear of carousels, images and interludes. Shared with validate-articles.mjs. */
|
|
41
33
|
export function relocateArticleFeature<S extends Section>(sections: S[], editorialMode?: string): S[] {
|
|
42
34
|
let extracted: ({ type: string } & Partial<Block>) | null = null;
|
|
43
35
|
const stripped = sections.map((section) => ({
|
|
@@ -55,8 +47,20 @@ export function relocateArticleFeature<S extends Section>(sections: S[], editori
|
|
|
55
47
|
} else {
|
|
56
48
|
for (let i = n - 1; i >= Math.ceil(n / 2); i--) order.push(i);
|
|
57
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;
|
|
58
54
|
const noInterlude = (i: number) => !stripped[i].interludes.length;
|
|
59
|
-
const targetIdx =
|
|
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;
|
|
60
64
|
const afterParagraph = pickFeatureParagraph(stripped[targetIdx]);
|
|
61
65
|
return stripped.map((section, i) =>
|
|
62
66
|
i !== targetIdx ? section : { ...section, interludes: [...section.interludes, { ...extracted!, afterParagraph }] },
|