From c9937f8f693fea381075515ab512b6d4786c3d76 Mon Sep 17 00:00:00 2001 From: Kato Date: Sat, 5 Sep 2026 15:55:45 +0000 Subject: [PATCH] =?UTF-8?q?Fix=20JS=20=E2=80=94=20rebuild=20renderWikiCard?= =?UTF-8?q?s,=20formatDate,=20closeWikiModal,=20openWikiModalSingle,=20sea?= =?UTF-8?q?rchWiki,=20getTopicColor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/main.js | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 115 insertions(+), 2 deletions(-) diff --git a/js/main.js b/js/main.js index f85a510..0c62109 100644 --- a/js/main.js +++ b/js/main.js @@ -729,7 +729,6 @@ function renderWikiCards(data) { return; } - // Sort by updatedAt descending (newest first) const sorted = [...data].sort((a, b) => new Date(b.updatedAt || b.createdAt) - new Date(a.updatedAt || a.createdAt)); sorted.forEach((item, idx) => { @@ -741,4 +740,118 @@ function renderWikiCards(data) { const topic = currentLang === 'en' && item.topic_en ? item.topic_en : (item.topic || 'Unknown'); const topicColor = getTopicColor(topic); - // Get excerpt from first subtopic \ No newline at end of file + const subtopic = currentLang === 'en' && item.subtopic_en ? item.subtopic_en : (item.subtopic || ''); + const content = currentLang === 'en' && item.wiki_en ? item.wiki_en : (item.wiki || ''); + const dateStr = formatDate(new Date(item.updatedAt || item.createdAt)); + const teaser = content.trim().substring(0, 180); + const teaserEnd = content.trim().length > 180 ? '...' : ''; + + const badgeStyle = 'background:' + topicColor.bg + ';color:' + topicColor.text + ';border-left:4px solid ' + topicColor.border; + + card.innerHTML = '' + escapeHtml(topic).toUpperCase() + '' + + '

' + escapeHtml(subtopic) + '

' + + '

' + escapeHtml(teaser) + teaserEnd + '

' + + '
' + + '' + dateStr + '' + + 'Weiterlesen' + + '
'; + + card.addEventListener('click', () => openWikiModalSingle(item)); + card.addEventListener('keydown', (e) => { + if (e.key === 'Enter' || e.key === ' ') { + e.preventDefault(); + openWikiModalSingle(item); + } + }); + + grid.appendChild(card); + }); +} + +function formatDate(date) { + if (!(date instanceof Date) || isNaN(date)) return ''; + const year = date.getFullYear(); + const month = String(date.getMonth() + 1).padStart(2, '0'); + const day = String(date.getDate()).padStart(2, '0'); + return year + '-' + month + '-' + day; +} + +function closeWikiModal() { + const overlay = document.getElementById('wiki-modal-overlay'); + if (overlay) overlay.classList.remove('active'); +} + +function openWikiModalSingle(item) { + let modalOverlay = document.getElementById('wiki-modal-overlay'); + if (!modalOverlay) { + modalOverlay = document.createElement('div'); + modalOverlay.id = 'wiki-modal-overlay'; + modalOverlay.className = 'modal-overlay'; + document.body.appendChild(modalOverlay); + } + + const topic = currentLang === 'en' && item.topic_en ? item.topic_en : (item.topic || 'Unknown'); + const subtopic = currentLang === 'en' && item.subtopic_en ? item.subtopic_en : (item.subtopic || ''); + const content = currentLang === 'en' && item.wiki_en ? item.wiki_en : (item.wiki || ''); + const dateStr = formatDate(new Date(item.updatedAt || item.createdAt)); + + let html = ''; + modalOverlay.innerHTML = html; + modalOverlay.classList.add('active'); +} + +function searchWiki(term) { + if (!term.trim()) { + renderWikiCards(wikiData); + return; + } + + const t = term.toLowerCase(); + const filtered = wikiData.filter(item => { + const topic = ((item.topic_en && currentLang === 'en') ? item.topic_en : (item.topic || '')) + + ' ' + ((item.subtopic_en && currentLang === 'en') ? item.subtopic_en : (item.subtopic || '')) + + ' ' + ((item.wiki_en && currentLang === 'en') ? item.wiki_en : (item.wiki || '')); + return topic.toLowerCase().includes(t); + }); + + renderWikiCards(filtered); +} + +function getTopicColor(topic) { + const TOPIC_COLORS = { + '๐ŸŒŽ Internationales Geschรคft': { bg: '#E0F2F1', text: '#00695C', border: '#00695C' }, + '๐Ÿฆ Banken & Finanzen Filialen': { bg: '#E3F2FD', text: '#1565C0', border: '#1565C0' }, + '๐Ÿฆ Banken & Finanzen allgmein': { bg: '#E8EAF6', text: '#283593', border: '#283593' }, + '๐Ÿ’ฐ Steuern': { bg: '#FFF3E0', text: '#E65100', border: '#E65100' }, + '๐Ÿ’ป Software & Digital Operations': { bg: '#EDE7F6', text: '#4527A0', border: '#4527A0' }, + '๐Ÿ“‘ Buchhaltung': { bg: '#E8F5E9', text: '#2E7D32', border: '#2E7D32' } + }; + + if (TOPIC_COLORS[topic]) return TOPIC_COLORS[topic]; + + const cleanTopic = topic.replace(/^[^\s]+\s/, ''); + for (const key of Object.keys(TOPIC_COLORS)) { + const cleanKey = key.replace(/^[^\s]+\s/, ''); + if (cleanTopic === cleanKey) return TOPIC_COLORS[key]; + } + + let hash = 0; + for (let i = 0; i < topic.length; i++) { + hash = topic.charCodeAt(i) + ((hash << 5) - hash); + } + const hues = [200, 180, 240, 30, 140, 60]; + const idx = Math.abs(hash) % hues.length; + const color = hues[idx]; + return { + bg: 'hsl(' + color + ', 70%, 92%)', + text: 'hsl(' + color + ', 60%, 35%)', + border: 'hsl(' + color + ', 60%, 35%)' + }; +} +