Skip to content

Commit 2c775ce

Browse files
simonwclaude
andcommitted
Fix search result links for gistpreview URL format
- Rename getPageUrl to getPageFetchUrl (for fetching raw content) - Add getPageLinkUrl for navigation links using gistpreview URL format - Search result links now use ?gist-id/page-XXX.html format on gistpreview 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 6af434c commit 2c775ce

File tree

3 files changed

+42
-15
lines changed

3 files changed

+42
-15
lines changed

src/claude_code_transcripts/templates/search.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,22 @@
4343
}
4444
}
4545

46-
function getPageUrl(pageFile) {
46+
function getPageFetchUrl(pageFile) {
4747
if (isGistPreview && gistOwner && gistId) {
48-
// Use raw gist URL for fetching
48+
// Use raw gist URL for fetching content
4949
return 'https://gist.githubusercontent.com/' + gistOwner + '/' + gistId + '/raw/' + pageFile;
5050
}
5151
return pageFile;
5252
}
5353

54+
function getPageLinkUrl(pageFile) {
55+
if (isGistPreview && gistId) {
56+
// Use gistpreview URL format for navigation links
57+
return '?' + gistId + '/' + pageFile;
58+
}
59+
return pageFile;
60+
}
61+
5462
function escapeHtml(text) {
5563
var div = document.createElement('div');
5664
div.textContent = text;
@@ -141,12 +149,13 @@
141149

142150
// Get the message ID for linking
143151
var msgId = msg.id || '';
144-
var link = pageFile + (msgId ? '#' + msgId : '');
152+
var pageLinkUrl = getPageLinkUrl(pageFile);
153+
var link = pageLinkUrl + (msgId ? '#' + msgId : '');
145154

146155
// Clone the message HTML and highlight matches
147156
var clone = msg.cloneNode(true);
148157
// Fix internal links to include the page file
149-
fixInternalLinks(clone, pageFile);
158+
fixInternalLinks(clone, pageLinkUrl);
150159
highlightTextNodes(clone, query);
151160

152161
var resultDiv = document.createElement('div');
@@ -200,7 +209,7 @@
200209

201210
// Create promises that process results immediately when each fetch completes
202211
var promises = batch.map(function(pageFile) {
203-
return fetch(getPageUrl(pageFile))
212+
return fetch(getPageFetchUrl(pageFile))
204213
.then(function(response) {
205214
if (!response.ok) throw new Error('Failed to fetch');
206215
return response.text();

tests/__snapshots__/test_generate_html/TestGenerateHtml.test_generates_index_html.html

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,14 +246,22 @@ <h1>Claude Code transcript</h1>
246246
}
247247
}
248248

249-
function getPageUrl(pageFile) {
249+
function getPageFetchUrl(pageFile) {
250250
if (isGistPreview && gistOwner && gistId) {
251-
// Use raw gist URL for fetching
251+
// Use raw gist URL for fetching content
252252
return 'https://gist.githubusercontent.com/' + gistOwner + '/' + gistId + '/raw/' + pageFile;
253253
}
254254
return pageFile;
255255
}
256256

257+
function getPageLinkUrl(pageFile) {
258+
if (isGistPreview && gistId) {
259+
// Use gistpreview URL format for navigation links
260+
return '?' + gistId + '/' + pageFile;
261+
}
262+
return pageFile;
263+
}
264+
257265
function escapeHtml(text) {
258266
var div = document.createElement('div');
259267
div.textContent = text;
@@ -344,12 +352,13 @@ <h1>Claude Code transcript</h1>
344352

345353
// Get the message ID for linking
346354
var msgId = msg.id || '';
347-
var link = pageFile + (msgId ? '#' + msgId : '');
355+
var pageLinkUrl = getPageLinkUrl(pageFile);
356+
var link = pageLinkUrl + (msgId ? '#' + msgId : '');
348357

349358
// Clone the message HTML and highlight matches
350359
var clone = msg.cloneNode(true);
351360
// Fix internal links to include the page file
352-
fixInternalLinks(clone, pageFile);
361+
fixInternalLinks(clone, pageLinkUrl);
353362
highlightTextNodes(clone, query);
354363

355364
var resultDiv = document.createElement('div');
@@ -403,7 +412,7 @@ <h1>Claude Code transcript</h1>
403412

404413
// Create promises that process results immediately when each fetch completes
405414
var promises = batch.map(function(pageFile) {
406-
return fetch(getPageUrl(pageFile))
415+
return fetch(getPageFetchUrl(pageFile))
407416
.then(function(response) {
408417
if (!response.ok) throw new Error('Failed to fetch');
409418
return response.text();

tests/__snapshots__/test_generate_html/TestParseSessionFile.test_jsonl_generates_html.html

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,22 @@ <h1>Claude Code transcript</h1>
237237
}
238238
}
239239

240-
function getPageUrl(pageFile) {
240+
function getPageFetchUrl(pageFile) {
241241
if (isGistPreview && gistOwner && gistId) {
242-
// Use raw gist URL for fetching
242+
// Use raw gist URL for fetching content
243243
return 'https://gist.githubusercontent.com/' + gistOwner + '/' + gistId + '/raw/' + pageFile;
244244
}
245245
return pageFile;
246246
}
247247

248+
function getPageLinkUrl(pageFile) {
249+
if (isGistPreview && gistId) {
250+
// Use gistpreview URL format for navigation links
251+
return '?' + gistId + '/' + pageFile;
252+
}
253+
return pageFile;
254+
}
255+
248256
function escapeHtml(text) {
249257
var div = document.createElement('div');
250258
div.textContent = text;
@@ -335,12 +343,13 @@ <h1>Claude Code transcript</h1>
335343

336344
// Get the message ID for linking
337345
var msgId = msg.id || '';
338-
var link = pageFile + (msgId ? '#' + msgId : '');
346+
var pageLinkUrl = getPageLinkUrl(pageFile);
347+
var link = pageLinkUrl + (msgId ? '#' + msgId : '');
339348

340349
// Clone the message HTML and highlight matches
341350
var clone = msg.cloneNode(true);
342351
// Fix internal links to include the page file
343-
fixInternalLinks(clone, pageFile);
352+
fixInternalLinks(clone, pageLinkUrl);
344353
highlightTextNodes(clone, query);
345354

346355
var resultDiv = document.createElement('div');
@@ -394,7 +403,7 @@ <h1>Claude Code transcript</h1>
394403

395404
// Create promises that process results immediately when each fetch completes
396405
var promises = batch.map(function(pageFile) {
397-
return fetch(getPageUrl(pageFile))
406+
return fetch(getPageFetchUrl(pageFile))
398407
.then(function(response) {
399408
if (!response.ok) throw new Error('Failed to fetch');
400409
return response.text();

0 commit comments

Comments
 (0)