File tree Expand file tree Collapse file tree 1 file changed +11
-8
lines changed
Expand file tree Collapse file tree 1 file changed +11
-8
lines changed Original file line number Diff line number Diff line change @@ -11,13 +11,16 @@ interface IndividualBlogProps {
1111 alt : string ;
1212}
1313
14- const getRandomColor = ( ) => {
15- const letters = "0123456789ABCDEF" ;
16- let color = "#" ;
17- for ( let i = 0 ; i < 6 ; i ++ ) {
18- color += letters [ Math . floor ( Math . random ( ) * 16 ) ] ;
14+ const getColorFromString = ( str : string ) => {
15+ let hash = 0 ;
16+ for ( let i = 0 ; i < str . length ; i ++ ) {
17+ hash = str . charCodeAt ( i ) + ( ( hash << 5 ) - hash ) ;
1918 }
20- return color ;
19+
20+ // Generate HSL color with fixed saturation and lightness for better readability
21+ const h = Math . abs ( hash % 360 ) ;
22+ // Using lightness of 85% for light backgrounds
23+ return `hsl(${ h } , 70%, 85%)` ;
2124} ;
2225
2326const IndividualBlog : React . FC < IndividualBlogProps > = ( {
@@ -36,8 +39,8 @@ const IndividualBlog: React.FC<IndividualBlogProps> = ({
3639 { tag . map ( ( t , index ) => (
3740 < span
3841 key = { index }
39- className = "rounded-full px-3 py-1 text-xs text-black "
40- style = { { backgroundColor : getRandomColor ( ) } }
42+ className = "rounded-full px-3 py-1 text-xs text-gray-800 "
43+ style = { { backgroundColor : getColorFromString ( t ) } }
4144 >
4245 { t }
4346 </ span >
You can’t perform that action at this time.
0 commit comments