-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathseo.js
More file actions
168 lines (157 loc) · 5.41 KB
/
seo.js
File metadata and controls
168 lines (157 loc) · 5.41 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
// Global SEO: Inject Organization + WebSite JSON-LD structured data
(function () {
if (typeof document === "undefined") return;
// --- Organization + WebSite schema (all pages) ---
var orgSchema = {
"@context": "https://schema.org",
"@graph": [
{
"@type": "Organization",
"@id": "https://dodopayments.com/#organization",
name: "Dodo Payments",
url: "https://dodopayments.com",
logo: {
"@type": "ImageObject",
url: "https://docs.dodopayments.com/logo/dark.svg",
},
sameAs: [
"https://x.com/dodopayments",
"https://linkedin.com/company/dodopayments",
"https://github.com/dodopayments",
"https://discord.gg/bYqAp4ayYh",
"https://www.instagram.com/dodo.payments/",
"https://www.facebook.com/profile.php?id=61565515607280",
],
description:
"Dodo Payments is the all-in-one payments, billing, and merchant of record platform for SaaS, AI, and digital products.",
},
{
"@type": "WebSite",
"@id": "https://docs.dodopayments.com/#website",
url: "https://docs.dodopayments.com",
name: "Dodo Payments Documentation",
publisher: {
"@id": "https://dodopayments.com/#organization",
},
inLanguage: [
"en",
"es",
"fr",
"de",
"ja",
"ko",
"hi",
"ar",
"zh-CN",
"id",
"it",
"pt-BR",
"sv",
"vi",
],
description:
"Documentation for Dodo Payments — the all-in-one payments, billing, and merchant of record platform for SaaS, AI, and digital products.",
potentialAction: {
"@type": "SearchAction",
target: {
"@type": "EntryPoint",
urlTemplate:
"https://docs.dodopayments.com/?q={search_term_string}",
},
"query-input": {
"@type": "PropertyValueSpecification",
valueRequired: true,
valueName: "search_term_string",
},
},
},
],
};
function injectSchema(data) {
var s = document.createElement("script");
s.type = "application/ld+json";
s.textContent = JSON.stringify(data);
document.head.appendChild(s);
}
injectSchema(orgSchema);
// --- FAQPage schema (FAQ page only, parsed from accordion content) ---
if (window.location.pathname.replace(/\/$/, "").endsWith("/miscellaneous/faq")) {
function buildFAQSchema() {
var faqs = [];
// Mintlify accordions render as interactive elements with trigger + content.
// Try common patterns: details/summary, data-state divs, role-based selectors.
var accordions =
document.querySelectorAll("details") ||
document.querySelectorAll("[data-state]");
// Fallback: find all accordion-like containers by looking for trigger buttons
// whose text starts with "Q" followed by a digit.
if (!accordions || !accordions.length) {
var buttons = document.querySelectorAll("button, [role='button']");
var seen = new Set();
buttons.forEach(function (btn) {
var text = btn.textContent.trim();
if (/^Q\d+:/i.test(text) && !seen.has(text)) {
seen.add(text);
var question = text.replace(/^Q\d+:\s*/i, "");
// The answer is in the next sibling or parent's content region
var parent = btn.closest("[data-state]") || btn.parentElement;
var content =
parent && parent.querySelector("[role='region'], [data-content]");
var answer = content
? content.textContent.trim().replace(/^A:\s*/i, "")
: "";
if (question && answer && answer.length > 10) {
faqs.push({
"@type": "Question",
name: question,
acceptedAnswer: {
"@type": "Answer",
text: answer.substring(0, 500),
},
});
}
}
});
} else {
accordions.forEach(function (acc) {
var trigger = acc.querySelector("summary, button, [role='button']");
var content = acc.querySelector(
"[role='region'], .accordion-content, dd, p"
);
if (!trigger) return;
var qText = trigger.textContent.trim();
if (!/^Q\d+:/i.test(qText)) return;
var question = qText.replace(/^Q\d+:\s*/i, "");
var answer = content
? content.textContent.trim().replace(/^A:\s*/i, "")
: "";
if (question && answer && answer.length > 10) {
faqs.push({
"@type": "Question",
name: question,
acceptedAnswer: {
"@type": "Answer",
text: answer.substring(0, 500),
},
});
}
});
}
if (faqs.length > 0) {
injectSchema({
"@context": "https://schema.org",
"@type": "FAQPage",
mainEntity: faqs,
});
}
}
// Mintlify is SSR (Next.js) so DOM should be ready, but allow time for hydration
if (document.readyState === "complete") {
setTimeout(buildFAQSchema, 500);
} else {
window.addEventListener("load", function () {
setTimeout(buildFAQSchema, 500);
});
}
}
})();