@tokenoftrust/storefront-runner 4.0.0 → 4.0.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.
|
@@ -40,14 +40,28 @@ function detailsPair(block: string): FaqItem | null {
|
|
|
40
40
|
return { q, a: textOf(rest) };
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
/**
|
|
43
|
+
/** A heading inside details is that pair's question, not a second heading pair. */
|
|
44
|
+
function insideDetails(index: number, ranges: Array<{ start: number; end: number }>): boolean {
|
|
45
|
+
return ranges.some((range) => index >= range.start && index < range.end);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** FAQ pairs from sanitized body HTML: question-phrased h2–h4 outside details, plus every details/summary pair. */
|
|
44
49
|
export function faqFromHtml(html: string | undefined): FaqItem[] {
|
|
45
50
|
if (!html) return [];
|
|
51
|
+
const ranges = [...html.matchAll(/<details\b[^>]*>[\s\S]*?<\/details>/gi)].map((match) => ({
|
|
52
|
+
start: match.index ?? 0,
|
|
53
|
+
end: (match.index ?? 0) + match[0].length,
|
|
54
|
+
}));
|
|
46
55
|
const parts = html.split(/(<h[2-4][^>]*>[\s\S]*?<\/h[2-4]>)/i);
|
|
47
56
|
const items: FaqItem[] = [];
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
57
|
+
let offset = 0;
|
|
58
|
+
for (let i = 0; i < parts.length; i++) {
|
|
59
|
+
const part = parts[i] ?? "";
|
|
60
|
+
if (i % 2 === 1) {
|
|
61
|
+
const q = textOf(part);
|
|
62
|
+
if (isQuestion(q) && !insideDetails(offset, ranges)) items.push({ q, a: textOf(parts[i + 1] ?? "") });
|
|
63
|
+
}
|
|
64
|
+
offset += part.length;
|
|
51
65
|
}
|
|
52
66
|
for (const block of html.matchAll(/<details\b[^>]*>[\s\S]*?<\/details>/gi)) {
|
|
53
67
|
const pair = detailsPair(block[0]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tokenoftrust/storefront-runner",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE",
|
|
5
5
|
"description": "World-shareable storefront runner: multi-tenant renderer on Astro/Cloudflare. No control plane.",
|
|
6
6
|
"packageManager": "pnpm@11.9.0",
|