feat: integrate Avatar component across various modules for improved user representation and enhance profile page with Gravatar support
This commit is contained in:
23
src/lib/gravatar.ts
Normal file
23
src/lib/gravatar.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { createHash } from 'crypto';
|
||||
|
||||
export type GravatarDefault =
|
||||
| 'identicon' // Geometric pattern
|
||||
| 'mp' // Mystery person silhouette
|
||||
| 'retro' // 8-bit pixel art
|
||||
| 'robohash' // Generated robot
|
||||
| 'wavatar' // Stylized face
|
||||
| 'monsterid' // Colorful monster
|
||||
| 'blank'; // Transparent
|
||||
|
||||
export function getGravatarUrl(
|
||||
email: string,
|
||||
size: number = 40,
|
||||
fallback: GravatarDefault = 'identicon'
|
||||
): string {
|
||||
const hash = createHash('md5')
|
||||
.update(email.toLowerCase().trim())
|
||||
.digest('hex');
|
||||
|
||||
return `https://www.gravatar.com/avatar/${hash}?d=${fallback}&s=${size}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user