44 lines
6.8 KiB
JavaScript
44 lines
6.8 KiB
JavaScript
import { c as createComponent, d as renderComponent, r as renderTemplate, b as createAstro, m as maybeRenderHead, a as addAttribute } from '../chunks/astro/server_DrnzQWw3.mjs';
|
||
import 'kleur/colors';
|
||
import { $ as $$BaseLayout } from '../chunks/BaseLayout_Bc2tHXHa.mjs';
|
||
import { $ as $$Pagination } from '../chunks/Pagination_BeoGb-H9.mjs';
|
||
import { $ as $$PostCard } from '../chunks/PostCard_D8td2Gog.mjs';
|
||
import { r as readCms, b as getApprovedPosts, c as getPostBySlug, d as getPaginatedPosts, f as formatPostRelativeTime, e as getCategoryPath } from '../chunks/cms_CRTVymfB.mjs';
|
||
export { renderers } from '../renderers.mjs';
|
||
|
||
const $$Astro = createAstro();
|
||
const $$Index = createComponent(async ($$result, $$props, $$slots) => {
|
||
const Astro2 = $$result.createAstro($$Astro, $$props, $$slots);
|
||
Astro2.self = $$Index;
|
||
const cms = await readCms();
|
||
const posts = getApprovedPosts(cms);
|
||
const { homeLayout, hotTopics, ad } = cms.settings;
|
||
const featuredPost = getPostBySlug(posts, homeLayout.featuredSlug) ?? posts[0];
|
||
const pageParam = Number(Astro2.url.searchParams.get("page") ?? "1");
|
||
const requestedPage = Number.isFinite(pageParam) ? pageParam : 1;
|
||
const sideFeaturedPosts = [
|
||
...posts.filter((post) => post.sidebar),
|
||
...homeLayout.sideFeaturedSlugs.map((slug) => getPostBySlug(posts, slug)).filter(Boolean)
|
||
].filter((post, index, list) => list.findIndex((item) => item.slug === post.slug) === index).slice(0, 2);
|
||
const latestSource = posts.filter((post) => post.slug !== featuredPost?.slug);
|
||
const { currentPage, totalPages, posts: latestPosts } = getPaginatedPosts(requestedPage, homeLayout.latestCount, latestSource);
|
||
const mostViewedPosts = posts.slice(1, 6);
|
||
return renderTemplate`${renderComponent($$result, "BaseLayout", $$BaseLayout, {}, { "default": async ($$result2) => renderTemplate` ${maybeRenderHead()}<main class="max-w-7xl mx-auto px-4 lg:px-8 py-6"> ${featuredPost && renderTemplate`<section class="grid grid-cols-1 lg:grid-cols-3 gap-4 items-start mb-5 lg:mb-6"> <a${addAttribute(`/posts/${featuredPost.slug}/`, "href")} class="lg:col-span-2 bg-white rounded-2xl overflow-hidden shadow-sm group"> <div class="img-placeholder h-64 sm:h-80 lg:h-[430px] w-full relative overflow-hidden"> ${featuredPost.image ? renderTemplate`<img${addAttribute(featuredPost.image, "src")}${addAttribute(featuredPost.title, "alt")} class="absolute inset-0 w-full h-full object-cover">` : renderTemplate`<div class="absolute inset-0 flex items-center justify-center text-gray-400"> <span class="material-icons text-5xl opacity-30">image</span> </div>`} <div class="absolute inset-0 bg-gradient-to-t from-black/70 via-black/20 to-transparent"></div> <div class="absolute bottom-0 p-4 sm:p-6"> <span class="bg-brand text-white text-xs px-2.5 py-1 rounded-full font-bold">ویژه</span> <h1 class="text-white font-bold text-xl sm:text-2xl mt-2 leading-snug line-clamp-2 group-hover:text-red-200 transition-colors"> ${featuredPost.title} </h1> <p class="text-white/75 text-sm mt-1 hidden sm:block line-clamp-2">${featuredPost.excerpt}</p> <div class="flex items-center gap-3 mt-3 text-white/60 text-xs"> <span class="material-icons text-sm">schedule</span> <span>${formatPostRelativeTime(featuredPost)}</span> <span>·</span> <span>${featuredPost.category}</span> <span>·</span> <span>${featuredPost.readTime} مطالعه</span> </div> </div> </div> </a> <div class="flex flex-col gap-4 lg:col-span-1"> <div class="grid grid-cols-2 lg:grid-cols-1 gap-4"> ${sideFeaturedPosts.map((post) => renderTemplate`<a${addAttribute(`/posts/${post.slug}/`, "href")} class="bg-white rounded-2xl overflow-hidden shadow-sm group"> <div class="img-placeholder h-28 lg:h-36 w-full relative overflow-hidden"> ${post.thumbnail || post.image ? renderTemplate`<img${addAttribute(post.thumbnail || post.image, "src")}${addAttribute(post.title, "alt")} class="w-full h-full object-cover" loading="lazy">` : renderTemplate`<div class="absolute inset-0 flex items-center justify-center text-gray-400"> <span class="material-icons text-3xl opacity-30">image</span> </div>`} </div> <div class="p-3"> <span class="text-brand text-xs font-bold">${post.category}</span> <h2 class="font-semibold text-sm mt-1 leading-snug line-clamp-2 group-hover:text-brand transition-colors">${post.title}</h2> <p class="text-xs text-gray-400 mt-1">${formatPostRelativeTime(post)}</p> </div> </a>`)} </div> </div> </section>`} <div class="grid grid-cols-1 lg:grid-cols-3 gap-8"> <div class="lg:col-span-2"> <div class="flex items-center justify-between mb-4"> <h2 class="font-bold text-lg">آخرین اخبار</h2> <a href="/posts/" class="text-brand text-sm hover:underline">همه اخبار</a> </div> <div class="space-y-4"> ${latestPosts.map((post) => renderTemplate`${renderComponent($$result2, "PostCard", $$PostCard, { "post": post })}`)} </div> ${renderComponent($$result2, "Pagination", $$Pagination, { "currentPage": currentPage, "totalPages": totalPages, "basePath": "/" })} </div> <aside class="lg:col-span-1 space-y-6"> <div class="bg-white rounded-2xl p-4 shadow-sm"> <h3 class="font-bold text-base mb-4 flex items-center gap-2"> <span class="material-icons text-brand text-xl">trending_up</span>
|
||
پربازدیدترین
|
||
</h3> <ol class="space-y-3"> ${mostViewedPosts.map((item, index) => renderTemplate`<li class="flex items-start gap-3 group"> <span class="text-2xl font-black text-gray-100 leading-none flex-shrink-0 w-6 text-center">${index + 1}</span> <div> <a${addAttribute(`/posts/${item.slug}/`, "href")} class="text-sm font-medium leading-snug group-hover:text-brand transition-colors line-clamp-2">${item.title}</a> <a${addAttribute(getCategoryPath(item.category), "href")} class="text-xs text-brand">${item.category}</a> </div> </li>`)} </ol> </div> ${homeLayout.showAd && ad.enabled && renderTemplate`<a${addAttribute(ad.href, "href")} class="img-placeholder rounded-2xl h-48 flex items-center justify-center text-gray-400"> <div class="text-center"> <span class="material-icons text-4xl opacity-30">campaign</span> <p class="text-xs mt-1 opacity-40">${ad.label}</p> <p class="text-sm mt-2 text-gray-500">${ad.text}</p> </div> </a>`} <div class="bg-white rounded-2xl p-4 shadow-sm"> <h3 class="font-bold text-base mb-3">موضوعات داغ</h3> <div class="flex flex-wrap gap-2"> ${hotTopics.map((tag) => renderTemplate`<a${addAttribute(`/search/?q=${encodeURIComponent(tag)}`, "href")} class="bg-gray-100 hover:bg-red-50 hover:text-brand text-gray-600 text-xs px-3 py-1.5 rounded-full transition-colors">#${tag}</a>`)} </div> </div> </aside> </div> </main> ` })}`;
|
||
}, "/Users/drfelfel/ruseemrooz/src/pages/index.astro", void 0);
|
||
|
||
const $$file = "/Users/drfelfel/ruseemrooz/src/pages/index.astro";
|
||
const $$url = "";
|
||
|
||
const _page = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
|
||
__proto__: null,
|
||
default: $$Index,
|
||
file: $$file,
|
||
url: $$url
|
||
}, Symbol.toStringTag, { value: 'Module' }));
|
||
|
||
const page = () => _page;
|
||
|
||
export { page };
|