Skip to content

Commit b42142c

Browse files
committed
Show batch date and hash
1 parent 6f74250 commit b42142c

1 file changed

Lines changed: 36 additions & 15 deletions

File tree

src/components/BatchCard.astro

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,63 @@ interface Props {
1010
1111
const { id, pdf, posts, hash } = Astro.props as Props;
1212
13-
// generate a near-gray color derived from the hash
14-
const gray = 40 + (parseInt(hash.slice(0, 2), 16) % 50);
15-
const color = `hsl(0, 0%, ${gray}%)`;
13+
// generate a near-gray hue derived from the hash so every batch has a slightly
14+
// different colour
15+
const hue = (parseInt(hash.slice(0, 2), 16) / 255) * 360;
16+
const light = 40 + (parseInt(hash.slice(2, 4), 16) % 50);
17+
const color = `hsl(${hue.toFixed(0)}, 20%, ${light}%)`;
1618
17-
// create symmetric 5x5 pixel art similar to GitHub identicons
19+
// build a 25x15 pixel art grid, mirroring horizontally
20+
const width = 25;
21+
const height = 15;
1822
const coords: { x: number; y: number }[] = [];
1923
let i = 0;
20-
for (let y = 0; y < 5; y++) {
21-
for (let x = 0; x < 3; x++, i++) {
22-
if (parseInt(hash[i], 16) % 2 === 1) {
24+
for (let y = 0; y < height; y++) {
25+
for (let x = 0; x < Math.ceil(width / 2); x++, i++) {
26+
if (parseInt(hash[i % hash.length], 16) % 2 === 1) {
2327
coords.push({ x, y });
24-
if (x !== 2) coords.push({ x: 4 - x, y });
28+
const mirror = width - 1 - x;
29+
if (mirror !== x) coords.push({ x: mirror, y });
2530
}
2631
}
2732
}
33+
34+
const date = posts[0]?.data.date ?? "";
2835
---
2936
<a
3037
href={pdf}
3138
target="_blank"
3239
rel="noopener noreferrer"
3340
class="group relative block overflow-hidden rounded-lg border border-black/15 dark:border-white/20 hover:bg-black/5 dark:hover:bg-white/5 transition-colors duration-300 ease-in-out">
3441
<div class="relative w-full h-48 bg-black/5 dark:bg-white/10">
35-
<svg viewBox="0 0 100 100" class="w-full h-full">
42+
<svg
43+
viewBox="0 0 375 225"
44+
preserveAspectRatio="none"
45+
class="w-full h-full"
46+
>
3647
{coords.map(({ x, y }) => (
37-
<rect x={x * 20} y={y * 20} width="20" height="20" fill={color} />
48+
<rect x={x * 15} y={y * 15} width="15" height="15" fill={color} />
3849
))}
3950
</svg>
40-
<div class="absolute inset-0 grid place-items-center font-mono text-3xl sm:text-4xl text-black dark:text-white">
41-
Batch #{id}
51+
<div class="absolute inset-0 flex flex-col items-center justify-center font-mono text-black dark:text-white">
52+
<div class="font-bold text-3xl sm:text-4xl">Batch #{id}</div>
53+
<div class="text-xs sm:text-sm">{date}</div>
54+
<div class="text-xs sm:text-sm">{hash}</div>
4255
</div>
4356
</div>
4457
<svg
4558
xmlns="http://www.w3.org/2000/svg"
46-
viewBox="0 0 512 512"
47-
class="absolute top-2 right-2 size-5 stroke-0 fill-current opacity-80">
48-
<path d="M320 0c-17.7 0-32 14.3-32 32s14.3 32 32 32h82.7L201.4 265.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L448 109.3V192c0 17.7 14.3 32 32 32s32-14.3 32-32V32c0-17.7-14.3-32-32-32H320zM80 32C35.8 32 0 67.8 0 112v320c0 44.2 35.8 80 80 80h320c44.2 0 80-35.8 80-80V320c0-17.7-14.3-32-32-32s-32 14.3-32 32v112c0 8.8-7.2 16-16 16H80c-8.8 0-16-7.2-16-16V112c0-8.8 7.2-16 16-16h112c17.7 0 32-14.3 32-32s-14.3-32-32-32H80z" />
59+
viewBox="0 0 24 24"
60+
fill="none"
61+
stroke="currentColor"
62+
stroke-width="1.5"
63+
stroke-linecap="round"
64+
stroke-linejoin="round"
65+
class="absolute top-2 right-2 size-5 opacity-80"
66+
>
67+
<path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" />
68+
<polyline points="15 3 21 3 21 9" />
69+
<line x1="10" y1="14" x2="21" y2="3" />
4970
</svg>
5071
<div class="p-4 space-y-2">
5172
<ul class="text-sm list-disc list-inside space-y-0.5">

0 commit comments

Comments
 (0)