Skip to content

Commit 54f770a

Browse files
simonwclaude
andcommitted
Fix gistpreview URL handling in search feature
- Fix gist ID extraction to use query string (?gist-id/file.html) instead of pathname - Preserve query string when updating URL hash for search terms - Ensures search URL stays as ?gist-id/index.html#search=term instead of losing the gist ID 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 3ad3ed0 commit 54f770a

File tree

3 files changed

+24
-21
lines changed

3 files changed

+24
-21
lines changed

src/claude_code_transcripts/templates/search.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
var gistInfoLoaded = false;
2323

2424
if (isGistPreview) {
25-
// Extract gist ID from URL path like /gist-id/index.html or /gist-id/raw/index.html
26-
var pathMatch = window.location.pathname.match(/^\/([a-f0-9]+)/i);
27-
if (pathMatch) {
28-
gistId = pathMatch[1];
25+
// Extract gist ID from URL query string like ?78a436a8a9e7a2e603738b8193b95410/index.html
26+
var queryMatch = window.location.search.match(/^\?([a-f0-9]+)/i);
27+
if (queryMatch) {
28+
gistId = queryMatch[1];
2929
}
3030
}
3131

@@ -74,15 +74,16 @@
7474

7575
function closeModal() {
7676
modal.close();
77-
// Update URL to remove search fragment
77+
// Update URL to remove search fragment, preserving path and query string
7878
if (window.location.hash.startsWith('#search=')) {
79-
history.replaceState(null, '', window.location.pathname);
79+
history.replaceState(null, '', window.location.pathname + window.location.search);
8080
}
8181
}
8282

8383
function updateUrlHash(query) {
8484
if (query) {
85-
history.replaceState(null, '', '#search=' + encodeURIComponent(query));
85+
// Preserve path and query string when adding hash
86+
history.replaceState(null, '', window.location.pathname + window.location.search + '#search=' + encodeURIComponent(query));
8687
}
8788
}
8889

tests/__snapshots__/test_generate_html/TestGenerateHtml.test_generates_index_html.html

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,10 @@ <h1>Claude Code transcript</h1>
225225
var gistInfoLoaded = false;
226226

227227
if (isGistPreview) {
228-
// Extract gist ID from URL path like /gist-id/index.html or /gist-id/raw/index.html
229-
var pathMatch = window.location.pathname.match(/^\/([a-f0-9]+)/i);
230-
if (pathMatch) {
231-
gistId = pathMatch[1];
228+
// Extract gist ID from URL query string like ?78a436a8a9e7a2e603738b8193b95410/index.html
229+
var queryMatch = window.location.search.match(/^\?([a-f0-9]+)/i);
230+
if (queryMatch) {
231+
gistId = queryMatch[1];
232232
}
233233
}
234234

@@ -277,15 +277,16 @@ <h1>Claude Code transcript</h1>
277277

278278
function closeModal() {
279279
modal.close();
280-
// Update URL to remove search fragment
280+
// Update URL to remove search fragment, preserving path and query string
281281
if (window.location.hash.startsWith('#search=')) {
282-
history.replaceState(null, '', window.location.pathname);
282+
history.replaceState(null, '', window.location.pathname + window.location.search);
283283
}
284284
}
285285

286286
function updateUrlHash(query) {
287287
if (query) {
288-
history.replaceState(null, '', '#search=' + encodeURIComponent(query));
288+
// Preserve path and query string when adding hash
289+
history.replaceState(null, '', window.location.pathname + window.location.search + '#search=' + encodeURIComponent(query));
289290
}
290291
}
291292

tests/__snapshots__/test_generate_html/TestParseSessionFile.test_jsonl_generates_html.html

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,10 @@ <h1>Claude Code transcript</h1>
216216
var gistInfoLoaded = false;
217217

218218
if (isGistPreview) {
219-
// Extract gist ID from URL path like /gist-id/index.html or /gist-id/raw/index.html
220-
var pathMatch = window.location.pathname.match(/^\/([a-f0-9]+)/i);
221-
if (pathMatch) {
222-
gistId = pathMatch[1];
219+
// Extract gist ID from URL query string like ?78a436a8a9e7a2e603738b8193b95410/index.html
220+
var queryMatch = window.location.search.match(/^\?([a-f0-9]+)/i);
221+
if (queryMatch) {
222+
gistId = queryMatch[1];
223223
}
224224
}
225225

@@ -268,15 +268,16 @@ <h1>Claude Code transcript</h1>
268268

269269
function closeModal() {
270270
modal.close();
271-
// Update URL to remove search fragment
271+
// Update URL to remove search fragment, preserving path and query string
272272
if (window.location.hash.startsWith('#search=')) {
273-
history.replaceState(null, '', window.location.pathname);
273+
history.replaceState(null, '', window.location.pathname + window.location.search);
274274
}
275275
}
276276

277277
function updateUrlHash(query) {
278278
if (query) {
279-
history.replaceState(null, '', '#search=' + encodeURIComponent(query));
279+
// Preserve path and query string when adding hash
280+
history.replaceState(null, '', window.location.pathname + window.location.search + '#search=' + encodeURIComponent(query));
280281
}
281282
}
282283

0 commit comments

Comments
 (0)