Skip to content

Commit 86dccb6

Browse files
fix: open in llm dropdown (#23145)
## Description - The original implementation was trying to pass the entire content of the documentation page through the URL parameters - Web servers/browsers have limits on URLs - Instead of passing the whole page as a URL parameter, the fix prompts Claude with a reference to the markdown file, putting the fetching and parsing onto the LLM, not the browser (which can't handle long files/pages) - Removing ChatGPT option, as OpenAI appears to no longer support reading RAW markdown files (I tested this using our site and several other docs sites) ## Related issues or tickets Fixes #23144 ## Reviews - [ ] Editorial review ## Testing Claude <img width="893" height="711" alt="image" src="https://github.com/user-attachments/assets/78fdafcd-4d7a-465e-b19d-a7f9c3eed326" />
1 parent 0cb6f5e commit 86dccb6

File tree

2 files changed

+8
-56
lines changed

2 files changed

+8
-56
lines changed

hugo_stats.json

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"classes": [
55
"--mount",
66
"--tmpfs",
7-
"-mr-20",
87
"-mt-0.5",
98
"-mt-8",
109
"-top-10",
@@ -193,7 +192,6 @@
193192
"border-blue",
194193
"border-divider-light",
195194
"border-gray-200",
196-
"border-gray-300",
197195
"border-gray-400",
198196
"border-green-400",
199197
"border-l-2",
@@ -239,9 +237,7 @@
239237
"dark:block",
240238
"dark:border-b-blue-600",
241239
"dark:border-divider-dark",
242-
"dark:border-gray-100",
243240
"dark:border-gray-400",
244-
"dark:border-gray-50",
245241
"dark:border-gray-700",
246242
"dark:border-green-400",
247243
"dark:border-l-magenta-dark",
@@ -266,7 +262,6 @@
266262
"dark:text-blue-700",
267263
"dark:text-divider-dark",
268264
"dark:text-gray",
269-
"dark:text-gray-100",
270265
"dark:text-gray-200",
271266
"dark:text-gray-300",
272267
"dark:text-gray-400",
@@ -554,7 +549,6 @@
554549
"text-gray-300",
555550
"text-gray-400",
556551
"text-gray-500",
557-
"text-gray-600",
558552
"text-gray-800",
559553
"text-left",
560554
"text-lg",
@@ -579,7 +573,6 @@
579573
"underline-offset-2",
580574
"w-2",
581575
"w-5",
582-
"w-56",
583576
"w-65",
584577
"w-8",
585578
"w-[1200px]",

layouts/partials/md-dropdown.html

Lines changed: 8 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,7 @@
5757
<div class="text-base">Ask questions with Docs AI</div>
5858
</div>
5959
</button>
60-
<button
61-
onclick="openInChatGPT()"
62-
data-heap-id="search-docs-ai-button"
63-
class="sub-button"
64-
>
65-
<span class="icon-svg mt-[2px] text-base leading-none">
66-
{{ partial "icon" "/icons/openai.svg" }}
67-
</span>
68-
<div class="leading-tight">
69-
<div class="text-base">Open in ChatGPT</div>
70-
</div>
71-
</button>
72-
60+
{{ if eq hugo.Environment "production" }}
7361
<button
7462
onclick="openInClaude()"
7563
data-heap-id="search-docs-ai-button"
@@ -82,11 +70,12 @@
8270
<div class="text-base">Open in Claude</div>
8371
</div>
8472
</button>
73+
{{ end }}
8574

8675
</div>
8776
</details>
8877

89-
<script>
78+
<script>
9079
function getCurrentPlaintextUrl() {
9180
const url = window.location.href.split("#")[0].replace(/\/$/, "");
9281
return `${url}/index.md`;
@@ -131,41 +120,11 @@
131120
}
132121
}
133122

134-
function openInChatGPT() {
135-
fetch(getCurrentPlaintextUrl())
136-
.then((response) => response.text())
137-
.then((text) => {
138-
const encodedText = encodeURIComponent(text);
139-
const chatGPTUrl = `https://chat.openai.com/?q=${encodedText}`;
140-
window.open(chatGPTUrl, "_blank");
141-
})
142-
.catch((err) => {
143-
console.error("Error opening in ChatGPT:", err);
144-
});
145-
}
146-
147123
function openInClaude() {
148-
fetch(getCurrentPlaintextUrl())
149-
.then((response) => response.text())
150-
.then((text) => {
151-
const encodedText = encodeURIComponent(text);
152-
const claudeUrl = `https://claude.ai/new?q=${encodedText}`;https://claude.ai/new?q=%22hey%22
153-
window.open(claudeUrl, '_blank');
154-
})
155-
.catch((err) => {
156-
console.error("Error opening in Claude:", err);
157-
});
124+
const markdownUrl = getCurrentPlaintextUrl();
125+
const prompt = `Read ${markdownUrl} so I can ask questions about it.`;
126+
const encodedText = encodeURIComponent(prompt);
127+
const claudeUrl = `https://claude.ai/new?q=${encodedText}`;
128+
window.open(claudeUrl, '_blank');
158129
}
159-
160-
document.addEventListener("click", function (event) {
161-
const dropdown = document.getElementById("markdownDropdown");
162-
163-
if (!dropdown) return;
164-
165-
const isClickInside = dropdown.contains(event.target);
166-
167-
if (!isClickInside && dropdown.hasAttribute("open")) {
168-
dropdown.removeAttribute("open");
169-
}
170-
});
171130
</script>

0 commit comments

Comments
 (0)