-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathstructured-data.js
More file actions
676 lines (610 loc) · 22.3 KB
/
structured-data.js
File metadata and controls
676 lines (610 loc) · 22.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
/**
* Structured Data (JSON-LD) for our Helius documentation
*
* Mintlify does not generate JSON-LD server-side. This script runs client-side
* and injects schema.org structured data into the <head> based on the current page
*
*
* Schema types used:
* - WebSite → homepage
* - Organization → every page (standalone top-level entity for Knowledge Panel)
* - BreadcrumbList → all pages
* - APIReference → /api-reference/* pages
* - TechArticle → guides, tutorials, how-tos
* - FAQPage → /faqs/* pages (when Q&A pairs are present)
* - SoftwareApplication → product overview pages
* - WebPage + Offers → pricing page (/billing/plans)
* - WebPage (enriched) → everything else (with speakable + dates)
*/
(() => {
"use strict";
const BASE_URL = "https://www.helius.dev/docs";
const ORGANIZATION = {
"@context": "https://schema.org",
"@type": "Organization",
"@id": "https://www.helius.dev/#organization",
name: "Helius",
url: "https://www.helius.dev",
logo: {
"@type": "ImageObject",
url: "https://www.helius.dev/Helius-Brandkit/Helius/PNG/Helius-Horizontal-Logo.png",
width: 562,
height: 118,
},
sameAs: [
"https://github.com/helius-labs",
"https://discord.com/invite/6GXdee3gBj",
"https://x.com/helius",
"https://www.linkedin.com/company/heliusapi",
],
};
const DOCUMENTATION_SITE = {
"@context": "https://schema.org",
"@type": "WebSite",
"@id": "https://www.helius.dev/docs#website",
name: "Helius Documentation",
url: BASE_URL,
};
// Human-readable labels for known breadcrumb path segments
const BREADCRUMB_LABELS = {
"api-reference": "API Reference",
rpc: "RPC",
http: "HTTP Methods",
websocket: "WebSocket",
das: "DAS",
"zk-compression": "ZK Compression",
laserstream: "LaserStream",
grpc: "gRPC",
sender: "Sender",
webhooks: "Webhooks",
"enhanced-transactions": "Enhanced Transactions API",
"enhanced-websockets": "Enhanced WebSockets",
"wallet-api": "Wallet API",
"priority-fee": "Priority Fee",
"sending-transactions": "Sending Transactions",
"data-streaming": "Data Streaming",
"dedicated-nodes": "Dedicated Nodes",
billing: "Billing",
faqs: "FAQs",
agents: "Agents",
mcp: "MCP",
guides: "Guides",
nfts: "NFTs",
orb: "Orb",
support: "Support",
staking: "Staking",
airship: "AirShip",
gatekeeper: "Gatekeeper",
"token-metadata": "Token Metadata API",
mint: "Mint API",
"shred-delivery": "Shred Delivery",
skills: "Skills",
zh: "中文",
};
// Product overview pages that should use Product schema
// TODO: replace PRODUCT_IMAGE with per-product card images once available
const PRODUCT_IMAGE = "https://www.helius.dev/docs/images/hero-dark.png";
const PRODUCT_OVERVIEWS = {
"/rpc/overview": {
name: "Helius RPC",
category: "Solana RPC Infrastructure",
description: "High-performance Solana RPCs",
image: PRODUCT_IMAGE,
},
"/laserstream": {
name: "Helius LaserStream",
category: "Solana Data Streaming",
description:
"Ultra-low latency gRPC data streaming for Solana with historical replay",
image: PRODUCT_IMAGE,
},
"/das-api": {
name: "Helius DAS API",
category: "Solana API",
description:
"Unified API for querying Solana digital assets — NFTs, tokens, and compressed assets",
image: PRODUCT_IMAGE,
},
"/webhooks": {
name: "Helius Webhooks",
category: "Solana Event Notification Service",
description:
"Real-time HTTP POST notifications for Solana events",
image: PRODUCT_IMAGE,
},
"/enhanced-websockets": {
name: "Helius Enhanced WebSockets",
category: "Solana Data Streaming",
description:
"Advanced WebSocket APIs with powerful filtering and transaction parsing",
image: PRODUCT_IMAGE,
},
"/sending-transactions/sender": {
name: "Helius Sender",
category: "Solana Transaction Service",
description:
"Ultra-low latency transaction sending via staked connections and Jito",
image: PRODUCT_IMAGE,
},
"/dedicated-nodes": {
name: "Helius Dedicated Nodes",
category: "Solana Infrastructure",
description:
"Private Solana nodes with no rate limits and full Yellowstone gRPC support",
image: PRODUCT_IMAGE,
},
"/priority-fee-api": {
name: "Helius Priority Fee API",
category: "Solana API",
description:
"Smart priority fee estimation based on real-time Solana network conditions",
image: PRODUCT_IMAGE,
},
"/wallet-api/overview": {
name: "Helius Wallet API",
category: "Solana API",
description:
"REST endpoints for querying Solana wallet balances, history, identities, funding, and transfers",
image: PRODUCT_IMAGE,
},
"/gatekeeper/overview": {
name: "Helius Gatekeeper",
category: "Solana Edge Gateway",
description:
"Low-latency edge gateway for Solana infrastructure with intelligent routing",
image: PRODUCT_IMAGE,
},
};
// Speakable specification — signals AI models which content is quotable
const SPEAKABLE = {
"@type": "SpeakableSpecification",
cssSelector: ["h1", 'meta[name="description"]'],
};
// Pricing tiers for the billing/plans page
// Source of truth: https://dashboard.helius.dev and /billing/plans.mdx
// Update this array whenever plan names, prices, or limits change.
// priceValidUntil signals search engines when to re-check pricing.
const PRICE_VALID_UNTIL = "2026-12-31";
const PRICING_TIERS = [
{
name: "Free",
price: "0",
description:
"1M monthly credits, 10 RPC req/s, 2 DAS & Enhanced API req/s, standard WebSockets, community support",
},
{
name: "Agent",
price: "1",
description:
"1M monthly credits, 10 RPC req/s, 2 DAS & Enhanced API req/s, standard WebSockets, community support. 1 USDC one-time signup fee, programmatic access via CLI or MCP",
},
{
name: "Developer",
price: "49",
description:
"10M monthly credits, 50 RPC req/s, 10 DAS & Enhanced API req/s, standard WebSockets, LaserStream devnet, chat support",
},
{
name: "Business",
price: "499",
description:
"100M monthly credits, 200 RPC req/s, 50 DAS & Enhanced API req/s, Enhanced WebSockets, LaserStream devnet, priority chat support",
},
{
name: "Professional",
price: "999",
description:
"200M monthly credits, 500 RPC req/s, 100 DAS & Enhanced API req/s, Enhanced WebSockets, LaserStream mainnet + devnet, Slack/Telegram support",
},
];
// ── Helpers ──────────────────────────────────────────────────────────
/** Strip /docs prefix, optional /zh/ lang prefix, and trailing slash */
const getPagePath = () => {
const path = window.location.pathname
.replace(/^\/docs\/?/, "/")
.replace(/\/$/, "");
return path || "/";
};
/** Detect language from URL path */
const getLanguage = () => {
const path = window.location.pathname.replace(/^\/docs\/?/, "/");
return path.indexOf("/zh/") === 0 || path === "/zh" ? "zh" : "en";
};
/** Get the path without the language prefix (for page-type detection) */
const getNormalizedPath = () => {
const path = getPagePath();
return path.replace(/^\/zh\/?/, "/") || "/";
};
/** Read the page <title> text */
const getPageTitle = () => {
const el = document.querySelector("title");
const raw = el ? el.textContent : "";
return raw.split("|")[0].trim() || "Helius Docs";
};
/** Read published/modified dates from Open Graph meta tags injected by Mintlify */
const getPageDates = () => {
let published = document.querySelector('meta[property="article:published_time"]');
const modified = document.querySelector('meta[property="article:modified_time"]');
if (!published) published = document.querySelector('meta[property="og:updated_time"]');
return {
datePublished: published ? published.getAttribute("content") || "" : "",
dateModified: modified ? modified.getAttribute("content") || "" : "",
};
};
/** Read the meta description */
const getMetaDescription = () => {
const el = document.querySelector('meta[name="description"]');
return el ? el.getAttribute("content") || "" : "";
};
/** Build the canonical URL for the current page */
const getCanonicalUrl = () => {
const path = getPagePath();
if (path === "/") return BASE_URL;
return BASE_URL + path;
};
/** Get a human-readable breadcrumb label for a path segment */
const getBreadcrumbLabel = (segment) => {
if (BREADCRUMB_LABELS[segment]) return BREADCRUMB_LABELS[segment];
// Fallback: capitalize first letter and replace hyphens with spaces
return segment.charAt(0).toUpperCase() + segment.slice(1).replace(/-/g, " ");
};
/** Inject a JSON-LD script element into the <head> with a marker attribute */
const injectJsonLd = (data) => {
const script = document.createElement("script");
script.type = "application/ld+json";
script.setAttribute("data-helius-sd", "");
script.textContent = JSON.stringify(data);
document.head.appendChild(script);
};
/** Remove all previously injected JSON-LD elements */
const cleanup = () => {
const scripts = document.querySelectorAll(
'script[type="application/ld+json"][data-helius-sd]'
);
for (let i = 0; i < scripts.length; i++) {
scripts[i].remove();
}
};
// ── Breadcrumbs ──────────────────────────────────────────────────────
const buildBreadcrumbList = () => {
const path = getPagePath();
const items = [
{
"@type": "ListItem",
position: 1,
name: "Helius Docs",
item: BASE_URL,
},
];
if (path === "/") return null;
const segments = path.split("/").filter(Boolean);
let cumulative = "";
for (let i = 0; i < segments.length; i++) {
cumulative += "/" + segments[i];
items.push({
"@type": "ListItem",
position: i + 2,
name:
i === segments.length - 1
? getPageTitle()
: getBreadcrumbLabel(segments[i]),
item: BASE_URL + cumulative,
});
}
return {
"@context": "https://schema.org",
"@type": "BreadcrumbList",
itemListElement: items,
};
};
// ── Page-type detection (operates on normalized path, without /zh/) ──
const isHomepage = (path) => path === "/" || path === "/index";
const isApiReference = (path) => path.indexOf("/api-reference") === 0;
const isProductOverview = (path) => PRODUCT_OVERVIEWS.hasOwnProperty(path);
const GUIDE_PREFIXES = [
"/rpc/",
"/laserstream/",
"/gatekeeper/",
"/grpc/",
"/sending-transactions/",
"/das/",
"/enhanced-transactions/",
"/enhanced-websockets/",
"/dedicated-nodes/",
"/webhooks/",
"/data-streaming/",
"/priority-fee/",
"/wallet-api/",
"/nfts/",
"/zk-compression/",
"/staking/",
"/shred-delivery/",
"/agents/",
"/billing/",
"/support/",
"/orb/",
"/airship/",
];
const GUIDE_EXACT = ["/grpc", "/agents", "/quickstart", "/getting-data", "/data-streaming"];
const isGuide = (path) =>
GUIDE_EXACT.indexOf(path) !== -1 ||
GUIDE_PREFIXES.some(function (prefix) {
return path.indexOf(prefix) === 0;
});
const isFaqPage = (path) => path.indexOf("/faqs") === 0;
const isPricingPage = (path) => path === "/billing/plans";
// ── Determine the programmingModel for API reference pages ───────────
const getProgrammingModel = (path) => {
if (path.indexOf("/rpc/websocket") !== -1) return "WebSocket JSON-RPC";
if (path.indexOf("/rpc/http") !== -1) return "HTTP JSON-RPC";
if (path.indexOf("/laserstream") !== -1) return "gRPC";
if (path.indexOf("/enhanced-websockets") !== -1) return "WebSocket";
if (path.indexOf("/webhooks") !== -1) return "REST (Webhooks)";
if (path.indexOf("/wallet-api") !== -1) return "REST";
if (path.indexOf("/sender") !== -1) return "HTTP JSON-RPC";
if (path.indexOf("/das") !== -1) return "HTTP JSON-RPC";
if (path.indexOf("/priority-fee") !== -1) return "HTTP JSON-RPC";
if (path.indexOf("/enhanced-transactions") !== -1) return "HTTP JSON-RPC";
if (path.indexOf("/zk-compression") !== -1) return "HTTP JSON-RPC";
return "HTTP JSON-RPC";
};
// ── Schema builders ──────────────────────────────────────────────────
const buildWebSiteSchema = () => ({
"@context": "https://schema.org",
"@type": "WebSite",
"@id": "https://www.helius.dev/docs#website",
name: "Helius Documentation",
url: BASE_URL,
description:
"Developer documentation for Helius — the leading Solana RPC and infrastructure platform",
publisher: { "@id": "https://www.helius.dev/#organization" },
});
const buildApiReferenceSchema = (normalizedPath) => {
const lang = getLanguage();
const desc = getMetaDescription();
const dates = getPageDates();
const schema = {
"@context": "https://schema.org",
"@type": "APIReference",
headline: getPageTitle(),
url: getCanonicalUrl(),
mainEntityOfPage: { "@type": "WebPage", "@id": getCanonicalUrl() },
isPartOf: { "@id": "https://www.helius.dev/docs#website" },
publisher: { "@id": "https://www.helius.dev/#organization" },
targetPlatform: "Solana",
programmingModel: getProgrammingModel(normalizedPath),
speakable: SPEAKABLE,
inLanguage: lang,
};
if (desc) schema.description = desc;
if (dates.datePublished) schema.datePublished = dates.datePublished;
if (dates.dateModified) schema.dateModified = dates.dateModified;
return schema;
};
const buildTechArticleSchema = () => {
const lang = getLanguage();
const desc = getMetaDescription();
const dates = getPageDates();
const schema = {
"@context": "https://schema.org",
"@type": "TechArticle",
headline: getPageTitle(),
url: getCanonicalUrl(),
mainEntityOfPage: { "@type": "WebPage", "@id": getCanonicalUrl() },
isPartOf: { "@id": "https://www.helius.dev/docs#website" },
publisher: { "@id": "https://www.helius.dev/#organization" },
speakable: SPEAKABLE,
inLanguage: lang,
};
if (desc) schema.description = desc;
if (dates.datePublished) schema.datePublished = dates.datePublished;
if (dates.dateModified) schema.dateModified = dates.dateModified;
return schema;
};
const buildFaqSchema = () => {
const questions = [];
// Extract Q&A from <details>/<summary> elements (Mintlify Accordions)
const details = document.querySelectorAll("details");
for (let i = 0; i < details.length; i++) {
const summary = details[i].querySelector("summary");
if (!summary) continue;
const clone = details[i].cloneNode(true);
const summaryClone = clone.querySelector("summary");
if (summaryClone) summaryClone.remove();
const answerText = (clone.textContent || "").trim();
if (answerText) {
questions.push({
"@type": "Question",
name: summary.textContent.trim(),
acceptedAnswer: {
"@type": "Answer",
text: answerText,
},
});
}
}
if (questions.length === 0) return null;
const desc = getMetaDescription();
const schema = {
"@context": "https://schema.org",
"@type": "FAQPage",
name: getPageTitle(),
url: getCanonicalUrl(),
isPartOf: { "@id": "https://www.helius.dev/docs#website" },
mainEntity: questions,
speakable: SPEAKABLE,
inLanguage: getLanguage(),
};
if (desc) schema.description = desc;
return schema;
};
const buildProductSchema = (normalizedPath) => {
const product = PRODUCT_OVERVIEWS[normalizedPath];
const desc = product.description || getMetaDescription();
const schema = {
"@context": "https://schema.org",
"@type": "SoftwareApplication",
name: product.name,
url: getCanonicalUrl(),
image: product.image,
applicationCategory: "DeveloperApplication",
operatingSystem: "Solana",
description: desc,
author: { "@id": "https://www.helius.dev/#organization" },
offers: {
"@type": "Offer",
price: "0",
priceCurrency: "USD",
description: "Free tier available",
url: BASE_URL + "/billing/plans",
},
};
return schema;
};
const buildPricingSchema = () => {
const offers = PRICING_TIERS.map(function (tier) {
return {
"@type": "Offer",
name: "Helius " + tier.name,
price: tier.price,
priceCurrency: "USD",
priceValidUntil: PRICE_VALID_UNTIL,
description: tier.description + " (billed monthly)",
url: BASE_URL + "/billing/plans",
availability: "https://schema.org/InStock",
};
});
const desc = getMetaDescription();
const schema = {
"@context": "https://schema.org",
"@type": "WebPage",
name: getPageTitle(),
url: getCanonicalUrl(),
isPartOf: { "@id": "https://www.helius.dev/docs#website" },
publisher: { "@id": "https://www.helius.dev/#organization" },
speakable: SPEAKABLE,
mainEntity: {
"@type": "SoftwareApplication",
name: "Helius",
applicationCategory: "DeveloperApplication",
operatingSystem: "Solana",
offers: offers,
},
inLanguage: getLanguage(),
};
if (desc) schema.description = desc;
return schema;
};
const buildWebPageSchema = (options) => {
const enriched = options && options.enriched;
const lang = getLanguage();
const desc = getMetaDescription();
const schema = {
"@context": "https://schema.org",
"@type": "WebPage",
name: getPageTitle(),
url: getCanonicalUrl(),
isPartOf: { "@id": "https://www.helius.dev/docs#website" },
publisher: { "@id": "https://www.helius.dev/#organization" },
inLanguage: lang,
};
if (desc) schema.description = desc;
if (enriched) {
schema.speakable = SPEAKABLE;
const dates = getPageDates();
if (dates.datePublished) schema.datePublished = dates.datePublished;
if (dates.dateModified) schema.dateModified = dates.dateModified;
}
return schema;
};
// ── Main ─────────────────────────────────────────────────────────────
const run = () => {
cleanup();
const normalizedPath = getNormalizedPath();
// 1. Standalone entity blocks (all pages) — injected so Google can resolve
// @id references in nested publisher/isPartOf fields across all pages
injectJsonLd(ORGANIZATION);
injectJsonLd(DOCUMENTATION_SITE);
// 2. Breadcrumbs (all pages except homepage)
const breadcrumbs = buildBreadcrumbList();
if (breadcrumbs) injectJsonLd(breadcrumbs);
// 3. Page-specific schema
if (isHomepage(normalizedPath)) {
injectJsonLd(buildWebSiteSchema());
} else if (isApiReference(normalizedPath)) {
injectJsonLd(buildApiReferenceSchema(normalizedPath));
} else if (isFaqPage(normalizedPath)) {
const faqSchema = buildFaqSchema();
if (faqSchema) {
injectJsonLd(faqSchema);
} else {
// On SPA navigation the <title> changes before accordion content renders.
// Fall back to WebPage immediately, then retry once content has settled.
setTimeout(function () {
const retrySchema = buildFaqSchema();
if (retrySchema) {
cleanup();
injectJsonLd(ORGANIZATION);
injectJsonLd(DOCUMENTATION_SITE);
const breadcrumbs = buildBreadcrumbList();
if (breadcrumbs) injectJsonLd(breadcrumbs);
injectJsonLd(retrySchema);
}
}, 800);
injectJsonLd(buildWebPageSchema());
}
} else if (isPricingPage(normalizedPath)) {
injectJsonLd(buildWebPageSchema());
// Also inject FAQ schema if the pricing page has accordion Q&A pairs
var pricingFaq = buildFaqSchema();
if (pricingFaq) injectJsonLd(pricingFaq);
injectJsonLd(buildPricingSchema());
} else if (isProductOverview(normalizedPath)) {
injectJsonLd(buildProductSchema(normalizedPath));
} else if (isGuide(normalizedPath)) {
injectJsonLd(buildTechArticleSchema());
} else {
injectJsonLd(buildWebPageSchema({ enriched: true }));
}
};
// ── Lifecycle ────────────────────────────────────────────────────────
// SPA navigation: re-run when Mintlify updates the <title> on route change
const setupObserver = () => {
let debounceTimer;
const scheduleRun = () => {
clearTimeout(debounceTimer);
debounceTimer = setTimeout(run, 150);
};
// Watch <head> for <title> element being replaced (Next.js replaces the
// entire element on route change rather than mutating its text in place)
new MutationObserver((mutations) => {
for (let i = 0; i < mutations.length; i++) {
const added = mutations[i].addedNodes;
for (let j = 0; j < added.length; j++) {
if (added[j].nodeName === "TITLE") {
scheduleRun();
return;
}
}
}
}).observe(document.head, { childList: true });
// Also watch the current title element for in-place text changes
const titleEl = document.querySelector("title");
if (titleEl) {
new MutationObserver(scheduleRun).observe(titleEl, {
childList: true,
characterData: true,
subtree: true,
});
}
};
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", () => {
run();
setupObserver();
});
} else {
run();
setupObserver();
}
})();