Skip to content

Commit 5134e76

Browse files
committed
refactor: changed main post card background from gradient to random cat images
1 parent 1982361 commit 5134e76

File tree

12 files changed

+30
-19
lines changed

12 files changed

+30
-19
lines changed

lib/mainImage.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export const catImages = [
2+
"/img/main/cat1.png",
3+
"/img/main/cat2.png",
4+
"/img/main/cat3.png",
5+
"/img/main/cat4.png",
6+
"/img/main/cat5.png",
7+
"/img/main/cat6.png",
8+
"/img/main/cat7.png",
9+
"/img/main/cat8.png",
10+
"/img/main/cat9.png",
11+
"/img/main/cat10.png"
12+
];
13+

pages/index.tsx

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,7 @@ import { GetStaticProps } from 'next';
55
import {getPostsMetaOnly} from '../lib/posts';
66
import AdSense from '../components/AdSense';
77
import TopNotice from "../components/TopNotice";
8-
9-
const gradients = [
10-
'from-pink-500 via-red-500 to-orange-400',
11-
'from-blue-400 to-green-400',
12-
'from-purple-500 to-pink-500',
13-
'from-yellow-400 via-green-500 to-teal-500',
14-
'from-indigo-500 to-sky-500',
15-
'from-rose-400 via-fuchsia-500 to-indigo-500',
16-
'from-emerald-400 to-lime-500',
17-
];
8+
import {catImages} from "../lib/mainImage";
189

1910
type Post = {
2011
id: string;
@@ -43,12 +34,12 @@ export const getStaticProps: GetStaticProps<HomeProps> = async () => {
4334

4435
const rest = restAll.filter((post) => post.id !== latest.id).slice(0, 3);
4536

46-
const gradientsForPosts = shuffle(gradients).slice(0, rest.length);
37+
const shuffledImages = shuffle(catImages).slice(0, rest.length);
4738

4839
return {
4940
props: {
5041
allPostsData,
51-
gradientsForPosts,
42+
gradientsForPosts: shuffledImages,
5243
},
5344
};
5445
};
@@ -123,13 +114,20 @@ export default function Home({ allPostsData, gradientsForPosts }: HomeProps) {
123114
</div>
124115
<div className="grid md:grid-cols-3 gap-6">
125116
{rest.map(({ id, title }, idx) => (
126-
<Link key={id} href={`/post/${id}`}>
127-
<div
128-
className={`flex flex-col justify-end p-6 h-48 sm:h-64 rounded-xl text-white shadow hover:shadow-xl transition bg-gradient-to-br ${gradientsForPosts[idx]}`}
129-
>
130-
<h3 className="text-lg font-semibold leading-snug">{title}</h3>
131-
</div>
132-
</Link>
117+
<Link key={id} href={`/post/${id}`}>
118+
<div
119+
className="flex flex-col justify-end p-6 h-48 sm:h-64 rounded-xl text-white shadow hover:shadow-xl transition"
120+
style={{
121+
backgroundImage: `url(${gradientsForPosts[idx]})`,
122+
backgroundSize: "cover",
123+
backgroundPosition: "center",
124+
}}
125+
>
126+
<h3 className="text-lg font-semibold leading-snug bg-black bg-opacity-50 p-2 rounded">
127+
{title}
128+
</h3>
129+
</div>
130+
</Link>
133131
))}
134132
</div>
135133
</section>

public/img/main/cat1.png

1.74 MB
Loading

public/img/main/cat10.png

2.15 MB
Loading

public/img/main/cat2.png

1.64 MB
Loading

public/img/main/cat3.png

1.86 MB
Loading

public/img/main/cat4.png

2.17 MB
Loading

public/img/main/cat5.png

1.81 MB
Loading

public/img/main/cat6.png

2.02 MB
Loading

public/img/main/cat7.png

1.65 MB
Loading

0 commit comments

Comments
 (0)