Skip to content

Commit 0bef0db

Browse files
authored
cleanup: optimize the page (#44)
* optimize the homepage Signed-off-by: kerthcet <kerthcet@gmail.com> * optimize Signed-off-by: kerthcet <kerthcet@gmail.com> * optimize Signed-off-by: kerthcet <kerthcet@gmail.com> * optimize Signed-off-by: kerthcet <kerthcet@gmail.com> * fix it Signed-off-by: kerthcet <kerthcet@gmail.com> --------- Signed-off-by: kerthcet <kerthcet@gmail.com>
1 parent a545b86 commit 0bef0db

21 files changed

Lines changed: 993 additions & 231 deletions

File tree

‎Makefile‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
1-
.PHONY: launch
1+
.PHONY: launch cover
2+
23
launch:
34
@echo "Launching the application..."
4-
npm run dev
5+
npm run dev
6+
7+
# Rebuild static/cover.png (the og:image) from tools/og-card.html.
8+
#
9+
# The card is copied into public/ and served over HTTP rather than opened as a
10+
# file:// URL, so the Jost webfont and the logo are same-origin — woff2 is
11+
# CORS-gated, and a cross-origin miss fails silently to the fallback font.
12+
cover:
13+
npm run build
14+
cp tools/og-card.html public/og-card.html
15+
@python3 -m http.server 8899 --directory public >/dev/null 2>&1 & \
16+
srv=$$!; sleep 1; \
17+
node tools/og-shot.mjs http://127.0.0.1:8899/og-card.html static/cover.png 1200 630; \
18+
kill $$srv
19+
rm -f public/og-card.html
20+
@echo "static/cover.png regenerated"

‎assets/js/custom.js‎

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,55 @@
1-
// Put your custom JS code here
1+
// Put your custom JS code here
2+
3+
// Refresh the homepage star counts from /.netlify/functions/stars.
4+
//
5+
// The counts are already rendered at build time, so this only corrects them
6+
// between rebuilds. Every failure path leaves the build-time values in place:
7+
// running `hugo server` without `netlify dev` has no function to call, and a
8+
// visitor may be offline.
9+
//
10+
// Cards are deliberately not re-sorted. This runs after first paint, so
11+
// reordering would visibly shuffle them. The order therefore reflects the last
12+
// deploy, and only looks wrong if two projects swap rank between deploys.
13+
(function () {
14+
function format(count) {
15+
return count >= 1000 ? (count / 1000).toFixed(1) + "k" : String(count);
16+
}
17+
18+
function refreshStars() {
19+
var badges = document.querySelectorAll(".feature-stars[data-repo]");
20+
if (!badges.length) {
21+
return;
22+
}
23+
24+
fetch("/.netlify/functions/stars")
25+
.then(function (response) {
26+
if (!response.ok) {
27+
throw new Error("stars endpoint responded " + response.status);
28+
}
29+
return response.json();
30+
})
31+
.then(function (stars) {
32+
for (var i = 0; i < badges.length; i++) {
33+
var badge = badges[i];
34+
var count = stars[badge.dataset.repo.toLowerCase()];
35+
if (typeof count !== "number") {
36+
continue;
37+
}
38+
39+
badge.querySelector("[data-stars-count]").textContent = format(count);
40+
badge.title = count + " stars on GitHub";
41+
// Reveals the badge on cards whose build-time lookup came back empty.
42+
badge.classList.remove("feature-stars-pending");
43+
}
44+
})
45+
.catch(function () {
46+
// Keep the build-time counts.
47+
});
48+
}
49+
50+
if (document.readyState === "loading") {
51+
document.addEventListener("DOMContentLoaded", refreshStars, { once: true });
52+
} else {
53+
refreshStars();
54+
}
55+
})();

‎assets/scss/common/_custom.scss‎

Lines changed: 291 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,291 @@
1-
// Put your custom SCSS code here
1+
// Put your custom SCSS code here
2+
3+
// Shrink the top-right navbar icons (social links + color mode toggler)
4+
#socialMenu .social-link svg,
5+
#buttonColorMode svg {
6+
width: 20px;
7+
height: 20px;
8+
}
9+
10+
// Skip link: the first focusable thing on the page, hidden until it has focus.
11+
//
12+
// Not Bootstrap's `.visually-hidden-focusable`, so this does not depend on that
13+
// utility surviving purgecss. Clipped rather than `display: none`, because a
14+
// display-none element cannot receive focus at all.
15+
.skip-link {
16+
position: absolute;
17+
top: 0;
18+
left: 0;
19+
z-index: 1080; // above the sticky navbar ($zindex-sticky is 1020)
20+
padding: 0.625rem 1rem;
21+
background: $primary;
22+
color: #fff;
23+
border-bottom-right-radius: 0.375rem;
24+
text-decoration: none;
25+
26+
&:not(:focus) {
27+
// The standard visually-hidden recipe: out of sight, still in the a11y tree.
28+
width: 1px;
29+
height: 1px;
30+
padding: 0;
31+
overflow: hidden;
32+
clip-path: inset(50%);
33+
white-space: nowrap;
34+
}
35+
36+
&:focus {
37+
color: #fff;
38+
}
39+
}
40+
41+
// Keep the footer at the bottom of the viewport on short pages
42+
// (the homepage does not fill the screen otherwise).
43+
body {
44+
display: flex;
45+
flex-direction: column;
46+
min-height: 100vh;
47+
}
48+
49+
// Flex items default to `min-width: auto`, so wide content (code blocks,
50+
// tables) could stretch the page instead of scrolling inside its own box
51+
// now that `body` is a flex container.
52+
body > * {
53+
min-width: 0;
54+
}
55+
56+
.footer {
57+
margin-top: auto;
58+
59+
// Doks sizes footer items at $font-size-base (16px) from `md` up, which is
60+
// heavy for a copyright line under an 18px body. No media query needed to
61+
// override it: same specificity, and this file is imported last.
62+
li {
63+
font-size: 0.8125rem;
64+
}
65+
}
66+
67+
// Scale the homepage headline with the viewport rather than wrapping it.
68+
.home h1.home-title {
69+
// `clamp()` passes through to CSS; Sass would try to evaluate `min()`
70+
// itself and fail on the mixed rem/vw units.
71+
font-size: clamp(1.5rem, 3.4vw, 3rem);
72+
// Doks pulls the home headline up by 1rem, which eats into the hero padding.
73+
margin-top: 0;
74+
margin-bottom: 1.75rem;
75+
}
76+
77+
// One line, but only where one line fits. Below `sm` the headline would have to
78+
// drop to ~15px to fit 320px on a single line, so it wraps to two legible lines
79+
// instead — `nowrap` there ran off the right edge and scrolled the page
80+
// sideways.
81+
@include media-breakpoint-up(sm) {
82+
.home h1.home-title {
83+
white-space: nowrap;
84+
}
85+
}
86+
87+
// The one piece of prose on the page. Constrained because a full-width measure
88+
// under a centred headline reads as a caption rather than a statement.
89+
.home .lead {
90+
max-width: 40rem;
91+
margin-inline: auto;
92+
opacity: 0.75;
93+
}
94+
95+
// The headline carries the top of the page alone, so give it room to sit in.
96+
// The slack comes out of the dead band above the footer, which the short
97+
// homepage leaves over anyway.
98+
.home {
99+
.section.container-fluid {
100+
// Scaled, not fixed: the headline itself scales with the viewport, and a
101+
// flat 5.5rem left 88px of air above a 20px headline on a phone.
102+
padding-top: clamp(2.5rem, 7vw, 5.5rem);
103+
padding-bottom: clamp(2rem, 5.5vw, 4.5rem);
104+
}
105+
106+
.section-features {
107+
padding-top: 0;
108+
}
109+
}
110+
111+
// Brand mark in the navbar (top left), next to the site title
112+
.navbar-brand {
113+
display: inline-flex;
114+
align-items: center;
115+
gap: 0.5rem;
116+
117+
&::before {
118+
content: "";
119+
display: inline-block;
120+
flex: 0 0 auto;
121+
width: 32px;
122+
height: 32px;
123+
background: url("images/logo.png") no-repeat center / contain;
124+
border-radius: 50%;
125+
}
126+
}
127+
128+
// Project cards on the homepage.
129+
//
130+
// Flex rather than grid or Bootstrap's row/col: seven cards never fill a row
131+
// evenly, and flex-wrap centres the short final row instead of leaving a hole
132+
// on one side. The explicit basis keeps every card the same width, which
133+
// `flex-grow` would not — the last row would stretch wider than the rows above.
134+
$feature-gap: 1.25rem;
135+
136+
// Names the grid without shouting: smaller than the headline, uppercase and
137+
// tracked out so it reads as a label for the section rather than a second title
138+
// competing with the hero.
139+
//
140+
// Deliberately not called `.section-title` — the theme already uses that for the
141+
// "Related posts" heading on blog and legal pages (doks-core _posts.scss:55), and
142+
// this would have restyled those into tiny uppercase labels.
143+
.feature-grid-title {
144+
margin-top: 0;
145+
margin-bottom: 1.5rem;
146+
text-align: center;
147+
font-size: 0.8125rem;
148+
font-weight: 600;
149+
letter-spacing: 0.08em;
150+
text-transform: uppercase;
151+
// Not lower: at 13px this is normal-size text for WCAG, so it needs 4.5:1.
152+
// 0.5 measured 3.01:1 and failed; 0.7 measures 5.4:1.
153+
opacity: 0.7;
154+
}
155+
156+
.feature-grid {
157+
display: flex;
158+
flex-wrap: wrap;
159+
justify-content: center;
160+
gap: $feature-gap;
161+
// It is a `ul` now, for the item count screen readers announce. Strip the
162+
// list affordances the browser adds; the cards are the visual affordance.
163+
padding-left: 0;
164+
margin-bottom: 0;
165+
list-style: none;
166+
}
167+
168+
.feature-card {
169+
flex: 0 0 100%;
170+
}
171+
172+
@include media-breakpoint-up(sm) {
173+
.feature-card {
174+
// Two per row: subtract the one gap between them.
175+
flex-basis: calc(50% - #{$feature-gap * 0.5});
176+
}
177+
}
178+
179+
@include media-breakpoint-up(lg) {
180+
.feature-card {
181+
// Four per row: three gaps spread across four cards.
182+
flex-basis: calc(25% - #{$feature-gap * 0.75});
183+
}
184+
}
185+
186+
.feature-card {
187+
padding: 1.5rem;
188+
// A warm tint rather than neutral grey: at these low alphas it barely reads
189+
// as colour, but it stops the cards from looking like grey wireframes.
190+
background: rgba($primary, 0.02);
191+
border: 1px solid rgba($primary, 0.14);
192+
border-radius: 0.75rem;
193+
transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
194+
195+
// `h3` rather than `h2`: the grid now sits under its own section heading, so
196+
// the card titles are one level deeper in the outline.
197+
h3 {
198+
// Doks puts a 2rem top margin on every heading, which leaves a gap
199+
// between the card's top edge and its title.
200+
margin-top: 0;
201+
margin-bottom: 0.5rem;
202+
display: flex;
203+
align-items: baseline;
204+
gap: 0.5rem;
205+
font-size: 1.125rem;
206+
207+
a {
208+
color: inherit;
209+
text-decoration: none;
210+
}
211+
}
212+
213+
// Decorative, and `aria-hidden` in the markup. `flex: 0 0 auto` stops a
214+
// wide emoji from being squeezed by a long project name.
215+
.feature-icon {
216+
flex: 0 0 auto;
217+
font-size: 1rem;
218+
line-height: 1;
219+
}
220+
221+
p {
222+
margin-bottom: 0;
223+
font-size: 1rem;
224+
opacity: 0.78;
225+
}
226+
227+
&:hover {
228+
border-color: rgba($primary, 0.6);
229+
box-shadow: 0 6px 20px rgba($primary, 0.12);
230+
transform: translateY(-2px);
231+
232+
h3 a {
233+
color: $primary;
234+
}
235+
}
236+
}
237+
238+
// The donation call to action. Deliberately unboxed: a panel here competed with
239+
// the project cards for attention and left a large empty band across the page.
240+
// A plain centred line separates it from the grid on whitespace alone.
241+
.feature-cta {
242+
// Separated by whitespace alone — no rule and no box. The gap is a little
243+
// wider than the grid's own row gap so the invitation still reads as the end
244+
// of the page rather than an eighth card that fell out of the row.
245+
margin-top: 3rem;
246+
text-align: center;
247+
248+
.feature-cta-title {
249+
display: block;
250+
font-weight: 600;
251+
color: $primary;
252+
}
253+
254+
p {
255+
margin: 0.125rem 0 0;
256+
font-size: 0.9375rem;
257+
opacity: 0.7;
258+
}
259+
}
260+
261+
// GitHub star count, right-aligned on the card's title line
262+
.feature-stars {
263+
display: inline-flex;
264+
align-items: center;
265+
gap: 0.25rem;
266+
margin-left: auto;
267+
flex: 0 0 auto;
268+
font-size: 0.8125rem;
269+
font-weight: 500;
270+
271+
svg {
272+
// A gold star, as GitHub draws it. The muting sits on the number instead of
273+
// the whole badge, so the colour is not washed out by an opacity of its own.
274+
color: #e3a008;
275+
// Nudge the star onto the text baseline
276+
margin-bottom: -0.125rem;
277+
}
278+
279+
// The count stays in the body colour: yellow text this small would be hard to
280+
// read on white, and the star alone carries the colour.
281+
[data-stars-count] {
282+
opacity: 0.65;
283+
}
284+
}
285+
286+
// No count yet: the build-time lookup failed and assets/js/custom.js has not
287+
// filled this in (or cannot reach the endpoint). Hide it rather than show a
288+
// bare star with no number.
289+
.feature-stars-pending {
290+
display: none;
291+
}
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1-
// Put your custom SCSS variables here
2-
$primary: #F2A884;
1+
// Put your custom SCSS variables here
2+
3+
// The brand orange, sampled from the logo. The previous value (#F2A884) was a
4+
// pale tint of it that only managed 1.96:1 contrast against white — well below
5+
// the 4.5:1 WCAG AA needs for text — so links and accents barely registered and
6+
// the site read as monochrome. This hits 4.56:1.
7+
$primary: #d93c0d;

0 commit comments

Comments
 (0)