blob: c3f7de6d361f45dcf8d517318961d95a5a9c12f6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# Adaptive Repository Grid Design
**Date:** 2026-04-28
**Branch:** `feature/adaptive-repo-grid`
**Worktree:** `.worktrees/adaptive-repo-grid`
## Context
The repository page (`themes/danix-xyz-hacker/layouts/repository/single.html`) has a hardcoded `grid-cols-1 md:grid-cols-2 lg:grid-cols-3` layout for Slackware package repo cards. The card data lives in `data/repos.yaml`. When only 1 repo is defined, the card stretches full width — visually poor. When 2 repos are defined, the 3-col grid leaves an empty slot. Maintainability: adding or removing repos from the YAML file requires manual CSS adjustment.
**Goal:** Grid adapts automatically to however many repos are in `data/repos.yaml`. No Hugo template logic required for N > 1. Single-repo edge case handled by CSS `:only-child`.
## Design
### Approach: CSS `auto-fit/minmax` + `:only-child`
Replace the fixed Tailwind grid with a semantic CSS class backed by a custom rule:
**Grid container** (`auto-fit` handles 2+ repos automatically):
```css
.repo-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
gap: 1.5rem;
}
```
**Single-card centering** (fires only when exactly 1 card is in the grid):
```css
.repo-card:only-child {
max-width: 50%;
margin-inline: auto;
}
```
The `:only-child` rule fires only when the element has no siblings inside the grid — safe for 2, 3, N repos. If a non-card element is ever added inside `.repo-grid`, this rule still works correctly as long as there is only one `.repo-card`.
### Responsive behaviour by count
| Repos | Result |
|-------|--------|
| 1 | Card centered, 50% container width |
| 2 | Two equal columns (each ~50%) |
| 3 | Three equal columns (~33% each) |
| 4+ | Wraps to new rows, min 280px per card |
On small screens `minmax(280px, 1fr)` collapses to a single column naturally — no breakpoint overrides needed.
## Files to Modify
**Theme repo** (`/home/danix/Programming/GIT/danix2-hugo-theme/`):
1. `layouts/repository/single.html` — replace `grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6` class on wrapper div with `repo-grid`; add `repo-card` class to each card div
2. `assets/css/main.css` — add `.repo-grid` and `.repo-card:only-child` rules
**Content repo** (`/home/danix/Programming/GIT/danix.xyz-hacker-theme/`):
3. After CSS change: run `npm run build` to recompile `main.min.css`
4. Commit theme changes, push theme repo, bump submodule pointer in content repo
## Verification
1. `data/repos.yaml` — test with 1 entry: card should be centered at ~50% width
2. `data/repos.yaml` — test with 2 entries: two equal-width columns
3. `data/repos.yaml` — test with 3 entries: three equal-width columns (current default)
4. Resize viewport to mobile: all counts collapse to single column
5. `hugo server` from worktree root (after `git submodule update --init`) to preview live
|