feat: group category page rows by use case, restructure intro

Category pages sorted rows by downloads, which buried editorial leads (the Django ORM showed as row 7 of 7, tkinter as 14 of 14) against CONTRIBUTING.md's "position is the marker"; the full intro in the hero pushed the table 2.5 screens down on a phone; and every page repeated the same "Search every project in one place" H2.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Vinta Chen 2026-09-26 23:33:57 +08:00
parent 528f9edbb7
commit 2b9469c0ae
No known key found for this signature in database
GPG key ID: B93DE4F003C33630
5 changed files with 370 additions and 19 deletions

View file

@ -4,8 +4,14 @@ function getScrollBehavior() {
return reducedMotion.matches ? "auto" : "smooth";
}
const table = document.querySelector(".table");
// Category pages list rows in editorial (README) order until a column is sorted
const defaultSort =
table && table.dataset.defaultSort === "editorial"
? { col: "editorial", order: "asc" }
: { col: "downloads", order: "desc" };
let activeFilter = null;
let activeSort = { col: "downloads", order: "desc" };
let activeSort = defaultSort;
const searchInput = document.querySelector(".search");
const filterBar = document.querySelector(".filter-bar");
const filterValue = document.querySelector(".filter-value");
@ -14,6 +20,7 @@ const noResults = document.querySelector(".no-results");
const rows = document.querySelectorAll(".table tbody tr.row");
const tags = document.querySelectorAll(".tag");
const tbody = document.querySelector(".table tbody");
const groupRows = document.querySelectorAll(".table tbody tr.group-row");
function initRevealSections() {
const sections = document.querySelectorAll("[data-reveal]");
@ -111,6 +118,12 @@ document
time.textContent = relativeTime(time.getAttribute("datetime"));
});
let currentGroupRow = null;
Array.prototype.forEach.call(tbody ? tbody.rows : [], function (tr) {
if (tr.classList.contains("group-row")) currentGroupRow = tr;
else if (tr.classList.contains("row")) tr._groupRow = currentGroupRow;
});
rows.forEach(function (row, i) {
row._origIndex = i;
let next = row.nextElementSibling;
@ -176,6 +189,15 @@ function applyFilters() {
}
});
groupRows.forEach(function (groupRow) {
groupRow.hidden = true;
});
if (activeSort.col === "editorial") {
rows.forEach(function (row) {
if (!row.hidden && row._groupRow) row._groupRow.hidden = false;
});
}
if (noResults) noResults.hidden = visibleCount > 0;
tags.forEach(function (tag) {
@ -211,7 +233,7 @@ function buildQueryString() {
const params = new URLSearchParams();
const query = searchInput ? searchInput.value.trim() : "";
if (query) params.set("q", query);
if (activeSort.col !== "downloads" || activeSort.order !== "desc") {
if (activeSort.col !== defaultSort.col || activeSort.order !== defaultSort.order) {
params.set("sort", activeSort.col);
params.set("order", activeSort.order);
}
@ -227,6 +249,8 @@ function updateURL() {
}
function getSortValue(row, col) {
// +1 keeps the first row above the "no value" cutoff in sortRows
if (col === "editorial") return row._origIndex + 1;
if (col === "name") {
return row.querySelector(".col-name a").textContent.trim().toLowerCase();
}
@ -282,7 +306,12 @@ function sortRows() {
});
const frag = document.createDocumentFragment();
let lastGroupRow = null;
arr.forEach(function (row) {
if (col === "editorial" && row._groupRow && row._groupRow !== lastGroupRow) {
frag.appendChild(row._groupRow);
lastGroupRow = row._groupRow;
}
frag.appendChild(row);
if (row._descRow) frag.appendChild(row._descRow);
if (row._expandRow) frag.appendChild(row._expandRow);
@ -392,7 +421,7 @@ sortHeaders.forEach(function (th) {
if (activeSort.col === col) {
if (activeSort.order === defaultOrder)
activeSort = { col: col, order: altOrder };
else activeSort = { col: "downloads", order: "desc" };
else activeSort = defaultSort;
} else {
activeSort = { col: col, order: defaultOrder };
}

View file

@ -438,6 +438,7 @@ kbd {
.search:focus-visible,
.filter-clear:focus-visible,
.tag:focus-visible,
.jump-link:focus-visible,
.back-to-top:focus-visible,
.no-results-clear:focus-visible,
.table a:focus-visible,
@ -459,9 +460,9 @@ kbd {
z-index: 1;
width: min(100%, calc(var(--shell-max) + (var(--shell-pad) * 2)));
margin: 0 auto;
padding: 1.25rem var(--shell-pad) clamp(3.75rem, 8vw, 6.75rem);
padding: 1.25rem var(--shell-pad) clamp(2.25rem, 5vw, 3.5rem);
display: grid;
gap: clamp(3rem, 8vw, 5.5rem);
gap: clamp(2rem, 5vw, 3rem);
}
.category-hero h1 {
@ -497,7 +498,9 @@ kbd {
}
.category-subtitle a,
.category-intro a {
.category-intro a,
.guide-body a,
.jump-link {
color: var(--hero-text);
text-decoration: underline;
text-decoration-color: oklch(100% 0 0 / 0.32);
@ -505,12 +508,14 @@ kbd {
}
.category-subtitle a:hover,
.category-intro a:hover {
.category-intro a:hover,
.guide-body a:hover,
.jump-link:hover {
text-decoration-color: oklch(100% 0 0 / 0.7);
}
.category-intro {
margin-top: 1.75rem;
margin-top: 1.25rem;
display: grid;
gap: 0.9rem;
color: var(--hero-muted);
@ -530,10 +535,65 @@ kbd {
padding-left: 1.25rem;
}
.category-intro code {
.category-intro code,
.guide-body code {
font-size: 0.9em;
}
.jump-links {
display: flex;
flex-wrap: wrap;
gap: 0.45rem 1.6rem;
margin-top: 1.5rem;
}
.jump-link {
font-size: var(--text-base);
font-weight: 600;
}
/* The arrow marks an in-page jump; inline-block keeps it out of the underline */
.jump-link::after {
content: "\2193";
display: inline-block;
margin-left: 0.3rem;
color: var(--hero-kicker);
}
.guide-band {
padding-block: clamp(3rem, 7vw, 5.5rem);
background: linear-gradient(140deg, var(--hero-bg-start) 0%, var(--hero-bg-mid) 58%, var(--hero-bg-end) 100%);
color: var(--hero-text);
}
.guide-section {
display: grid;
gap: 1.5rem;
}
.guide-section h2 {
font-family: var(--font-display);
font-size: clamp(2.2rem, 4vw, 3.3rem);
font-weight: 600;
line-height: 0.94;
letter-spacing: -0.03em;
}
.guide-body {
display: grid;
gap: 1rem;
color: var(--hero-muted);
font-size: var(--text-lg);
line-height: 1.7;
text-wrap: pretty;
}
.guide-body ul {
display: grid;
gap: 0.35rem;
padding-left: 1.25rem;
}
.sponsor-band {
padding-block: clamp(2.5rem, 5.5vw, 4rem);
background:
@ -651,6 +711,11 @@ kbd {
padding-bottom: 1.75rem;
}
.order-note {
color: var(--ink-soft);
font-size: var(--text-base);
}
.results-note {
color: var(--ink-soft);
font-size: var(--text-sm);
@ -819,6 +884,44 @@ kbd {
cursor: pointer;
}
.group-row th {
padding-top: 2.25rem;
padding-bottom: 0.85rem;
padding-left: max(var(--shell-pad), calc(50vw - (var(--shell-max) / 2) + var(--shell-pad)));
text-align: left;
border-bottom: 1px solid var(--line-strong);
background: var(--bg-paper);
}
.group-row h2 {
display: flex;
align-items: baseline;
gap: 0.75rem;
font-family: var(--font-display);
font-size: clamp(1.7rem, 2.8vw, 2.2rem);
font-weight: 600;
line-height: 1;
scroll-margin-top: 4.5rem;
}
.group-row h2 a {
color: var(--ink);
}
.group-row h2 a:hover {
color: var(--accent-deep);
text-decoration: underline;
text-decoration-color: var(--accent-underline);
text-underline-offset: 0.2em;
}
.group-count {
font-family: var(--font-body);
font-size: var(--text-sm);
font-weight: 600;
color: var(--ink-muted);
}
.row:not(.open):hover td {
background: var(--row-hover);
}
@ -1735,7 +1838,8 @@ th[data-sort].sort-asc::after {
}
.table thead th:first-child,
.table tbody td:first-child {
.table tbody td:first-child,
.group-row th {
padding-left: 0.8rem;
}