Skip to content

Commit 692ffbc

Browse files
Fix additional repository issues: env config, image handling, scripts, and docs
Co-authored-by: rezwana-karim <126201034+rezwana-karim@users.noreply.github.com>
1 parent 663c5eb commit 692ffbc

6 files changed

Lines changed: 209 additions & 7 deletions

File tree

.env.example

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Development Environment Variables
2+
# Copy this file to .env.local and update values as needed
3+
4+
# Next.js Configuration
5+
NEXT_TELEMETRY_DISABLED=1
6+
7+
# GitHub Configuration (for development)
8+
# GITHUB_TOKEN=your_github_token_here
9+
10+
# API URLs (for future integrations)
11+
# API_BASE_URL=http://localhost:3000/api
12+
13+
# Feature Flags (for future use)
14+
# ENABLE_ANALYTICS=false
15+
# ENABLE_ERROR_REPORTING=false
16+
17+
# Database Configuration (for future use)
18+
# DATABASE_URL=postgresql://username:password@localhost:5432/codestorm_hub

README.md

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,34 @@ This project implements a comprehensive design system based on:
4848

4949
## Development
5050

51-
- `npm run dev` - Start development server
52-
- `npm run build` - Build for production
53-
- `npm run build:github-pages` - Build for GitHub Pages deployment
51+
### Environment Setup
52+
53+
1. Copy the environment example file:
54+
```bash
55+
cp .env.example .env.local
56+
```
57+
58+
2. Install dependencies:
59+
```bash
60+
npm install
61+
```
62+
63+
### Available Scripts
64+
65+
- `npm run dev` - Start development server with Turbopack
66+
- `npm run build` - Build for production (GitHub Pages optimized)
5467
- `npm run start` - Start production server
55-
- `npm run lint` - Run ESLint
68+
- `npm run lint` - Run ESLint with auto-fix
69+
- `npm run type-check` - Run TypeScript type checking
70+
- `npm run dev:clean` - Clean build cache and start dev server
71+
72+
### Code Quality
73+
74+
This project enforces strict code quality standards:
75+
- TypeScript strict mode
76+
- ESLint with Next.js recommended rules
77+
- Accessibility compliance (WCAG 2.1 AA)
78+
- Performance optimization (Core Web Vitals)
5679

5780
## Deployment
5881

next.config.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,38 @@ const nextConfig: NextConfig = {
1616
hostname: "github.com",
1717
pathname: "/CodeStorm-Hub/**",
1818
},
19+
{
20+
protocol: "https",
21+
hostname: "images.unsplash.com",
22+
pathname: "/**",
23+
},
24+
{
25+
protocol: "https",
26+
hostname: "avatars.githubusercontent.com",
27+
pathname: "/**",
28+
},
29+
{
30+
protocol: "https",
31+
hostname: "ui-avatars.com",
32+
pathname: "/**",
33+
},
1934
],
2035
},
36+
37+
// Performance optimizations
38+
poweredByHeader: false,
39+
40+
// TypeScript configuration
41+
typescript: {
42+
// Type checking is handled by the CI pipeline
43+
ignoreBuildErrors: false,
44+
},
45+
46+
// ESLint configuration
47+
eslint: {
48+
// Linting is handled by the CI pipeline
49+
ignoreDuringBuilds: false,
50+
},
2151
};
2252

2353
export default nextConfig;

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
"version": "0.1.0",
44
"private": true,
55
"scripts": {
6-
"dev": "next dev --turbopack",
7-
"build": "next build --turbopack",
6+
"dev": "NEXT_TELEMETRY_DISABLED=1 next dev --turbopack",
7+
"build": "NEXT_TELEMETRY_DISABLED=1 next build --turbopack",
88
"start": "next start",
9-
"lint": "eslint . --ext .ts,.tsx,.js,.jsx --fix"
9+
"lint": "eslint . --ext .ts,.tsx,.js,.jsx --fix",
10+
"type-check": "tsc --noEmit",
11+
"dev:clean": "rm -rf .next && npm run dev"
1012
},
1113
"dependencies": {
1214
"@radix-ui/colors": "^3.0.0",

src/components/ui/avatar.tsx

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import * as React from "react"
2+
import Image from "next/image"
3+
import { cn } from "@/lib/utils"
4+
import { getImageWithFallback } from "@/lib/image-utils"
5+
6+
export interface AvatarProps extends React.HTMLAttributes<HTMLDivElement> {
7+
src: string
8+
alt: string
9+
size?: number
10+
fallback?: string
11+
}
12+
13+
const Avatar = React.forwardRef<HTMLDivElement, AvatarProps>(
14+
({ className, src, alt, size = 40, fallback, ...props }, ref) => {
15+
const [imageSrc, setImageSrc] = React.useState(src)
16+
const { src: optimizedSrc, fallbackSrc } = getImageWithFallback(src, alt)
17+
18+
const handleError = React.useCallback(() => {
19+
if (fallback) {
20+
setImageSrc(fallback)
21+
} else if (fallbackSrc && imageSrc !== fallbackSrc) {
22+
setImageSrc(fallbackSrc)
23+
}
24+
}, [fallback, fallbackSrc, imageSrc])
25+
26+
React.useEffect(() => {
27+
setImageSrc(optimizedSrc)
28+
}, [optimizedSrc])
29+
30+
return (
31+
<div
32+
ref={ref}
33+
className={cn(
34+
"relative inline-flex h-10 w-10 items-center justify-center rounded-full bg-muted overflow-hidden",
35+
className
36+
)}
37+
style={{ width: size, height: size }}
38+
{...props}
39+
>
40+
<Image
41+
src={imageSrc}
42+
alt={alt}
43+
width={size}
44+
height={size}
45+
className="h-full w-full object-cover"
46+
onError={handleError}
47+
unoptimized={true}
48+
/>
49+
</div>
50+
)
51+
}
52+
)
53+
54+
Avatar.displayName = "Avatar"
55+
56+
export { Avatar }

src/lib/image-utils.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/**
2+
* Image utilities for handling external images and fallbacks
3+
*/
4+
5+
export interface ImageFallbackProps {
6+
src: string
7+
alt: string
8+
fallbackSrc?: string
9+
}
10+
11+
/**
12+
* Generate a fallback avatar using GitHub's avatar API or a placeholder
13+
*/
14+
export function generateFallbackAvatar(name: string): string {
15+
// Create a simple avatar using the first letter of the name
16+
const initials = name
17+
.split(' ')
18+
.map(word => word[0])
19+
.join('')
20+
.toUpperCase()
21+
.slice(0, 2)
22+
23+
// Return a GitHub-style avatar URL or placeholder
24+
return `https://ui-avatars.com/api/?name=${encodeURIComponent(initials)}&background=171717&color=fff&size=200`
25+
}
26+
27+
/**
28+
* Validate image URL and provide fallbacks
29+
*/
30+
export function getImageWithFallback(src: string, alt: string): ImageFallbackProps {
31+
// If it's already a fallback avatar, return as is
32+
if (src.includes('ui-avatars.com') || src.includes('github.com')) {
33+
return { src, alt }
34+
}
35+
36+
// For Unsplash images, provide a fallback
37+
const fallbackSrc = generateFallbackAvatar(alt.replace(' profile picture', '').replace(' avatar', ''))
38+
39+
return {
40+
src,
41+
alt,
42+
fallbackSrc
43+
}
44+
}
45+
46+
/**
47+
* Handle image load errors by updating src to fallback
48+
*/
49+
export function handleImageError(event: React.SyntheticEvent<HTMLImageElement>, fallbackSrc?: string) {
50+
const img = event.target as HTMLImageElement
51+
if (fallbackSrc && img.src !== fallbackSrc) {
52+
img.src = fallbackSrc
53+
}
54+
}
55+
56+
/**
57+
* Optimize external image URLs for better loading
58+
*/
59+
export function optimizeImageUrl(src: string, width: number, height: number): string {
60+
// For Unsplash images, add optimization parameters
61+
if (src.includes('unsplash.com')) {
62+
const url = new URL(src)
63+
url.searchParams.set('w', width.toString())
64+
url.searchParams.set('h', height.toString())
65+
url.searchParams.set('fit', 'crop')
66+
url.searchParams.set('crop', 'face')
67+
url.searchParams.set('auto', 'format')
68+
url.searchParams.set('q', '80')
69+
return url.toString()
70+
}
71+
72+
return src
73+
}

0 commit comments

Comments
 (0)