Skip to content

Commit 84b00d3

Browse files
committed
Enhance source rendering logic to support object structures with source, title, and URL, including fallback for string URLs
1 parent bf97185 commit 84b00d3

1 file changed

Lines changed: 35 additions & 9 deletions

File tree

TransAdviceAgent.html

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -368,17 +368,43 @@ <h4>Limitations & Future Work</h4>
368368
for (let i = start; i < end; i++) {
369369
const src = sources[i];
370370
const div = document.createElement('div');
371-
const { url, text } = getUrlAndText(src);
372-
if (url && isValidUrl(url)) {
373-
const a = document.createElement('a');
374-
a.href = url;
375-
a.textContent = text;
376-
a.target = '_blank';
377-
a.rel = 'noopener noreferrer';
378-
div.appendChild(a);
371+
372+
// If backend supplies an object with fields {source, title, url}, format as "source: title" linking to url
373+
if (src && typeof src === 'object' && !Array.isArray(src)) {
374+
const url = src.url || src.link || src.href || null;
375+
const sourceName = (src.source || src.source_name || '').toString().trim();
376+
const title = (src.title || src.text || '').toString().trim();
377+
const linkText = (sourceName || title) ? `${sourceName || 'Source'}: ${title || '(no title)'}` : JSON.stringify(src);
378+
379+
console.debug('Rendering source object', { index: i, src, url, linkText });
380+
381+
if (url && isValidUrl(url)) {
382+
const a = document.createElement('a');
383+
a.href = url;
384+
a.textContent = linkText;
385+
a.target = '_blank';
386+
a.rel = 'noopener noreferrer';
387+
div.appendChild(a);
388+
} else {
389+
div.textContent = linkText + (url ? ` (${url})` : '');
390+
}
391+
379392
} else {
380-
div.textContent = text + (url ? ` (${url})` : '');
393+
// Fallback: handle string URLs or unexpected shapes using existing helper
394+
const { url, text } = getUrlAndText(src);
395+
console.debug('Rendering fallback source', { index: i, src, url, text });
396+
if (url && isValidUrl(url)) {
397+
const a = document.createElement('a');
398+
a.href = url;
399+
a.textContent = text;
400+
a.target = '_blank';
401+
a.rel = 'noopener noreferrer';
402+
div.appendChild(a);
403+
} else {
404+
div.textContent = text + (url ? ` (${url})` : '');
405+
}
381406
}
407+
382408
sourcesListEl.appendChild(div);
383409
}
384410
// update pagination active state

0 commit comments

Comments
 (0)