Skip to content

Commit 9b3841f

Browse files
add cute fun stickers
1 parent 07ccb61 commit 9b3841f

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

src/pages/index.astro

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,45 @@ const posts = (await getCollection('library'))
1010
if (b.data.title === 'Checkly Setup') return 1
1111
return 0
1212
})
13+
14+
// Define theme colors for random sticker colors
15+
const themeColors = [
16+
'#32858b', // accent
17+
'#22c55e', // checkly green
18+
'#8b5cf6', // playwright purple
19+
'#eab308', // yellow variant
20+
'#f97316', // orange variant
21+
'#ef4444', // red variant
22+
'#06b6d4', // cyan variant
23+
'#10b981', // emerald variant
24+
]
25+
26+
// Function to get a random color that's different from others by at least 10% in brightness
27+
function getRandomStickerColor(usedColors: string[] = []) {
28+
const availableColors = themeColors.filter(color => {
29+
if (usedColors.length === 0) return true
30+
31+
// Simple brightness calculation
32+
const getBrightness = (hex: string) => {
33+
const r = parseInt(hex.slice(1, 3), 16)
34+
const g = parseInt(hex.slice(3, 5), 16)
35+
const b = parseInt(hex.slice(5, 7), 16)
36+
return (r * 299 + g * 587 + b * 114) / 1000
37+
}
38+
39+
const colorBrightness = getBrightness(color)
40+
return usedColors.every(used => {
41+
const usedBrightness = getBrightness(used)
42+
return Math.abs(colorBrightness - usedBrightness) / 255 > 0.1 // 10% difference
43+
})
44+
})
45+
46+
return availableColors.length > 0
47+
? availableColors[Math.floor(Math.random() * availableColors.length)]
48+
: themeColors[Math.floor(Math.random() * themeColors.length)]
49+
}
50+
51+
const usedStickerColors: string[] = []
1352
const base = import.meta.env.BASE_URL.endsWith('/')
1453
? import.meta.env.BASE_URL
1554
: import.meta.env.BASE_URL + '/'
@@ -45,10 +84,17 @@ const base = import.meta.env.BASE_URL.endsWith('/')
4584
const hasChecklyTag = post.data.tags?.includes('Checkly')
4685
const hasPlaywrightTag = post.data.tags?.includes('Playwright')
4786

87+
// Get random color for sticker if it has one
88+
let stickerColor = '#32858b' // default
89+
if (post.data.sticker) {
90+
stickerColor = getRandomStickerColor(usedStickerColors)
91+
usedStickerColors.push(stickerColor)
92+
}
93+
4894
return (
4995
<article class="card" data-tags={post.data.tags?.join(',') || ''}>
5096
{post.data.sticker && (
51-
<div class="start-here-sticker" style={`transform: rotate(${-12 + (Math.random() * 2 - 1)}deg)`}>{post.data.sticker}</div>
97+
<div class="start-here-sticker" style={`transform: rotate(${-12 + (Math.random() * 2 - 1)}deg); background: ${stickerColor}; border-color: ${stickerColor};`}>{post.data.sticker}</div>
5298
)}
5399
<div class="card-header">
54100
<div class="card-icon">

0 commit comments

Comments
 (0)