diff --git a/css/styles.css b/css/styles.css index 9578e71..265b7f7 100644 --- a/css/styles.css +++ b/css/styles.css @@ -1054,6 +1054,85 @@ body[data-lang="en"] .hide-de { display: none !important; } .rank-badge.rank-expert { background: #fff3e0; color: #e65100; } .rank-badge.rank-legend { background: #fce4ec; color: #c62828; } +/* ======================================== + WIKI TOPICS — filter pills + ======================================== */ +.wiki-topics { + display: flex; + flex-wrap: wrap; + gap: 6px; + margin: 12px 0 20px; +} +.wiki-topic-filter { + background: #f0f2f5; + border: none; + border-radius: 999px; + padding: 5px 12px; + font-size: 13px; + font-weight: 500; + color: #1c1e21; + cursor: pointer; + transition: background 0.2s, color 0.2s; + white-space: nowrap; +} +.wiki-topic-filter:hover { + background: #e4e6eb; +} +.wiki-topic-filter.active { + background: #1877f2; + color: #fff; +} +.wiki-filter-count { + font-size: 11px; + opacity: 0.7; + margin-left: 2px; +} + +/* ======================================== + WIKI FOOTER — counter + pagination + ======================================== */ +.wiki-footer { + display: flex; + align-items: center; + justify-content: center; + gap: 16px; + margin-top: 24px; + flex-wrap: wrap; +} +.wiki-counter { + font-size: 14px; + font-weight: 600; + color: #65676b; +} +.wiki-pagination { + display: flex; + align-items: center; + gap: 8px; +} +.wiki-page-btn { + background: #f0f2f5; + border: none; + border-radius: 8px; + padding: 6px 14px; + font-size: 13px; + font-weight: 500; + color: #1c1e21; + cursor: pointer; + transition: background 0.2s; +} +.wiki-page-btn:hover:not(:disabled) { + background: #e4e6eb; +} +.wiki-page-btn:disabled { + opacity: 0.4; + cursor: default; +} +.wiki-page-info { + font-size: 13px; + font-weight: 600; + color: #65676b; +} + /* ======================================== WIKI CARDS ======================================== */ diff --git a/index.html b/index.html index 35017cf..84053e5 100644 --- a/index.html +++ b/index.html @@ -436,12 +436,17 @@ +
' + (isDE() ? 'Keine Wiki-Daten' : 'No wiki data') + '
'; + const c = document.getElementById('wiki-counter'); if (c) c.innerHTML = ''; + const p = document.getElementById('wiki-pagination'); if (p) p.innerHTML = ''; } } catch (error) { document.getElementById('wiki-grid').innerHTML = '' + (isDE() ? 'Fehler beim Laden' : 'Error loading') + '
'; } } +function renderWikiTopics() { + const container = document.getElementById('wiki-topics'); + if (!container) return; + const topics = getWikiTopics(wikiData); + let html = ''; + topics.forEach(([topic, count]) => { + const esc = escapeHtml(topic).replace(/'/g, "\\'"); + html += ''; + }); + container.innerHTML = html; +} + +function filterWikiByTopic(topic) { + wikiActiveTopic = topic; + if (!topic) { + wikiFilteredData = [...wikiData].sort((a, b) => new Date(b.updatedAt || b.createdAt) - new Date(a.updatedAt || a.createdAt)); + } else { + wikiFilteredData = [...wikiData].filter(item => { + const t = currentLang === 'en' && item.topic_en ? item.topic_en : (item.topic || ''); + return t === topic; + }).sort((a, b) => new Date(b.updatedAt || b.createdAt) - new Date(a.updatedAt || a.createdAt)); + } + wikiCurrentPage = 1; + renderWikiTopics(); + renderWikiPage(); +} + +function renderWikiPage() { + const total = wikiFilteredData.length; + const totalPages = Math.max(1, Math.ceil(total / wikiPerPage)); + if (wikiCurrentPage > totalPages) wikiCurrentPage = totalPages; + const start = (wikiCurrentPage - 1) * wikiPerPage; + const pageData = wikiFilteredData.slice(start, start + wikiPerPage); + renderWikiCards(pageData); + renderWikiCounter(start, total); + renderWikiPagination(totalPages); +} + +function renderWikiCounter(start, total) { + const el = document.getElementById('wiki-counter'); + if (!el) return; + if (total === 0 || start >= total) { el.innerHTML = ''; return; } + const shown = Math.min(wikiPerPage, total - start); + el.textContent = start + shown + '/' + total; +} + +function renderWikiPagination(totalPages) { + const el = document.getElementById('wiki-pagination'); + if (!el) return; + if (totalPages <= 1) { el.innerHTML = ''; return; } + el.innerHTML = + '' + + '' + wikiCurrentPage + '/' + totalPages + '' + + ''; +} + +function wikiGoPage(page) { + const total = wikiFilteredData.length; + const totalPages = Math.max(1, Math.ceil(total / wikiPerPage)); + if (page < 1 || page > totalPages) return; + wikiCurrentPage = page; + const start = (wikiCurrentPage - 1) * wikiPerPage; + renderWikiCards(wikiFilteredData.slice(start, start + wikiPerPage)); + renderWikiCounter(start, total); + renderWikiPagination(totalPages); + const section = document.querySelector('#wiki'); + if (section) section.scrollIntoView({ behavior: 'smooth', block: 'start' }); +} + function renderWikiCards(data) { const grid = document.getElementById('wiki-grid'); grid.innerHTML = ''; @@ -759,9 +854,7 @@ function renderWikiCards(data) { return; } - const sorted = [...data].sort((a, b) => new Date(b.updatedAt || b.createdAt) - new Date(a.updatedAt || a.createdAt)); - - sorted.forEach((item, idx) => { + data.forEach((item, idx) => { const card = document.createElement('div'); card.className = 'wiki-card-new stagger-' + (idx % 4 + 1); card.setAttribute('role', 'button'); @@ -769,7 +862,6 @@ function renderWikiCards(data) { const topic = currentLang === 'en' && item.topic_en ? item.topic_en : (item.topic || 'Unknown'); const topicColor = getTopicColor(topic); - // Feed topic accent into CSS custom properties (top bar + hover border) card.style.setProperty('--topic-accent', topicColor.border); const subtopic = currentLang === 'en' && item.subtopic_en ? item.subtopic_en : (item.subtopic || ''); @@ -839,20 +931,22 @@ function openWikiModalSingle(item) { } function searchWiki(term) { - if (!term.trim()) { - renderWikiCards(wikiData); - return; + const t = term.toLowerCase().trim(); + if (!t) { + wikiActiveTopic = ''; + wikiFilteredData = [...wikiData].sort((a, b) => new Date(b.updatedAt || b.createdAt) - new Date(a.updatedAt || a.createdAt)); + } else { + wikiActiveTopic = ''; + wikiFilteredData = wikiData.filter(item => { + const text = ((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 text.toLowerCase().includes(t); + }).sort((a, b) => new Date(b.updatedAt || b.createdAt) - new Date(a.updatedAt || a.createdAt)); } - - 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); + renderWikiTopics(); + wikiCurrentPage = 1; + renderWikiPage(); } function getTopicColor(topic) {