|
2 | 2 | import { Image } from "astro:assets"; |
3 | 3 | import { getCollection } from "astro:content"; |
4 | 4 | import type { CollectionEntry } from "astro:content"; |
| 5 | +import BitsPreview from "./bits_preview.astro"; |
5 | 6 |
|
6 | 7 | const allArticles = await getCollection("articles"); |
7 | 8 | const articles = allArticles |
@@ -34,7 +35,14 @@ const articles = allArticles |
34 | 35 | </p> |
35 | 36 | </div> |
36 | 37 |
|
37 | | - <div class="relative flex flex-row items center" id="blog-carousel"> |
| 38 | + <BitsPreview /> |
| 39 | + |
| 40 | + <div class="mb-16"> |
| 41 | + <h3 class="text-xl sm:text-2xl font-medium text-gray-700 mb-6 font-['Red_Hat_Display_Variable']"> |
| 42 | + In-Depth Articles |
| 43 | + </h3> |
| 44 | + |
| 45 | + <div class="relative flex flex-row items center" id="blog-carousel"> |
38 | 46 | <button |
39 | 47 | class="bg-white/80 backdrop-blur-sm max-w-fit m-auto rounded-full p-3 shadow-lg border border-brand-200/50 text-brand-600 hover:text-brand-800 hover:bg-white transition-all duration-200 sm:block" |
40 | 48 | id="prev-btn" |
@@ -136,6 +144,7 @@ const articles = allArticles |
136 | 144 | </div> |
137 | 145 | <div class="flex justify-center gap-2 mt-6 sm:mt-8" id="carousel-dots"> |
138 | 146 | </div> |
| 147 | + </div> |
139 | 148 | </div> |
140 | 149 | </section> |
141 | 150 |
|
@@ -210,13 +219,30 @@ const articles = allArticles |
210 | 219 |
|
211 | 220 | function updateDots(totalSlides: number) { |
212 | 221 | if (dotsContainer) { |
213 | | - dotsContainer.innerHTML = ""; |
214 | | - for (let i = 0; i < totalSlides; i++) { |
215 | | - const dot = document.createElement("span"); |
216 | | - dot.className = `w-2 h-2 rounded-full ${i === currentIndex ? "bg-[#B7BEE7]" : "bg-[#B7BEE7]/40"}`; |
217 | | - dot.setAttribute("data-index", i.toString()); |
218 | | - dotsContainer.appendChild(dot); |
| 222 | + // Only create dots if they don't exist or count has changed |
| 223 | + const existingDots = dotsContainer.querySelectorAll('button[data-index]'); |
| 224 | + if (existingDots.length !== totalSlides) { |
| 225 | + dotsContainer.innerHTML = ""; |
| 226 | + for (let i = 0; i < totalSlides; i++) { |
| 227 | + const dot = document.createElement("button"); |
| 228 | + dot.className = `w-2.5 h-2.5 rounded-full transition-all duration-200 cursor-pointer bg-brand-200 hover:bg-brand-400`; |
| 229 | + dot.setAttribute("data-index", i.toString()); |
| 230 | + dot.setAttribute("aria-label", `Go to slide ${i + 1}`); |
| 231 | + dotsContainer.appendChild(dot); |
| 232 | + } |
219 | 233 | } |
| 234 | + |
| 235 | + // Update dot states |
| 236 | + const dots = dotsContainer.querySelectorAll('button[data-index]'); |
| 237 | + dots.forEach((dot, index) => { |
| 238 | + if (index === currentIndex) { |
| 239 | + dot.classList.add('bg-brand-600', 'w-8'); |
| 240 | + dot.classList.remove('bg-brand-200', 'hover:bg-brand-400'); |
| 241 | + } else { |
| 242 | + dot.classList.remove('bg-brand-600', 'w-8'); |
| 243 | + dot.classList.add('bg-brand-200', 'hover:bg-brand-400'); |
| 244 | + } |
| 245 | + }); |
220 | 246 | } |
221 | 247 | } |
222 | 248 |
|
|
0 commit comments