diff --git a/search.py b/search.py index 3b78248..2550c46 100644 --- a/search.py +++ b/search.py @@ -96,6 +96,7 @@ def searchcommand(): record['performance_date'] = performance_date.strftime("%d.%m.%Y") except (ValueError, TypeError): record['performance_date'] = None + record['query'] = query results.append(record) # Randomize and sort diff --git a/static/app.css b/static/app.css index 8ca4b2d..9911970 100644 --- a/static/app.css +++ b/static/app.css @@ -140,6 +140,10 @@ a.show-transcript:hover { color: rgb(113, 146, 167); } +.highlight { + background-color: yellow; +} + a.create-share { text-decoration: none; color: var(--main-text-color); diff --git a/static/app.js b/static/app.js index 82c2931..c3ff875 100644 --- a/static/app.js +++ b/static/app.js @@ -314,6 +314,7 @@ document.querySelectorAll('.play-file').forEach(link => { link.addEventListener('click', function (event) { event.preventDefault(); const url = this.getAttribute('data-url'); + const highlight = this.getAttribute('highlight'); fetch(url) .then(response => { if (!response.ok) { @@ -322,6 +323,23 @@ document.querySelectorAll('.play-file').forEach(link => { return response.text(); }) .then(data => { + // Highlight words in the transcript (substring match, case-insensitive) + if (highlight) { + // Escape special regex chars + const escapeRegExp = s => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); + + // Split on whitespace, escape each word, and join with | + const words = highlight + .trim() + .split(/\s+/) + .map(escapeRegExp) + .filter(Boolean); + + if (words.length) { + const regex = new RegExp(`(${words.join('|')})`, 'gi'); + data = data.replace(regex, '$1'); + } + } document.getElementById('transcriptContent').innerHTML = marked.parse(data); document.getElementById('transcriptModal').style.display = 'block'; }) @@ -357,7 +375,14 @@ document.querySelectorAll('.play-file').forEach(link => { }); }); }); -} + + // Handle back/forward navigation. + window.addEventListener('popstate', function (event) { + const subpath = event.state ? event.state.subpath : ''; + loadDirectory(subpath); + }); + +} // End of attachEventListeners function // Modal close logic for transcript modal. document.addEventListener('DOMContentLoaded', function () { @@ -379,11 +404,6 @@ document.addEventListener('DOMContentLoaded', function () { loadDirectory(initialSubpath); }); -// Handle back/forward navigation. -window.addEventListener('popstate', function (event) { - const subpath = event.state ? event.state.subpath : ''; - loadDirectory(subpath); -}); let isReloadButtonVisible = true; // Boolean to track the visibility of the reload button. diff --git a/static/search.js b/static/search.js index 1480d34..0959140 100644 --- a/static/search.js +++ b/static/search.js @@ -10,20 +10,20 @@ document.addEventListener('DOMContentLoaded', function() { const card = document.createElement('div'); const filenameWithoutExtension = file.filename.split('.').slice(0, -1).join('.'); const parentFolder = file.relative_path.split('/').slice(0, -1).join('/'); + const transcriptURL = '/transcript/' + parentFolder + '/Transkription/' + filenameWithoutExtension + '.md'; card.className = 'card'; card.innerHTML = `
Datum: ${file.performance_date}
- ${ file.transcript_hits !== undefined - ? `Treffer im Transkript: ${file.transcript_hits}
` - : `Downloads: ${file.hitcount}
` - } +Anzahl Downloads: ${file.hitcount}
+ ${ file.performance_date !== undefined ? `Datum: ${file.performance_date}
` : ``} + ${ file.transcript_hits !== undefined ? `Treffer im Transkript: ${file.transcript_hits} 📄
` : ``}No results found.
'; }