Skip to content

Commit 77fcebc

Browse files
authored
Update newsy.html
1 parent 9f8ddf3 commit 77fcebc

1 file changed

Lines changed: 56 additions & 8 deletions

File tree

‎newsy.html‎

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@
6868
position: relative;
6969
width: 100%;
7070
max-width: 400px;
71+
display: flex;
72+
gap: 10px;
7173
}
7274

7375
.search-input {
@@ -100,6 +102,26 @@
100102
pointer-events: none;
101103
}
102104

105+
.sort-btn {
106+
background: rgba(255, 255, 255, 0.03);
107+
border: 1px solid var(--border);
108+
color: var(--text-muted);
109+
padding: 0 16px;
110+
border-radius: 8px;
111+
font-family: 'JetBrains Mono', monospace;
112+
font-size: 0.8rem;
113+
font-weight: 700;
114+
cursor: pointer;
115+
transition: 0.2s;
116+
white-space: nowrap;
117+
}
118+
119+
.sort-btn:hover {
120+
border-color: var(--accent-blue);
121+
color: #fff;
122+
background: rgba(0, 210, 255, 0.05);
123+
}
124+
103125
.newsy-grid {
104126
max-width: 1200px;
105127
margin: 0 auto;
@@ -255,8 +277,11 @@ <h1>Tech Briefs & News</h1>
255277
</div>
256278

257279
<div class="search-container">
258-
<span class="search-icon">&gt;</span>
259-
<input type="text" id="newsSearch" class="search-input" placeholder="Szukaj po tytule newsa...">
280+
<div style="position: relative; flex-grow: 1;">
281+
<span class="search-icon">&gt;</span>
282+
<input type="text" id="newsSearch" class="search-input" placeholder="Szukaj po tytule newsa...">
283+
</div>
284+
<button id="sortToggleBtn" class="sort-btn" onclick="toggleSortOrder()" title="Zmień kolejność sortowania">Sort: Najnowsze</button>
260285
</div>
261286
</div>
262287
</div>
@@ -279,10 +304,11 @@ <h1>Tech Briefs & News</h1>
279304
</div>
280305

281306
<div class="newsy-grid" id="newsGrid">
282-
{% for post in site.newsy %}
307+
{% assign sorted_newsy = site.newsy | sort: 'date' | reverse %}
308+
{% for post in sorted_newsy %}
283309
{% assign post_cat = post.category | default: "brief" | downcase %}
284310

285-
<a href="{{ post.url | relative_url }}" class="news-card" data-title="{{ post.title | downcase }}" data-category="{{ post_cat }}">
311+
<a href="{{ post.url | relative_url }}" class="news-card" data-title="{{ post.title | downcase }}" data-category="{{ post_cat }}" data-date="{{ post.date | date: '%s' }}">
286312
<div style="display: flex; flex-direction: column; height: 100%;">
287313
{% assign t = post %}
288314
{% assign thumb = t.icon | default: t.image %}
@@ -354,16 +380,32 @@ <h2 class="news-card-title">{{ post.title }}</h2>
354380
const searchInput = document.getElementById('newsSearch');
355381
const filterButtons = document.querySelectorAll('.filter-btn');
356382
const newsGrid = document.getElementById('newsGrid');
357-
const cards = newsGrid.querySelectorAll('.news-card');
383+
const sortToggleBtn = document.getElementById('sortToggleBtn');
358384
const noResults = document.getElementById('noResults');
359385

360386
let currentCategory = 'all';
361387
let currentQuery = '';
388+
let isAscending = false; // false = najnowsze pierwsze, true = najstarsze pierwsze
362389

363-
function filterCards() {
390+
function getActiveCards() {
391+
return Array.from(newsGrid.querySelectorAll('.news-card'));
392+
}
393+
394+
function filterAndSortCards() {
395+
let cards = getActiveCards();
364396
let visibleCount = 0;
365397

398+
// Sortowanie
399+
cards.sort((a, b) => {
400+
const dateA = parseInt(a.getAttribute('data-date'));
401+
const dateB = parseInt(b.getAttribute('data-date'));
402+
return isAscending ? dateA - dateB : dateB - dateA;
403+
});
404+
405+
// Ponowne uporządkowanie DOM i filtrowanie
366406
cards.forEach(card => {
407+
newsGrid.appendChild(card); // Przestawienie fizyczne w gridzie
408+
367409
const title = card.getAttribute('data-title');
368410
const category = card.getAttribute('data-category');
369411

@@ -381,17 +423,23 @@ <h2 class="news-card-title">{{ post.title }}</h2>
381423
noResults.style.display = (visibleCount === 0) ? 'block' : 'none';
382424
}
383425

426+
function toggleSortOrder() {
427+
isAscending = !isAscending;
428+
sortToggleBtn.textContent = isAscending ? 'Sort: Najstarsze' : 'Sort: Najnowsze';
429+
filterAndSortCards();
430+
}
431+
384432
searchInput.addEventListener('input', (e) => {
385433
currentQuery = e.target.value.toLowerCase().trim();
386-
filterCards();
434+
filterAndSortCards();
387435
});
388436

389437
filterButtons.forEach(btn => {
390438
btn.addEventListener('click', () => {
391439
filterButtons.forEach(b => b.classList.remove('active'));
392440
btn.classList.add('active');
393441
currentCategory = btn.getAttribute('data-filter');
394-
filterCards();
442+
filterAndSortCards();
395443
});
396444
});
397445
</script>

0 commit comments

Comments
 (0)