@@ -4,6 +4,7 @@ import { getEntry } from "astro:content";
44import { categoriesHandler } from " @/lib/handlers/categories" ;
55import NewsCard from " @/components/cards/newsCard.astro" ;
66import ArrowRight02 from " @/assets/svgs/arrow-right-02.astro" ;
7+ import AdUnit from " @/components/elements/AdUnit.astro" ;
78
89const entry = await getEntry (" views" , " categories" );
910
@@ -19,41 +20,56 @@ const articles = categoriesHandler.allCategoriesWithLatestArticles();
1920<ListLayout header ={ " All Categories" } entry ={ entry } >
2021 <ul class =" w-full space-y-8 my-6" >
2122 {
22- articles .map ((category ) => {
23+ articles .map ((category , categoryIndex ) => {
2324 const { path, title, latestArticles } = category .data ;
2425 const articleCount = category .data .count ;
2526 return (
26- <div class = " flex flex-col items-start gap-4" >
27- <div class = " flex items-center w-full justify-between gap-2 border-b border-accent/30" >
28- <h2 class = " text-xl inline-flex items-center" >
29- { title } { " " }
30- <span class = " text-xs font-sans ml-2 text-primary" >
31- ({ articleCount } Articles)
32- </span >
33- </h2 >
34- <a
35- href = { ` /categories/${path }/1 ` }
36- class = " group flex text-sm items-center gap-1 hover:gap-2 transition-all duration-200"
37- >
38- See All
39- <span class = " transform group-hover:translate-x-1 transition-transform duration-200" >
40- <ArrowRight02 size = " 16" />
41- </span >
42- </a >
43- </div >
44- <div class = " snap-x" >
45- { /* {latestArticles.slice(0, 6).map((article, index) => (
46- <NewsCard article={article} index={index} />
47- ))} */ }
48- <div class = " flex overflow-x-auto pb-4 space-x-4 snap-x snap-proximity" >
49- { latestArticles .slice (0 , 6 ).map ((article , index ) => (
50- <div class = " snap-start flex-none lg:flex-initial" >
51- <NewsCard article = { article } index = { index } />
52- </div >
53- ))}
27+ <>
28+ <div class = " flex flex-col items-start gap-4" >
29+ <div class = " flex items-center w-full justify-between gap-2 border-b border-accent/30" >
30+ <h2 class = " text-xl inline-flex items-center" >
31+ { title } { " " }
32+ <span class = " text-xs font-sans ml-2 text-primary" >
33+ ({ articleCount } Articles)
34+ </span >
35+ </h2 >
36+ <a
37+ href = { ` /categories/${path }/1 ` }
38+ class = " group flex text-sm items-center gap-1 hover:gap-2 transition-all duration-200"
39+ >
40+ See All
41+ <span class = " transform group-hover:translate-x-1 transition-transform duration-200" >
42+ <ArrowRight02 size = " 16" />
43+ </span >
44+ </a >
45+ </div >
46+ <div class = " snap-x" >
47+ { /* {latestArticles.slice(0, 6).map((article, index) => (
48+ <NewsCard article={article} index={index} />
49+ ))} */ }
50+ <div class = " flex overflow-x-auto pb-4 space-x-4 snap-x snap-proximity" >
51+ { latestArticles .slice (0 , 6 ).map ((article , index ) => (
52+ <div class = " snap-start flex-none lg:flex-initial" >
53+ <NewsCard article = { article } index = { index } />
54+ </div >
55+ ))}
56+ </div >
5457 </div >
5558 </div >
56- </div >
59+ { /* Insert horizontal ad after every 3rd category, but not after the last category */ }
60+ { categoryIndex > 0 &&
61+ (categoryIndex + 1 ) % 3 === 0 &&
62+ categoryIndex !== articles .length - 1 && (
63+ <li class = " my-8 flex justify-center" >
64+ <AdUnit
65+ adType = " fluid-layout"
66+ adSlot = " 5304666400"
67+ adLayoutKey = " -fb+5w+4e-db+86"
68+ className = " w-full max-w-4xl"
69+ />
70+ </li >
71+ )}
72+ </>
5773 );
5874 })
5975 }
0 commit comments