Your Recent Searches
@@ -93,7 +94,23 @@
}
const csrftoken = getCookie('csrftoken');
- // --- Font prefs: fetch + apply + persist ---
+ // Helper: build entry view URL from a known-good template
+ // We grab a real URL like /entry/1/ and swap the trailing number with the actual id.
+ const ENTRY_URL_TEMPLATE = "{% url 'entry_view' 1 %}";
+ function entryUrlFor(id){
+ return ENTRY_URL_TEMPLATE.replace(/\/\d+\/?$/, '/' + id + '/');
+ }
+
+ // Helper: first N words with ellipsis
+ function firstWords(text, n){
+ const clean = (text || '').replace(/\s+/g, ' ').trim();
+ if (!clean) return '';
+ const words = clean.split(' ');
+ if (words.length <= n) return clean;
+ return words.slice(0, n).join(' ') + '…';
+ }
+
+ // --- Font prefs: fetch + apply + persist (unchanged) ---
function applyFont(size){
const root = document.documentElement;
root.classList.remove('fs-small','fs-default','fs-large','fs-xlarge');
@@ -117,7 +134,7 @@
});
});
- // --- Search history: fetch + render ---
+ // --- Search history: fetch + render (unchanged) ---
const histList = document.getElementById('searchHistoryList');
const histEmpty = document.getElementById('searchHistoryEmpty');
function renderHistory(items){
@@ -139,7 +156,7 @@
if (j.ok) renderHistory(j.items);
}).catch(()=>{});
- // --- Recently viewed: fetch + render ---
+ // --- Recently viewed: fetch + render (FIXED link + 20-word snippet) ---
const rvList = document.getElementById('recentViewsList');
const rvEmpty = document.getElementById('recentViewsEmpty');
function renderRecent(items){
@@ -147,9 +164,11 @@
if (!items || !items.length){ rvEmpty.style.display='block'; return; }
rvEmpty.style.display = 'none';
items.forEach(it=>{
- const li = document.createElement('li');
+ const url = entryUrlFor(it.entry_id);
+ const snippet = firstWords(it.illustration || '', 20) || `Entry #${it.entry_id}`;
const when = new Date(it.viewed_at);
- li.innerHTML = `
#${it.entry_id}
+ const li = document.createElement('li');
+ li.innerHTML = `
${snippet}
— ${when.toLocaleString()}`;
rvList.appendChild(li);
});
@@ -158,7 +177,7 @@
if (j.ok) renderRecent(j.items);
}).catch(()=>{});
- // --- Log searches reliably using Beacon on submit ---
+ // --- Log searches reliably using Beacon on submit (unchanged) ---
const searchForm = document.querySelector('form.search-form');
if (searchForm){
searchForm.addEventListener('submit', ()=>{